schema

package
v0.0.0-...-4d3e907 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 8, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SpecVersionCurrent is the lastest spec
	SpecVersionCurrent SpecVersion = "http://json-schema.org/schema#"
	// SpecVersionCurrentHyper is the latest hyper spec
	SpecVersionCurrentHyper = "http://json-schema.org/hyper-schema#"
	// SpecVersionDraftV4 is the draft-04 spec
	SpecVersionDraftV4 = "http://json-schema.org/draft-04/schema#"
	// SpecVersionDraftV4Hyper is the draft-04 hyper spec
	SpecVersionDraftV4Hyper = "http://json-schema.org/draft-04/hyper-schema#"
)
View Source
const (
	// SchemaTypeObject is the object type
	SchemaTypeObject string = "object"
	// SchemaTypeInteger is the integer type
	SchemaTypeInteger = "integer"
	// SchemaTypeNumber is the number type
	SchemaTypeNumber = "number"
	// SchemaTypeBoolean is the boolean type
	SchemaTypeBoolean = "boolean"
	// SchemaTypeString is the string type
	SchemaTypeString = "string"
	// SchemaTypeArray is the array type
	SchemaTypeArray = "array"
)
View Source
const (
	// DefinitionRoot is the root of the definition ref
	DefinitionRoot = "#/definitions/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArraySchema

type ArraySchema interface {
	JSONSchema
	GetItems() JSONSchema
	GetMaxItems() int64
	GetMinItems() int64
	GetAdditionalItems() bool
	GetUniqueItems() bool

	SetItems(items JSONSchema)
	SetMaxItems(maxItems int64)
	SetMinItems(minItems int64)
	SetAdditionalItems(additionalItems bool)
	SetUniqueItems(uniqueItems bool)
}

ArraySchema represents the schema for a JSON array.

func NewArraySchema

func NewArraySchema() ArraySchema

NewArraySchema creates a new array schema

type BoolOrSchema

type BoolOrSchema struct {
	Boolean bool
	Schema  JSONSchema
}

BoolOrSchema holds a bool or a JSONSchema for values that can take either. This is used for things like additionalProperties

func NewBoolOrSchema

func NewBoolOrSchema(v interface{}) *BoolOrSchema

NewBoolOrSchema creates a *BoolOrSchema based on the given interface.

func (*BoolOrSchema) MarshalJSON

func (b *BoolOrSchema) MarshalJSON() ([]byte, error)

MarshalJSON convert this object to JSON

func (*BoolOrSchema) UnmarshalJSON

func (b *BoolOrSchema) UnmarshalJSON(data []byte) error

UnmarshalJSON converts this bool or schema object from a JSON structure

type JSONSchema

type JSONSchema interface {
	Clone() JSONSchema
	GetSchemaURI() string
	GetID() string
	GetType() *StringOrArray
	GetRef() string
	GetTitle() string
	GetDescription() string
	GetAllOf() []JSONSchema
	GetAnyOf() []JSONSchema
	GetOneOf() []JSONSchema
	GetNot() JSONSchema
	GetDefinitions() map[string]JSONSchema
	GetDefault() interface{}

	AddDefinition(key string, def JSONSchema)
	SetSchemaURI(uri string)
	SetID(id string)
	SetRef(ref string)
	SetTitle(title string)
	SetDescription(description string)
	SetAllOf(items []JSONSchema)
	SetAnyOf(items []JSONSchema)
	SetOneOf(items []JSONSchema)
	SetNot(not JSONSchema)
	SetDefault(def interface{})
	SetType(typeList string)
}

JSONSchema is the base interface that represents common json-schema attributes.

func FromJSON

func FromJSON(js []byte) (JSONSchema, error)

FromJSON returns a JSONSchema object from the given json bytes.

func NewBasicSchema

func NewBasicSchema(jsonType string) JSONSchema

NewBasicSchema creates a new BasicSchema

type NumericSchema

type NumericSchema interface {
	SimpleSchema
	GetMultipleOf() float64
	GetMaximum() float64
	GetMinimum() float64
	GetExclusiveMaximum() bool
	GetExclusiveMinimum() bool

	SetMultipleOf(multipleOf float64)
	SetMaximum(maximum float64)
	SetMinimum(minimum float64)
	SetExclusiveMaximum(exclusiveMaximum bool)
	SetExclusiveMinimum(exclusiveMinimum bool)
}

NumericSchema represents the schema for a JSON number.

func NewNumericSchema

func NewNumericSchema(jsonType string) NumericSchema

NewNumericSchema creates a new numeric schema.

type ObjectSchema

type ObjectSchema interface {
	JSONSchema
	GetProperties() map[string]JSONSchema
	SetProperties(props map[string]JSONSchema)
	GetRequired() []string
	GetMaxProperties() int64
	GetMinProperties() int64
	GetAdditionalProperties() *BoolOrSchema

	SetMaxProperties(maxProperties int64)
	SetMinProperties(minProperties int64)
	SetAdditionalProperties(additionalProperties *BoolOrSchema)
	AddRequiredField(fieldName string)

	SetGoPath(string)
	GetGoPath() string
}

ObjectSchema represents a JSON object schema.

func NewMapSchema

func NewMapSchema(suppressXAttrs bool) ObjectSchema

NewMapSchema creates a new object schema with additionalProperties set to true.

func NewObjectSchema

func NewObjectSchema(suppressXAttrs bool) ObjectSchema

NewObjectSchema creates a new object schema

type SimpleSchema

type SimpleSchema interface {
	JSONSchema
	SetFormat(format string)
	GetFormat() string
}

SimpleSchema is the schema for simple JSON types such as a string, number or boolean.

func NewSimpleSchema

func NewSimpleSchema(jsonType string) SimpleSchema

NewSimpleSchema creates a simple schema with the specified jsonType.

type SpecVersion

type SpecVersion string

SpecVersion is the type for specifying which spec version you adhere to.

type StringOrArray

type StringOrArray struct {
	String string
	Array  []string
}

StringOrArray holds a string or a slice of strings for values that can take either. This is used for things like type

func NewStringOrArray

func NewStringOrArray(v interface{}) *StringOrArray

NewStringOrArray creates a *StringOrArray based on the given interface.

func (*StringOrArray) MarshalJSON

func (soa *StringOrArray) MarshalJSON() ([]byte, error)

MarshalJSON convert this object to JSON

func (*StringOrArray) UnmarshalJSON

func (soa *StringOrArray) UnmarshalJSON(data []byte) error

UnmarshalJSON converts this bool or schema object from a JSON structure

type StringSchema

type StringSchema interface {
	SimpleSchema
	SetPattern(pattern string)
	SetMaxLength(maxLength int64)
	SetMinLength(minLength int64)

	GetPattern() string
	GetMaxLength() int64
	GetMinLength() int64
}

StringSchema represents the schema for a JSON string.

func NewStringSchema

func NewStringSchema() StringSchema

NewStringSchema creates a new string schema.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL