jsonschema

package
v0.0.0-...-a9eb721 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package jsonschema GENERATED BY gengo:deepcopy DON'T EDIT THIS FILE

Package jsonschema GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE

Index

Constants

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

Variables

View Source
var ErrInvalidJSONSchemaObject = errors.New("invalid json schema object")
View Source
var ErrInvalidJSONSchemaType = errors.New("invalid json schema type")

Functions

func IsType

func IsType[T Schema](s any) bool

func Print

func Print(w io.Writer, fn func(p Printer))

func Unmarshal

func Unmarshal(data []byte, v any) error

Types

type AnchorString

type AnchorString string

openapi:strfmt anchor

func (AnchorString) OpenAPISchema

func (AnchorString) OpenAPISchema() Schema

func (AnchorString) RuntimeDoc

func (AnchorString) RuntimeDoc(names ...string) ([]string, bool)

func (*AnchorString) UmarshalText

func (s *AnchorString) UmarshalText(text []byte) error

type AnyType

type AnyType struct {
	Core
	Metadata
}

func Any

func Any() *AnyType

func (AnyType) PrintTo

func (AnyType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (AnyType) RuntimeDoc

func (v AnyType) RuntimeDoc(names ...string) ([]string, bool)

type ArrayType

type ArrayType struct {
	Type  string `json:"type,omitempty"`
	Items Schema `json:"items,omitempty"`

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

	Core
	Metadata
}

func ArrayOf

func ArrayOf(items Schema) *ArrayType

func (ArrayType) PrintTo

func (s ArrayType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (ArrayType) RuntimeDoc

func (v ArrayType) RuntimeDoc(names ...string) ([]string, bool)

type BooleanType

type BooleanType struct {
	Type string `json:"type,omitempty"`

	Core
	Metadata
}

func Boolean

func Boolean() *BooleanType

func (BooleanType) PrintTo

func (BooleanType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (BooleanType) RuntimeDoc

func (v BooleanType) RuntimeDoc(names ...string) ([]string, bool)

type CanSwaggerDoc

type CanSwaggerDoc interface {
	SwaggerDoc() map[string]string
}

interface of k8s pkgs

type Core

type Core struct {

	// default https://json-schema.org/draft/2020-12/schema
	Schema *URIString `json:"$schema,omitempty"`

	ID *URIReferenceString `json:"$id,omitempty"`

	Comment string `json:"$comment,omitempty"`

	Vocabulary map[URIString]bool `json:"$vocabulary,omitempty"`

	// https://json-schema.org/understanding-json-schema/structuring#anchor
	Anchor string `json:"$anchor,omitempty"`

	// for generics type
	// https://json-schema.org/blog/posts/dynamicref-and-generics
	DynamicAnchor string `json:"$dynamicAnchor,omitempty"`

	Defs map[string]Schema `json:"$defs,omitempty"`
}

func (*Core) GetCore

func (core *Core) GetCore() *Core

func (Core) RuntimeDoc

func (v Core) RuntimeDoc(names ...string) ([]string, bool)

type Discriminator

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

func (Discriminator) RuntimeDoc

func (v Discriminator) RuntimeDoc(names ...string) ([]string, bool)

type EnumType

type EnumType struct {
	Enum []any `json:"enum"`

	Core
	Metadata
}

func (EnumType) PrintTo

func (t EnumType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (EnumType) RuntimeDoc

func (v EnumType) RuntimeDoc(names ...string) ([]string, bool)

type Ext

type Ext struct {
	Extensions map[string]any `json:",inline"`
}

func ExtOf

func ExtOf(ext map[string]any) Ext

func (*Ext) AddExtension

func (v *Ext) AddExtension(key string, value any)

func (*Ext) DeepCopy

func (in *Ext) DeepCopy() *Ext

func (*Ext) DeepCopyInto

func (in *Ext) DeepCopyInto(out *Ext)

func (*Ext) GetExtension

func (v *Ext) GetExtension(key string) (any, bool)

func (Ext) Merge

func (v Ext) Merge(m Ext) Ext

func (Ext) RuntimeDoc

func (v Ext) RuntimeDoc(names ...string) ([]string, bool)

type GoEnumValues

type GoEnumValues interface {
	EnumValues() []any
}

type GoTaggedUnionType

type GoTaggedUnionType interface {
	Discriminator() string
	Mapping() map[string]any
	SetUnderlying(u any)
}

type GoUnionType

type GoUnionType interface {
	OneOf() []any
}

type IntersectionType

type IntersectionType struct {
	AllOf []Schema `json:"allOf"`

	Core
	Metadata
}

func AllOf

func AllOf(schemas ...Schema) *IntersectionType

func (IntersectionType) PrintTo

func (t IntersectionType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (IntersectionType) RuntimeDoc

func (v IntersectionType) RuntimeDoc(names ...string) ([]string, bool)

type Metadata

type Metadata struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Default     any    `json:"default,omitempty"`
	WriteOnly   *bool  `json:"writeOnly,omitempty"`
	ReadOnly    *bool  `json:"readOnly,omitempty"`
	Examples    []any  `json:"examples,omitempty"`
	Deprecated  *bool  `json:"deprecated,omitempty"`

	Ext
}

+gengo:deepcopy

func (*Metadata) DeepCopy

func (in *Metadata) DeepCopy() *Metadata

func (*Metadata) DeepCopyInto

func (in *Metadata) DeepCopyInto(out *Metadata)

func (*Metadata) GetMetadata

func (v *Metadata) GetMetadata() *Metadata

func (Metadata) RuntimeDoc

func (v Metadata) RuntimeDoc(names ...string) ([]string, bool)

type NullType

type NullType struct {
	Type string `json:"type,omitempty"`

	Core
	Metadata
}

func (NullType) PrintTo

func (NullType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (NullType) RuntimeDoc

func (v NullType) RuntimeDoc(names ...string) ([]string, bool)

type NumberType

type NumberType struct {
	Type string `json:"type,omitempty"`

	// validate
	MultipleOf       *float64 `json:"multipleOf,omitempty"`
	Maximum          *float64 `json:"maximum,omitempty"`
	ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty"`
	ExclusiveMinimum *float64 `json:"exclusiveMinimum,omitempty"`

	Core
	Metadata
}

func (NumberType) PrintTo

func (t NumberType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (NumberType) RuntimeDoc

func (v NumberType) RuntimeDoc(names ...string) ([]string, bool)

type ObjectType

type ObjectType struct {
	Type string `json:"type,omitempty"`

	Properties           Props  `json:"properties,omitempty"`
	PropertyNames        Schema `json:"propertyNames,omitempty"`
	AdditionalProperties Schema `json:"additionalProperties,omitempty"`

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

	Core
	Metadata
}

func MapOf

func MapOf(v Schema) *ObjectType

func ObjectOf

func ObjectOf(props map[string]Schema, required ...string) *ObjectType

func RecordOf

func RecordOf(k Schema, v Schema) *ObjectType

func (ObjectType) PrintTo

func (t ObjectType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (ObjectType) RuntimeDoc

func (v ObjectType) RuntimeDoc(names ...string) ([]string, bool)

func (*ObjectType) SetProperty

func (t *ObjectType) SetProperty(name string, schema Schema, required bool)

type OpenAPISchemaFormatGetter

type OpenAPISchemaFormatGetter interface {
	OpenAPISchemaFormat() string
}

type OpenAPISchemaGetter

type OpenAPISchemaGetter interface {
	OpenAPISchema() Schema
}

type OpenAPISchemaTypeGetter

type OpenAPISchemaTypeGetter interface {
	OpenAPISchemaType() []string
}

type Payload

type Payload struct {
	Schema
}

func (Payload) MarshalJSON

func (p Payload) MarshalJSON() ([]byte, error)

func (Payload) RuntimeDoc

func (v Payload) RuntimeDoc(names ...string) ([]string, bool)

func (*Payload) UnmarshalJSON

func (p *Payload) UnmarshalJSON(data []byte) (err error)

type Printer

type Printer interface {
	io.Writer

	PrintFrom(pt PrinterTo, optionFns ...SchemaPrintOption)
	Print(values ...any)
	Printf(fmt string, values ...any)

	Indent() func()
	Return()
	PrintDoc(desc string)
}

type PrinterTo

type PrinterTo interface {
	PrintTo(w io.Writer, optionFns ...SchemaPrintOption)
}

type Props

type Props map[string]Schema

func (Props) MarshalJSONV2

func (props Props) MarshalJSONV2(encoder *jsontext.Encoder, options json.Options) error

func (Props) RuntimeDoc

func (Props) RuntimeDoc(names ...string) ([]string, bool)

type RefType

type RefType struct {
	Ref        *URIReferenceString `json:"$ref,omitempty"`
	DynamicRef *URIReferenceString `json:"$dynamicRef,omitempty"`

	Core
	Metadata
}

func (RefType) PrintTo

func (t RefType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (RefType) RefName

func (t RefType) RefName() string

func (RefType) RuntimeDoc

func (v RefType) RuntimeDoc(names ...string) ([]string, bool)

type Refer

type Refer interface {
	RefName() string
}

type Schema

type Schema interface {
	GetCore() *Core
	GetMetadata() *Metadata
	PrintTo(w io.Writer, optionFns ...SchemaPrintOption)
}

func Integer

func Integer() Schema

func Long

func Long() Schema

type SchemaPrintOption

type SchemaPrintOption func(o *printOption)

func PrintWithDoc

func PrintWithDoc() SchemaPrintOption

func (SchemaPrintOption) RuntimeDoc

func (SchemaPrintOption) RuntimeDoc(names ...string) ([]string, bool)

type StringType

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

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

	Core
	Metadata
}

func Binary

func Binary() *StringType

func Bytes

func Bytes() *StringType

func String

func String() *StringType

func (StringType) PrintTo

func (t StringType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (StringType) RuntimeDoc

func (v StringType) RuntimeDoc(names ...string) ([]string, bool)

type URIReferenceString

type URIReferenceString url.URL

openapi:strfmt uri-reference

func ParseURIReferenceString

func ParseURIReferenceString(u string) (*URIReferenceString, error)

func (URIReferenceString) MarshalText

func (u URIReferenceString) MarshalText() ([]byte, error)

func (*URIReferenceString) RefName

func (u *URIReferenceString) RefName() string

func (URIReferenceString) RuntimeDoc

func (v URIReferenceString) RuntimeDoc(names ...string) ([]string, bool)

func (*URIReferenceString) UnmarshalText

func (u *URIReferenceString) UnmarshalText(b []byte) error

type URIString

type URIString url.URL

openapi:strfmt uri

func (URIString) MarshalText

func (u URIString) MarshalText() ([]byte, error)

func (URIString) RuntimeDoc

func (v URIString) RuntimeDoc(names ...string) ([]string, bool)

func (*URIString) UnmarshalText

func (u *URIString) UnmarshalText(b []byte) error

type UnionType

type UnionType struct {
	OneOf         []Schema       `json:"oneOf"`
	Discriminator *Discriminator `json:"discriminator,omitempty"`

	Core
	Metadata
}

func OneOf

func OneOf(schemas ...Schema) *UnionType

func (UnionType) PrintTo

func (t UnionType) PrintTo(w io.Writer, optionFns ...SchemaPrintOption)

func (UnionType) RuntimeDoc

func (v UnionType) RuntimeDoc(names ...string) ([]string, bool)

Directories

Path Synopsis
Package extractors GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package extractors GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE

Jump to

Keyboard shortcuts

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