2017-11-11 04:44:02 +00:00
|
|
|
package types
|
|
|
|
|
2018-01-16 05:08:26 +00:00
|
|
|
const (
|
|
|
|
ResourceFieldID = "id"
|
|
|
|
)
|
|
|
|
|
2017-11-11 04:44:02 +00:00
|
|
|
type Collection struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Links map[string]string `json:"links"`
|
|
|
|
CreateTypes map[string]string `json:"createTypes,omitempty"`
|
|
|
|
Actions map[string]string `json:"actions"`
|
|
|
|
Pagination *Pagination `json:"pagination,omitempty"`
|
|
|
|
Sort *Sort `json:"sort,omitempty"`
|
|
|
|
Filters map[string][]Condition `json:"filters,omitempty"`
|
|
|
|
ResourceType string `json:"resourceType"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type GenericCollection struct {
|
|
|
|
Collection
|
|
|
|
Data []interface{} `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type ResourceCollection struct {
|
|
|
|
Collection
|
|
|
|
Data []Resource `json:"data,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type SortOrder string
|
|
|
|
|
|
|
|
type Sort struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Order SortOrder `json:"order,omitempty"`
|
|
|
|
Reverse string `json:"reverse,omitempty"`
|
2017-11-21 20:46:30 +00:00
|
|
|
Links map[string]string `json:"links,omitempty"`
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 20:46:30 +00:00
|
|
|
var (
|
|
|
|
ModifierEQ ModifierType = "eq"
|
|
|
|
ModifierNE ModifierType = "ne"
|
|
|
|
ModifierNull ModifierType = "null"
|
|
|
|
ModifierNotNull ModifierType = "notnull"
|
|
|
|
ModifierIn ModifierType = "in"
|
|
|
|
ModifierNotIn ModifierType = "notin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ModifierType string
|
|
|
|
|
2017-11-11 04:44:02 +00:00
|
|
|
type Condition struct {
|
2017-11-21 20:46:30 +00:00
|
|
|
Modifier ModifierType `json:"modifier,omitempty"`
|
|
|
|
Value interface{} `json:"value,omitempty"`
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Pagination struct {
|
|
|
|
Marker string `json:"marker,omitempty"`
|
|
|
|
First string `json:"first,omitempty"`
|
|
|
|
Previous string `json:"previous,omitempty"`
|
|
|
|
Next string `json:"next,omitempty"`
|
2017-11-21 20:46:30 +00:00
|
|
|
Last string `json:"last,omitempty"`
|
2017-11-11 04:44:02 +00:00
|
|
|
Limit *int64 `json:"limit,omitempty"`
|
|
|
|
Total *int64 `json:"total,omitempty"`
|
|
|
|
Partial bool `json:"partial,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Resource struct {
|
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Links map[string]string `json:"links"`
|
|
|
|
Actions map[string]string `json:"actions"`
|
|
|
|
}
|
|
|
|
|
2018-10-04 21:07:55 +00:00
|
|
|
type NamedResource struct {
|
|
|
|
Resource
|
|
|
|
Name string `json:"name"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type NamedResourceCollection struct {
|
|
|
|
Collection
|
|
|
|
Data []NamedResource `json:"data,omitempty"`
|
|
|
|
}
|
|
|
|
|
2017-11-11 04:44:02 +00:00
|
|
|
type APIVersion struct {
|
2018-02-09 20:31:12 +00:00
|
|
|
Group string `json:"group,omitempty"`
|
|
|
|
Version string `json:"version,omitempty"`
|
|
|
|
Path string `json:"path,omitempty"`
|
|
|
|
SubContext bool `json:"subContext,omitempty"`
|
|
|
|
SubContextSchema string `json:"filterField,omitempty"`
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 20:46:30 +00:00
|
|
|
type Namespaced struct{}
|
|
|
|
|
|
|
|
var NamespaceScope TypeScope = "namespace"
|
|
|
|
|
|
|
|
type TypeScope string
|
|
|
|
|
2017-11-11 04:44:02 +00:00
|
|
|
type Schema struct {
|
2019-02-05 20:20:38 +00:00
|
|
|
ID string `json:"id,omitempty"`
|
|
|
|
Embed bool `json:"embed,omitempty"`
|
|
|
|
EmbedType string `json:"embedType,omitempty"`
|
|
|
|
CodeName string `json:"-"`
|
|
|
|
CodeNamePlural string `json:"-"`
|
|
|
|
PkgName string `json:"-"`
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
BaseType string `json:"baseType,omitempty"`
|
|
|
|
Links map[string]string `json:"links"`
|
|
|
|
Version APIVersion `json:"version"`
|
|
|
|
PluralName string `json:"pluralName,omitempty"`
|
|
|
|
ResourceMethods []string `json:"resourceMethods,omitempty"`
|
|
|
|
ResourceFields map[string]Field `json:"resourceFields"`
|
|
|
|
ResourceActions map[string]Action `json:"resourceActions,omitempty"`
|
|
|
|
CollectionMethods []string `json:"collectionMethods,omitempty"`
|
|
|
|
CollectionFields map[string]Field `json:"collectionFields,omitempty"`
|
|
|
|
CollectionActions map[string]Action `json:"collectionActions,omitempty"`
|
|
|
|
CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"`
|
|
|
|
DynamicSchemaVersion string `json:"dynamicSchemaVersion,omitempty"`
|
|
|
|
Scope TypeScope `json:"-"`
|
2019-05-29 17:49:34 +00:00
|
|
|
Enabled func() bool `json:"-"`
|
2017-11-11 04:44:02 +00:00
|
|
|
|
2018-01-20 06:25:36 +00:00
|
|
|
InternalSchema *Schema `json:"-"`
|
|
|
|
Mapper Mapper `json:"-"`
|
|
|
|
ActionHandler ActionHandler `json:"-"`
|
|
|
|
LinkHandler RequestHandler `json:"-"`
|
|
|
|
ListHandler RequestHandler `json:"-"`
|
|
|
|
CreateHandler RequestHandler `json:"-"`
|
|
|
|
DeleteHandler RequestHandler `json:"-"`
|
|
|
|
UpdateHandler RequestHandler `json:"-"`
|
2018-07-13 19:56:01 +00:00
|
|
|
InputFormatter InputFormatter `json:"-"`
|
2018-01-20 06:25:36 +00:00
|
|
|
Formatter Formatter `json:"-"`
|
|
|
|
CollectionFormatter CollectionFormatter `json:"-"`
|
|
|
|
ErrorHandler ErrorHandler `json:"-"`
|
|
|
|
Validator Validator `json:"-"`
|
|
|
|
Store Store `json:"-"`
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Field struct {
|
|
|
|
Type string `json:"type,omitempty"`
|
|
|
|
Default interface{} `json:"default,omitempty"`
|
|
|
|
Nullable bool `json:"nullable,omitempty"`
|
2017-12-29 22:09:30 +00:00
|
|
|
Create bool `json:"create"`
|
2017-11-11 04:44:02 +00:00
|
|
|
WriteOnly bool `json:"writeOnly,omitempty"`
|
|
|
|
Required bool `json:"required,omitempty"`
|
2017-12-29 22:09:30 +00:00
|
|
|
Update bool `json:"update"`
|
2017-11-11 04:44:02 +00:00
|
|
|
MinLength *int64 `json:"minLength,omitempty"`
|
|
|
|
MaxLength *int64 `json:"maxLength,omitempty"`
|
|
|
|
Min *int64 `json:"min,omitempty"`
|
|
|
|
Max *int64 `json:"max,omitempty"`
|
|
|
|
Options []string `json:"options,omitempty"`
|
|
|
|
ValidChars string `json:"validChars,omitempty"`
|
|
|
|
InvalidChars string `json:"invalidChars,omitempty"`
|
|
|
|
Description string `json:"description,omitempty"`
|
|
|
|
CodeName string `json:"-"`
|
2018-08-21 20:30:34 +00:00
|
|
|
DynamicField bool `json:"dynamicField,omitempty"`
|
2021-06-07 23:33:59 +00:00
|
|
|
Pointer bool `json:"pointer,omitempty"`
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Action struct {
|
|
|
|
Input string `json:"input,omitempty"`
|
|
|
|
Output string `json:"output,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Filter struct {
|
2017-11-21 20:46:30 +00:00
|
|
|
Modifiers []ModifierType `json:"modifiers,omitempty"`
|
2017-11-11 04:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ListOpts struct {
|
|
|
|
Filters map[string]interface{}
|
|
|
|
}
|
2018-01-20 08:30:04 +00:00
|
|
|
|
|
|
|
func (c *Collection) AddAction(apiContext *APIContext, name string) {
|
|
|
|
c.Actions[name] = apiContext.URLBuilder.CollectionAction(apiContext.Schema, nil, name)
|
|
|
|
}
|