schema: json serialization tags.
This commit is contained in:
+29
-29
@@ -48,41 +48,41 @@ func FetchSchemaFromURL(schemaURL string) (Schema, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Schema struct {
|
type Schema struct {
|
||||||
GenericTags map[string]ContentSpec `yaml:"generic_tags"`
|
GenericTags map[string]ContentSpec `yaml:"generic_tags" json:"generic_tags,omitempty"`
|
||||||
Kinds map[string]KindSchema `yaml:"kinds"`
|
Kinds map[string]KindSchema `yaml:"kinds" json:"kinds,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type KindSchema struct {
|
type KindSchema struct {
|
||||||
Description string `yaml:"description"`
|
Description string `yaml:"description" json:"description,omitempty"`
|
||||||
InUse bool `yaml:"in_use"`
|
InUse bool `yaml:"in_use" json:"in_use,omitempty"`
|
||||||
Content ContentSpec `yaml:"content"`
|
Content ContentSpec `yaml:"content" json:"content,omitempty"`
|
||||||
Required []string `yaml:"required"`
|
Required []string `yaml:"required" json:"required,omitempty"`
|
||||||
Multiple []string `yaml:"multiple"`
|
Multiple []string `yaml:"multiple" json:"multiple,omitempty"`
|
||||||
Tags []TagSpec `yaml:"tags"`
|
Tags []TagSpec `yaml:"tags" json:"tags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TagSpec struct {
|
type TagSpec struct {
|
||||||
Name string `yaml:"name"`
|
Name string `yaml:"name" json:"name,omitempty"`
|
||||||
Prefix string `yaml:"prefix"`
|
Prefix string `yaml:"prefix" json:"prefix,omitempty"`
|
||||||
Next *ContentSpec `yaml:"next"`
|
Next *ContentSpec `yaml:"next" json:"next,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ContentSpec struct {
|
type ContentSpec struct {
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type" json:"type,omitempty"`
|
||||||
Required bool `yaml:"required"`
|
Required bool `yaml:"required" json:"required,omitempty"`
|
||||||
Min int `yaml:"min"`
|
Min int `yaml:"min" json:"min,omitempty"`
|
||||||
Max int `yaml:"max"`
|
Max int `yaml:"max" json:"max,omitempty"`
|
||||||
Either []string `yaml:"either"`
|
Either []string `yaml:"either" json:"either,omitempty"`
|
||||||
Next *ContentSpec `yaml:"next"`
|
Next *ContentSpec `yaml:"next" json:"next,omitempty"`
|
||||||
Variadic bool `yaml:"variadic"`
|
Variadic bool `yaml:"variadic" json:"variadic,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
Schema Schema
|
Schema Schema `json:"schema,omitempty"`
|
||||||
FailOnUnknownKind bool
|
FailOnUnknownKind bool `json:"fail_on_unknown_kind,omitempty"`
|
||||||
FailOnUnknownType bool
|
FailOnUnknownType bool `json:"fail_on_unknown_type,omitempty"`
|
||||||
TypeValidators map[string]func(value string, spec *ContentSpec) error
|
TypeValidators map[string]func(value string, spec *ContentSpec) error `json:"type_validators,omitempty"`
|
||||||
UnknownTypes []string
|
UnknownTypes []string `json:"unknown_types,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewValidatorFromBytes(schemaData []byte) (Validator, error) {
|
func NewValidatorFromBytes(schemaData []byte) (Validator, error) {
|
||||||
@@ -212,7 +212,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type UnknownTypes struct {
|
type UnknownTypes struct {
|
||||||
Types []string
|
Types []string `json:"types,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ut UnknownTypes) Error() string {
|
func (ut UnknownTypes) Error() string {
|
||||||
@@ -220,7 +220,7 @@ func (ut UnknownTypes) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ContentError struct {
|
type ContentError struct {
|
||||||
Err error
|
Err error `json:"err,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ce ContentError) Error() string {
|
func (ce ContentError) Error() string {
|
||||||
@@ -228,9 +228,9 @@ func (ce ContentError) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TagError struct {
|
type TagError struct {
|
||||||
Tag int
|
Tag int `json:"tag,omitempty"`
|
||||||
Item int
|
Item int `json:"item,omitempty"`
|
||||||
Err error
|
Err error `json:"err,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (te TagError) Error() string {
|
func (te TagError) Error() string {
|
||||||
@@ -238,7 +238,7 @@ func (te TagError) Error() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RequiredTagError struct {
|
type RequiredTagError struct {
|
||||||
Missing []string
|
Missing []string `json:"missing,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rte RequiredTagError) Error() string {
|
func (rte RequiredTagError) Error() string {
|
||||||
|
|||||||
Reference in New Issue
Block a user