jsonschema

package
v0.0.0-...-35c18bc Latest Latest
Warning

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

Go to latest
Published: May 23, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	XEnumLabels   = `x-enum-labels`
	XGoVendorType = `x-go-vendor-type`
	XGoStarLevel  = `x-go-star-level`
	XGoFieldName  = `x-go-field-name`

	XTagValidate = `x-tag-validate`
)
View Source
const (
	TypeInteger = "integer"
	TypeNumber  = "number"
	TypeString  = "string"
	TypeBoolean = "boolean"

	TypeArray  = "array"
	TypeObject = "object"
)

Variables

This section is empty.

Functions

func FlattenMarshalJSON

func FlattenMarshalJSON(values ...interface{}) ([]byte, error)

func FlattenUnmarshalJSON

func FlattenUnmarshalJSON(data []byte, values ...interface{}) error

Types

type Discriminator

type Discriminator struct {
	PropertyName string            `json:"propertyName"`
	Mapping      map[string]string `json:"mapping,omitempty"`
}

type ExternalDoc

type ExternalDoc struct {
	Description string `json:"description,omitempty"`
	URL         string `json:"url,omitempty"`
}

func NewExternalDoc

func NewExternalDoc(url string, desc string) *ExternalDoc

type OpenAPISchemaFormatGetter

type OpenAPISchemaFormatGetter interface {
	OpenAPISchemaFormat() string
}

type OpenAPISchemaTypeGetter

type OpenAPISchemaTypeGetter interface {
	OpenAPISchemaType() []string
}

type Props

type Props map[string]*Schema

type Ref

type Ref struct {
	Remote   string
	Paths    []string
	RootSelf bool
}

func ParseRef

func ParseRef(ref string) *Ref

func (Ref) IsZero

func (r Ref) IsZero() bool

func (Ref) MarshalText

func (r Ref) MarshalText() (text []byte, err error)

func (Ref) RefString

func (r Ref) RefString() string

func (*Ref) UnmarshalText

func (r *Ref) UnmarshalText(text []byte) (err error)

type Refer

type Refer interface {
	RefString() string
}

type Reference

type Reference struct {
	Refer
}

func (Reference) MarshalJSONRefFirst

func (ref Reference) MarshalJSONRefFirst(values ...interface{}) ([]byte, error)

func (*Reference) UnmarshalJSONRefFirst

func (ref *Reference) UnmarshalJSONRefFirst(data []byte, values ...interface{}) error

type Schema

type Schema struct {
	SchemaBasic

	Reference
	VendorExtensible
}

func AllOf

func AllOf(schemas ...*Schema) *Schema

func AnyOf

func AnyOf(schemas ...*Schema) *Schema

func Binary

func Binary() *Schema

func Boolean

func Boolean() *Schema

func Bytes

func Bytes() *Schema

func Double

func Double() *Schema

func Float

func Float() *Schema

func Integer

func Integer() *Schema

func ItemsOf

func ItemsOf(items *Schema) *Schema

func KeyValueOf

func KeyValueOf(k *Schema, s *Schema) *Schema

func Long

func Long() *Schema

func MapOf

func MapOf(s *Schema) *Schema

func NewSchema

func NewSchema(tpe string, fmt ...string) *Schema

func Not

func Not(schema *Schema) *Schema

func ObjectOf

func ObjectOf(props Props, required ...string) *Schema

func OneOf

func OneOf(schemas ...*Schema) *Schema

func RefSchema

func RefSchema(ref string) *Schema

func RefSchemaByRefer

func RefSchemaByRefer(refer Refer) *Schema

func String

func String() *Schema

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

func (*Schema) SetProperty

func (s *Schema) SetProperty(name string, propSchema *Schema, required bool)

func (*Schema) UnmarshalJSON

func (s *Schema) UnmarshalJSON(data []byte) error

func (Schema) WithDesc

func (s Schema) WithDesc(desc string) *Schema

func (Schema) WithDiscriminator

func (s Schema) WithDiscriminator(discriminator *Discriminator) *Schema

func (Schema) WithTitle

func (s Schema) WithTitle(title string) *Schema

func (Schema) WithValidation

func (s Schema) WithValidation(validation *SchemaValidation) *Schema

type SchemaBasic

type SchemaBasic struct {
	Type   StringOrArray `json:"type,omitempty"`
	Format string        `json:"format,omitempty"`

	Items                *SchemaOrArray     `json:"items,omitempty"`
	Properties           map[string]*Schema `json:"properties,omitempty"`
	AdditionalProperties *SchemaOrBool      `json:"additionalProperties,omitempty"`
	PropertyNames        *Schema            `json:"propertyNames,omitempty"`

	AllOf []*Schema `json:"allOf,omitempty"`
	AnyOf []*Schema `json:"anyOf,omitempty"`
	OneOf []*Schema `json:"oneOf,omitempty"`
	Not   *Schema   `json:"not,omitempty"`

	Title       string      `json:"title,omitempty"`
	Description string      `json:"description,omitempty"`
	Default     interface{} `json:"default,omitempty"`

	Nullable      bool           `json:"nullable,omitempty"`
	Discriminator *Discriminator `json:"discriminator,omitempty"`
	ReadOnly      bool           `json:"readOnly,omitempty"`
	WriteOnly     bool           `json:"writeOnly,omitempty"`
	XML           *XML           `json:"xml,omitempty"`
	ExternalDocs  *ExternalDoc   `json:"external_docs,omitempty"`
	Example       interface{}    `json:"example,omitempty"`
	Deprecated    bool           `json:"deprecated,omitempty"`

	Definitions map[string]*Schema `json:"definitions,omitempty"`

	SchemaValidation
}

type SchemaOrArray

type SchemaOrArray struct {
	Schema  *Schema
	Schemas []Schema
}

func (SchemaOrArray) Len

func (s SchemaOrArray) Len() int

func (*SchemaOrArray) MarshalJSON

func (s *SchemaOrArray) MarshalJSON() ([]byte, error)

func (*SchemaOrArray) UnmarshalJSON

func (s *SchemaOrArray) UnmarshalJSON(data []byte) error

type SchemaOrBool

type SchemaOrBool struct {
	Allows bool
	Schema *Schema
}

func (*SchemaOrBool) MarshalJSON

func (s *SchemaOrBool) MarshalJSON() ([]byte, error)

func (*SchemaOrBool) UnmarshalJSON

func (s *SchemaOrBool) UnmarshalJSON(data []byte) error

type SchemaValidation

type SchemaValidation struct {
	// numbers
	MultipleOf       *float64 `json:"multipleOf,omitempty"`
	Maximum          *float64 `json:"maximum,omitempty"`
	ExclusiveMaximum bool     `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty"`
	ExclusiveMinimum bool     `json:"exclusiveMinimum,omitempty"`

	// string
	MaxLength *uint64 `json:"maxLength,omitempty"`
	MinLength *uint64 `json:"minLength,omitempty"`
	Pattern   string  `json:"pattern,omitempty"`

	// array
	MaxItems    *uint64 `json:"maxItems,omitempty"`
	MinItems    *uint64 `json:"minItems,omitempty"`
	UniqueItems bool    `json:"uniqueItems,omitempty"`

	// object
	MaxProperties *uint64  `json:"maxProperties,omitempty"`
	MinProperties *uint64  `json:"minProperties,omitempty"`
	Required      []string `json:"required,omitempty"`

	// any
	Enum []interface{} `json:"enum,omitempty"`
}

type StringOrArray

type StringOrArray []string

func (StringOrArray) Contains

func (s StringOrArray) Contains(value string) bool

func (StringOrArray) MarshalJSON

func (s StringOrArray) MarshalJSON() ([]byte, error)

func (*StringOrArray) UnmarshalJSON

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

type VendorExtensible

type VendorExtensible struct {
	Extensions map[string]interface{}
}

func (*VendorExtensible) AddExtension

func (v *VendorExtensible) AddExtension(key string, value interface{})

func (VendorExtensible) MarshalJSON

func (v VendorExtensible) MarshalJSON() ([]byte, error)

func (*VendorExtensible) UnmarshalJSON

func (v *VendorExtensible) UnmarshalJSON(data []byte) error

type XML

type XML struct {
	Name      string `json:"name,omitempty"`
	Namespace string `json:"namespace,omitempty"`
	Prefix    string `json:"prefix,omitempty"`
	Attribute bool   `json:"attribute,omitempty"`
	Wrapped   bool   `json:"wrapped,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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