jsonschema

package
v1.4.1-0...-415649e Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: MIT Imports: 4 Imported by: 0

README

json schema core 简易实现

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsChangedBasic

func IsChangedBasic(a, b *Schema) bool

Types

type Schema

type Schema struct {
	// 3.1 []string 2,3.0 string, if this schema is reference, it will be null
	Type *SliceOrOneValue[string] `json:"type,omitempty"`

	XOrder []string `json:"x-apicat-orders,omitempty"`
	XMock  string   `json:"x-apicat-mock,omitempty"`
	// diff 如果有值就代表有变化
	XDiff *string `json:"x-apicat-diff,omitempty"`
	// category path
	XCategory string `json:"x-apicat-category,omitempty"`
	// 3.1 schema or bool
	Items *ValueOrBoolean[*Schema] `json:"items,omitempty"`

	// 3.0 bool 3.1 int
	ExclusiveMaximum *ValueOrBoolean[int64] `json:"exclusiveMaximum,omitempty"`
	ExclusiveMinimum *ValueOrBoolean[int64] `json:"exclusiveMinimum,omitempty"`

	// 所有版本
	Not                  *Schema                  `json:"not,omitempty"`
	Properties           map[string]*Schema       `json:"properties,omitempty"`
	Title                string                   `json:"title,omitempty"`
	MultipleOf           *int64                   `json:"multipleOf,omitempty"`
	Maximum              *int64                   `json:"maximum,omitempty"`
	Minimum              *int64                   `json:"minimum,omitempty"`
	MaxLength            *int64                   `json:"maxLength,omitempty"`
	MinLength            *int64                   `json:"minLength,omitempty"`
	Format               string                   `json:"format,omitempty"`
	Pattern              string                   `json:"pattern,omitempty"`
	MaxItems             *int64                   `json:"maxItems,omitempty"`
	MinItems             *int64                   `json:"minItems,omitempty"`
	UniqueItems          *int64                   `json:"uniqueItems,omitempty"`
	MaxProperties        *int64                   `json:"maxProperties,omitempty"`
	MinProperties        *int64                   `json:"minProperties,omitempty"`
	Required             []string                 `json:"required,omitempty"`
	Enum                 []any                    `json:"enum,omitempty"`
	AdditionalProperties *ValueOrBoolean[*Schema] `json:"additionalProperties,omitempty"`
	Description          string                   `json:"description,omitempty"`
	Default              any                      `json:"default,omitempty"`
	Nullable             *bool                    `json:"nullable,omitempty"`
	ReadOnly             bool                     `json:"readOnly,omitempty"`
	WriteOnly            bool                     `json:"writeOnly,omitempty"`
	Example              any                      `json:"example,omitempty"`
	Deprecated           bool                     `json:"deprecated,omitempty"`

	Reference *string `json:"$ref,omitempty"`
}

func Create

func Create(typ string) *Schema

func (*Schema) FindRefById

func (s *Schema) FindRefById(id string) (refs []*Schema)

func (*Schema) IsRefId

func (s *Schema) IsRefId(id string) bool

check this schema reference this id

func (*Schema) Ref

func (s *Schema) Ref() bool

func (*Schema) RemovePropertyByRefId

func (s *Schema) RemovePropertyByRefId(id string, stype string)

func (*Schema) RemoveXOrderByName

func (s *Schema) RemoveXOrderByName(name string)

func (*Schema) SetXDiff

func (s *Schema) SetXDiff(x *string)

func (*Schema) Valid

func (s *Schema) Valid() error

func (*Schema) Validation

func (s *Schema) Validation(raw []byte) error

type SliceOrOneValue

type SliceOrOneValue[T any] struct {
	// contains filtered or unexported fields
}

func CreateSliceOrOne

func CreateSliceOrOne[T any](v ...T) *SliceOrOneValue[T]

func (SliceOrOneValue[T]) MarshalJSON

func (s SliceOrOneValue[T]) MarshalJSON() ([]byte, error)

func (*SliceOrOneValue[T]) SetValue

func (s *SliceOrOneValue[T]) SetValue(v ...T)

func (*SliceOrOneValue[T]) UnmarshalJSON

func (s *SliceOrOneValue[T]) UnmarshalJSON(raw []byte) error

func (*SliceOrOneValue[T]) Value

func (s *SliceOrOneValue[T]) Value() []T

type ValueOrBoolean

type ValueOrBoolean[T any] struct {
	// contains filtered or unexported fields
}

func (*ValueOrBoolean[T]) Bool

func (v *ValueOrBoolean[T]) Bool() bool

func (*ValueOrBoolean[T]) IsBool

func (v *ValueOrBoolean[T]) IsBool() bool

func (ValueOrBoolean[T]) MarshalJSON

func (v ValueOrBoolean[T]) MarshalJSON() ([]byte, error)

func (*ValueOrBoolean[T]) SetBoolean

func (v *ValueOrBoolean[T]) SetBoolean(b bool)

func (*ValueOrBoolean[T]) SetValue

func (v *ValueOrBoolean[T]) SetValue(value T)

func (*ValueOrBoolean[T]) UnmarshalJSON

func (v *ValueOrBoolean[T]) UnmarshalJSON(raw []byte) error

func (*ValueOrBoolean[T]) Value

func (v *ValueOrBoolean[T]) Value() T

Jump to

Keyboard shortcuts

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