2018-10-01 15:43:18 +00:00
|
|
|
package config
|
2018-10-01 10:29:05 +00:00
|
|
|
|
2020-03-14 15:14:04 +00:00
|
|
|
import (
|
|
|
|
"net/http"
|
2020-03-28 17:48:27 +00:00
|
|
|
"reflect"
|
2020-03-14 15:14:04 +00:00
|
|
|
|
2020-03-16 08:20:00 +00:00
|
|
|
"git.xdrm.io/go/aicra/datatype"
|
2020-03-14 15:14:04 +00:00
|
|
|
)
|
2018-10-01 10:29:05 +00:00
|
|
|
|
2019-05-01 08:29:02 +00:00
|
|
|
var availableHTTPMethods = []string{http.MethodGet, http.MethodPost, http.MethodPut, http.MethodDelete}
|
2018-10-01 10:29:05 +00:00
|
|
|
|
2020-03-28 11:26:11 +00:00
|
|
|
// validator unifies the check and format routine
|
|
|
|
type validator interface {
|
|
|
|
Validate(...datatype.T) error
|
|
|
|
}
|
|
|
|
|
2020-03-15 00:37:28 +00:00
|
|
|
// Server represents a full server configuration
|
|
|
|
type Server struct {
|
2020-03-16 08:20:00 +00:00
|
|
|
Types []datatype.T
|
2020-03-16 08:01:51 +00:00
|
|
|
Services []*Service
|
2020-03-15 00:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Service represents a service definition (from api.json)
|
|
|
|
type Service struct {
|
2020-03-28 18:11:23 +00:00
|
|
|
Method string `json:"method"`
|
|
|
|
Pattern string `json:"path"`
|
|
|
|
Scope [][]string `json:"scope"`
|
|
|
|
Description string `json:"info"`
|
|
|
|
Input map[string]*Parameter `json:"in"`
|
|
|
|
Output map[string]interface{} `json:"out"`
|
2020-03-15 00:37:28 +00:00
|
|
|
|
2020-03-16 10:32:37 +00:00
|
|
|
// references to url parameters
|
|
|
|
// format: '/uri/{param}'
|
2020-03-15 00:38:49 +00:00
|
|
|
Captures []*BraceCapture
|
2020-03-16 10:32:37 +00:00
|
|
|
|
|
|
|
// references to Query parameters
|
|
|
|
// format: 'GET@paranName'
|
|
|
|
Query map[string]*Parameter
|
2020-03-16 10:48:44 +00:00
|
|
|
|
|
|
|
// references for form parameters (all but Captures and Query)
|
|
|
|
Form map[string]*Parameter
|
2020-03-15 00:37:28 +00:00
|
|
|
}
|
|
|
|
|
2019-05-01 08:29:02 +00:00
|
|
|
// Parameter represents a parameter definition (from api.json)
|
|
|
|
type Parameter struct {
|
|
|
|
Description string `json:"info"`
|
|
|
|
Type string `json:"type"`
|
|
|
|
Rename string `json:"name,omitempty"`
|
2020-03-28 18:11:23 +00:00
|
|
|
// ExtractType is the type of data the datatype returns
|
|
|
|
ExtractType reflect.Type
|
2020-03-14 23:27:54 +00:00
|
|
|
// Optional is set to true when the type is prefixed with '?'
|
|
|
|
Optional bool
|
2020-03-14 15:14:04 +00:00
|
|
|
|
2020-03-14 23:27:54 +00:00
|
|
|
// Validator is inferred from @Type
|
|
|
|
Validator datatype.Validator
|
2019-05-01 08:29:02 +00:00
|
|
|
}
|
2018-10-01 10:29:05 +00:00
|
|
|
|
2020-03-15 00:38:49 +00:00
|
|
|
// BraceCapture links to the related URI parameter
|
|
|
|
type BraceCapture struct {
|
2020-03-15 00:37:28 +00:00
|
|
|
Name string
|
|
|
|
Index int
|
|
|
|
Ref *Parameter
|
2018-10-01 10:29:05 +00:00
|
|
|
}
|