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"
|
|
|
|
|
|
|
|
"git.xdrm.io/go/aicra/config/datatype"
|
|
|
|
)
|
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-15 00:37:28 +00:00
|
|
|
// Server represents a full server configuration
|
|
|
|
type Server struct {
|
2020-03-16 08:01:51 +00:00
|
|
|
Types []datatype.DataType
|
|
|
|
Services []*Service
|
2020-03-15 00:37:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Service represents a service definition (from api.json)
|
|
|
|
type Service struct {
|
|
|
|
Method string `json:"method"`
|
|
|
|
Pattern string `json:"path"`
|
|
|
|
Scope [][]string `json:"scope"`
|
|
|
|
Description string `json:"info"`
|
|
|
|
Input map[string]*Parameter `json:"in"`
|
|
|
|
// Download *bool `json:"download"`
|
|
|
|
// Output map[string]*Parameter `json:"out"`
|
|
|
|
|
2020-03-15 00:38:49 +00:00
|
|
|
Captures []*BraceCapture
|
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-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
|
|
|
}
|
2020-03-14 14:24:17 +00:00
|
|
|
|
2020-03-15 00:37:28 +00:00
|
|
|
// links to the related URI parameter and hold a value
|
|
|
|
type braceCaptureValue struct {
|
2020-03-15 00:38:49 +00:00
|
|
|
BraceCapture
|
2020-03-15 00:37:28 +00:00
|
|
|
Value interface{}
|
2020-03-14 23:27:54 +00:00
|
|
|
}
|