jsonschema

package
v0.0.0-...-1be23ea Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: MIT Imports: 18 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,omitzero"`
	Items Schema `json:"items,omitzero"`

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

	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,omitzero"`

	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,omitzero"`

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

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

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

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

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

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

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,omitzero"`
}

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 = validatortaggedunion.Type

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,omitzero"`
	Description string `json:"description,omitzero"`
	Default     any    `json:"default,omitzero"`
	WriteOnly   *bool  `json:"writeOnly,omitzero"`
	ReadOnly    *bool  `json:"readOnly,omitzero"`
	Examples    []any  `json:"examples,omitzero"`
	Deprecated  *bool  `json:"deprecated,omitzero"`

	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,omitzero"`

	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,omitzero"`

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

	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,omitzero"`

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

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

	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 struct {
	// contains filtered or unexported fields
}

func (*Props) Delete

func (p *Props) Delete(key string) (didDelete bool)

func (*Props) Get

func (p *Props) Get(key string) (Schema, bool)

func (Props) IsZero

func (p Props) IsZero() bool

func (*Props) KeyValues

func (p *Props) KeyValues() iter.Seq2[string, Schema]

func (*Props) Len

func (p *Props) Len() int

func (Props) MarshalJSONV2

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

func (*Props) Set

func (p *Props) Set(key string, value Schema) bool

func (*Props) UnmarshalJSONV2

func (props *Props) UnmarshalJSONV2(d *jsontext.Decoder, options json.Options) error

type RefType

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

	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,omitzero"`
	Format string `json:"format,omitzero"`

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

	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,omitzero"`

	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