Documentation ¶
Overview ¶
References:
https://oai.github.io/Documentation/ https://spec.openapis.org/oas/v3.1.0 https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00 https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00
Index ¶
- Constants
- type Anys
- type Bodies
- type Body
- type Callback
- type Callbacks
- type Comps
- type Contact
- type Discr
- type Doc
- func (self *Doc) DerefSchema(sch Schema) (Schema, bool)
- func (self *Doc) GotCompSchema(name string) (Schema, bool)
- func (self *Doc) GotSchema(refPath string) (Schema, bool)
- func (self *Doc) JsonBody(typ interface{}) Body
- func (self *Doc) JsonBodyOpt(typ interface{}) *Body
- func (self *Doc) RespsOkJson(typ interface{}) Resps
- func (self *Doc) Route(path, meth string, op Op) *Doc
- func (self *Doc) Sch(typ interface{}) Schema
- func (self *Doc) SchemaMedia(typ interface{}) MediaType
- func (self *Doc) TypeSchema(typ r.Type) (sch Schema)
- type Encoding
- type Encodings
- type Example
- type Examples
- type ExtDoc
- type Flow
- type Flows
- type Head
- type Heads
- type Info
- type License
- type Link
- type Links
- type MediaType
- type MediaTypes
- type Op
- type Param
- type Params
- type Path
- type Paths
- type Ref
- type Resp
- type Resps
- type Schema
- func (self Schema) IsNullable() bool
- func (self *Schema) Nullable()
- func (self Schema) Opt() *Schema
- func (self *Schema) TypeAdd(vals ...string) *Schema
- func (self Schema) TypeHas(exp string) bool
- func (self Schema) TypeIs(exp ...string) bool
- func (self *Schema) TypeReplace(vals ...string) *Schema
- func (self Schema) ValidTitle() string
- type Schemas
- type SecReq
- type SecScheme
- type SecSchemes
- type Server
- type Tag
- type Var
- type Vars
- type Xml
Constants ¶
const ( // OpenAPI version supported by this package. Ver = `3.1.0` TypeNull = `null` TypeInt = `integer` TypeNum = `number` TypeStr = `string` TypeBool = `boolean` TypeObj = `object` TypeArr = `array` /** References: https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-7.3 https://swagger.io/docs/specification/data-models/data-types/ The following are the formats that this package automatically detects. */ FormatInt32 = `int32` FormatInt64 = `int64` FormatFloat32 = `float` FormatFloat64 = `double` FormatDate = `date` FormatTime = `time` FormatDateTime = `date-time` FormatDuration = `duration` FormatUuid = `uuid` // Well-known formats that this package doesn't automatically detect. FormatByte = `byte` FormatBin = `binary` FormatPassword = `password` FormatEmail = `email` // Reference: https://spec.openapis.org/oas/v3.1.0#parameter-locations InPath = `path` InQuery = `query` InHeader = `header` InCookie = `cookie` ConTypeJson = `application/json` )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Body ¶
type Body struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Cont MediaTypes `json:"content,omitempty" yaml:"content,omitempty" toml:"content,omitempty"` Requ bool `json:"required,omitempty" yaml:"required,omitempty" toml:"required,omitempty"` }
Short for "request body": https://spec.openapis.org/oas/v3.1.0#request-body-object
type Callback ¶
https://spec.openapis.org/oas/v3.1.0#callback-object. May also be `{"$ref": "..."}`.
type Comps ¶
type Comps struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Schemas Schemas `json:"schemas,omitempty" yaml:"schemas,omitempty" toml:"schemas,omitempty"` Resps Resps `json:"responses,omitempty" yaml:"responses,omitempty" toml:"responses,omitempty"` Params Params `json:"parameters,omitempty" yaml:"parameters,omitempty" toml:"parameters,omitempty"` Examples Examples `json:"examples,omitempty" yaml:"examples,omitempty" toml:"examples,omitempty"` Reqs Bodies `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty" toml:"requestBodies,omitempty"` Heads Heads `json:"headers,omitempty" yaml:"headers,omitempty" toml:"headers,omitempty"` SecSchemes SecSchemes `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty" toml:"securitySchemes,omitempty"` Links Links `json:"links,omitempty" yaml:"links,omitempty" toml:"links,omitempty"` Callbacks Callbacks `json:"callbacks,omitempty" yaml:"callbacks,omitempty" toml:"callbacks,omitempty"` Paths Paths `json:"pathItems,omitempty" yaml:"pathItems,omitempty" toml:"pathItems,omitempty"` }
Short for "components": https://spec.openapis.org/oas/v3.1.0#components-object
type Contact ¶
type Contact struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty" toml:"name,omitempty"` Url string `json:"url,omitempty" yaml:"url,omitempty" toml:"url,omitempty"` Email string `json:"email,omitempty" yaml:"email,omitempty" toml:"email,omitempty"` }
type Discr ¶
type Discr struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Prop string `json:"propertyName,omitempty" yaml:"propertyName,omitempty" toml:"propertyName,omitempty"` Map map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty" toml:"mapping,omitempty"` }
Short for "discriminator": https://spec.openapis.org/oas/v3.1.0#discriminator-object
type Doc ¶
type Doc struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Openapi string `json:"openapi,omitempty" yaml:"openapi,omitempty" toml:"openapi,omitempty"` Info *Info `json:"info,omitempty" yaml:"info,omitempty" toml:"info,omitempty"` JsonSchema string `json:"jsonSchemaDialect,omitempty" yaml:"jsonSchemaDialect,omitempty" toml:"jsonSchemaDialect,omitempty"` Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty" toml:"servers,omitempty"` Paths Paths `json:"paths,omitempty" yaml:"paths,omitempty" toml:"paths,omitempty"` Webhooks Paths `json:"webhooks,omitempty" yaml:"webhooks,omitempty" toml:"webhooks,omitempty"` Comps Comps `json:"components,omitempty" yaml:"components,omitempty" toml:"components,omitempty"` Security []SecReq `json:"security,omitempty" yaml:"security,omitempty" toml:"security,omitempty"` Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty" toml:"tags,omitempty"` ExtDoc *ExtDoc `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty" toml:"externalDocs,omitempty"` }
Top-level OpenAPI document. Reference:
https://spec.openapis.org/oas/v3.1.0#openapi-object
func (*Doc) DerefSchema ¶
Dereferences the given schema, returning a non-reference. The bool is true if the target schema was found, false otherwise. May panic if the schema unexpectedly has double indirection.
func (*Doc) GotCompSchema ¶
Looks up a schema by the given name among the doc's components. The name must be the exact schema title, not a reference path. May panic if the schema unexpectedly has double indirection.
func (*Doc) GotSchema ¶
Looks up the schema by a full reference path. Currently supports only component references starting with `#/components/schemas/`.
func (*Doc) JsonBody ¶
Shortcut. Returns `oas.Body` describing a JSON response with the schema of the given type, after registering its schema in the document. The input is used only as a type carrier; its actual value is ignored.
func (*Doc) JsonBodyOpt ¶
Same as `.JsonBody(typ).Opt()` but slightly clearer.
func (*Doc) RespsOkJson ¶
Shortcut. Returns `oas.Resps` with 200 JSON for the given type, after registering its schema in the document. The input is used only as a type carrier; its actual value is ignored.
func (*Doc) Sch ¶
Shortcut for returning `.TypeSchema` from the input's type. The input value is used only as a type carrier.
func (*Doc) SchemaMedia ¶
Shortcut. Returns `oas.MediaType` with the schema of the given type, after registering its schema in the document. The input is used only as a type carrier; its actual value is ignored.
type Encoding ¶
type Encoding struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` ConType string `json:"contentType,omitempty" yaml:"contentType,omitempty" toml:"contentType,omitempty"` Head Heads `json:"headers,omitempty" yaml:"headers,omitempty" toml:"headers,omitempty"` Style string `json:"style,omitempty" yaml:"style,omitempty" toml:"style,omitempty"` Explode bool `json:"explode,omitempty" yaml:"explode,omitempty" toml:"explode,omitempty"` Reserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty" toml:"allowReserved,omitempty"` }
type Example ¶
type Example struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Val string `json:"value,omitempty" yaml:"value,omitempty" toml:"value,omitempty"` ExVal string `json:"externalValue,omitempty" yaml:"externalValue,omitempty" toml:"externalValue,omitempty"` }
type ExtDoc ¶
type ExtDoc struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Url string `json:"url,omitempty" yaml:"url,omitempty" toml:"url,omitempty"` }
Short for "external documentation": https://spec.openapis.org/oas/v3.1.0#external-documentation-object
type Flow ¶
type Flow struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` AuthUrl string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty" toml:"authorizationUrl,omitempty"` TokenUrl string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty" toml:"tokenUrl,omitempty"` RefreshUrl string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty" toml:"refreshUrl,omitempty"` Scopes map[string]string `json:"scopes,omitempty" yaml:"scopes,omitempty" toml:"scopes,omitempty"` }
type Flows ¶
type Flows struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Implicit Flow `json:"implicit,omitempty" yaml:"implicit,omitempty" toml:"implicit,omitempty"` Password Flow `json:"password,omitempty" yaml:"password,omitempty" toml:"password,omitempty"` ClientCred Flow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty" toml:"clientCredentials,omitempty"` AuthCode Flow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty" toml:"authorizationCode,omitempty"` }
type Head ¶
type Head struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Requ bool `json:"required,omitempty" yaml:"required,omitempty" toml:"required,omitempty"` Depr bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty" toml:"deprecated,omitempty"` Empty bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty" toml:"allowEmptyValue,omitempty"` Style string `json:"style,omitempty" yaml:"style,omitempty" toml:"style,omitempty"` Explode bool `json:"explode,omitempty" yaml:"explode,omitempty" toml:"explode,omitempty"` Reserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty" toml:"allowReserved,omitempty"` Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty" toml:"schema,omitempty"` Example any `json:"example,omitempty" yaml:"example,omitempty" toml:"example,omitempty"` Examples Examples `json:"examples,omitempty" yaml:"examples,omitempty" toml:"examples,omitempty"` Cont MediaTypes `json:"content,omitempty" yaml:"content,omitempty" toml:"content,omitempty"` }
Short for "header": https://spec.openapis.org/oas/v3.1.0#header-object
type Info ¶
type Info struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Title string `json:"title,omitempty" yaml:"title,omitempty" toml:"title,omitempty"` Terms string `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty" toml:"termsOfService,omitempty"` Contact *Contact `json:"contact,omitempty" yaml:"contact,omitempty" toml:"contact,omitempty"` License *License `json:"license,omitempty" yaml:"license,omitempty" toml:"license,omitempty"` Ver string `json:"version,omitempty" yaml:"version,omitempty" toml:"version,omitempty"` }
type License ¶
type License struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty" toml:"name,omitempty"` Ident string `json:"identifier,omitempty" yaml:"identifier,omitempty" toml:"identifier,omitempty"` Url string `json:"url,omitempty" yaml:"url,omitempty" toml:"url,omitempty"` }
type Link ¶
type Link struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` OpRef string `json:"operationRef,omitempty" yaml:"operationRef,omitempty" toml:"operationRef,omitempty"` OpId string `json:"operationId,omitempty" yaml:"operationId,omitempty" toml:"operationId,omitempty"` Params Anys `json:"parameters,omitempty" yaml:"parameters,omitempty" toml:"parameters,omitempty"` ReqBody any `json:"requestBody,omitempty" yaml:"requestBody,omitempty" toml:"requestBody,omitempty"` Server *Server `json:"server,omitempty" yaml:"server,omitempty" toml:"server,omitempty"` }
type MediaType ¶
type MediaType struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Schema Schema `json:"schema,omitempty" yaml:"schema,omitempty" toml:"schema,omitempty"` Example any `json:"example,omitempty" yaml:"example,omitempty" toml:"example,omitempty"` Examples Examples `json:"examples,omitempty" yaml:"examples,omitempty" toml:"examples,omitempty"` Encoding Encodings `json:"encoding,omitempty" yaml:"encoding,omitempty" toml:"encoding,omitempty"` }
type MediaTypes ¶
type Op ¶
type Op struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty" toml:"tags,omitempty"` ExtDoc *ExtDoc `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty" toml:"externalDocs,omitempty"` OpId string `json:"operationId,omitempty" yaml:"operationId,omitempty" toml:"operationId,omitempty"` Params []Param `json:"parameters,omitempty" yaml:"parameters,omitempty" toml:"parameters,omitempty"` ReqBody *Body `json:"requestBody,omitempty" yaml:"requestBody,omitempty" toml:"requestBody,omitempty"` Resps Resps `json:"responses,omitempty" yaml:"responses,omitempty" toml:"responses,omitempty"` Callbacks Callbacks `json:"callbacks,omitempty" yaml:"callbacks,omitempty" toml:"callbacks,omitempty"` Depr bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty" toml:"deprecated,omitempty"` Sec []SecReq `json:"security,omitempty" yaml:"security,omitempty" toml:"security,omitempty"` Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty" toml:"servers,omitempty"` }
Short for "operation": https://spec.openapis.org/oas/v3.1.0#operation-object
type Param ¶
type Param struct { Head Name string `json:"name,omitempty" yaml:"name,omitempty" toml:"name,omitempty"` In string `json:"in,omitempty" yaml:"in,omitempty" toml:"in,omitempty"` }
Short for "parameter": https://spec.openapis.org/oas/v3.1.0#parameter-object
type Path ¶
type Path struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Get *Op `json:"get,omitempty" yaml:"get,omitempty" toml:"get,omitempty"` Put *Op `json:"put,omitempty" yaml:"put,omitempty" toml:"put,omitempty"` Post *Op `json:"post,omitempty" yaml:"post,omitempty" toml:"post,omitempty"` Delete *Op `json:"delete,omitempty" yaml:"delete,omitempty" toml:"delete,omitempty"` Options *Op `json:"options,omitempty" yaml:"options,omitempty" toml:"options,omitempty"` Head *Op `json:"head,omitempty" yaml:"head,omitempty" toml:"head,omitempty"` Patch *Op `json:"patch,omitempty" yaml:"patch,omitempty" toml:"patch,omitempty"` Trace *Op `json:"trace,omitempty" yaml:"trace,omitempty" toml:"trace,omitempty"` Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty" toml:"servers,omitempty"` Params []Param `json:"parameters,omitempty" yaml:"parameters,omitempty" toml:"parameters,omitempty"` }
Called "path item" in the spec: https://spec.openapis.org/oas/v3.1.0#path-item-object
type Paths ¶
type Ref ¶
type Ref struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` }
Reference object. References:
https://spec.openapis.org/oas/v3.1.0#reference-object https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-8.2.3.1
Most of our types have a `Ref string` field, and technically they should embed this type to avoid unnecessary duplication. However, we copy the fields instead of embedding the type to ensure better compatibility with 3rd party encoders, some of which don't seem to support embedded structs, particularly for YAML.
type Resp ¶
type Resp struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Head Heads `json:"headers,omitempty" yaml:"headers,omitempty" toml:"headers,omitempty"` Cont MediaTypes `json:"content,omitempty" yaml:"content,omitempty" toml:"content,omitempty"` Links Links `json:"links,omitempty" yaml:"links,omitempty" toml:"links,omitempty"` }
Short for "response": https://spec.openapis.org/oas/v3.1.0#response-object
type Schema ¶
type Schema struct { // Ref `json:",omitempty" yaml:",omitempty" toml:",omitempty"` // Ref Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Discr *Discr `json:"discriminator,omitempty" yaml:"discriminator,omitempty" toml:"discriminator,omitempty"` Xml *Xml `json:"xml,omitempty" yaml:"xml,omitempty" toml:"xml,omitempty"` ExtDoc *ExtDoc `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty" toml:"externalDocs,omitempty"` Example any `json:"example,omitempty" yaml:"example,omitempty" toml:"example,omitempty"` // Also see `.Examples`. // Subschemas. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.2.1 AllOf []Schema `json:"allOf,omitempty" yaml:"allOf,omitempty" toml:"allOf,omitempty"` AnyOf []Schema `json:"anyOf,omitempty" yaml:"anyOf,omitempty" toml:"anyOf,omitempty"` OneOf []Schema `json:"oneOf,omitempty" yaml:"oneOf,omitempty" toml:"oneOf,omitempty"` Not *Schema `json:"not,omitempty" yaml:"not,omitempty" toml:"not,omitempty"` // Conditional subschemas. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.2.2 If *Schema `json:"if,omitempty" yaml:"if,omitempty" toml:"if,omitempty"` Then *Schema `json:"then,omitempty" yaml:"then,omitempty" toml:"then,omitempty"` Else *Schema `json:"else,omitempty" yaml:"else,omitempty" toml:"else,omitempty"` DepSchemas Schemas `json:"dependentSchemas,omitempty" yaml:"dependentSchemas,omitempty" toml:"dependentSchemas,omitempty"` // Array child schemas. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.3.1 PrefixItems []Schema `json:"prefixItems,omitempty" yaml:"prefixItems,omitempty" toml:"prefixItems,omitempty"` Items *Schema `json:"items,omitempty" yaml:"items,omitempty" toml:"items,omitempty"` Contains *Schema `json:"contains,omitempty" yaml:"contains,omitempty" toml:"contains,omitempty"` // Object subschemas. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-10.3.2 Props Schemas `json:"properties,omitempty" yaml:"properties,omitempty" toml:"properties,omitempty"` PatProps Schemas `json:"patternProperties,omitempty" yaml:"patternProperties,omitempty" toml:"patternProperties,omitempty"` AddProps *Schema `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty" toml:"additionalProperties,omitempty"` PropNames *Schema `json:"propertyNames,omitempty" yaml:"propertyNames,omitempty" toml:"propertyNames,omitempty"` // Unevaluated locations. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00#section-11 UnevalItems *Schema `json:"unevaluatedItems,omitempty" yaml:"unevaluatedItems,omitempty" toml:"unevaluatedItems,omitempty"` UnevalProps *Schema `json:"unevaluatedProperties,omitempty" yaml:"unevaluatedProperties,omitempty" toml:"unevaluatedProperties,omitempty"` // Validation for any instance. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.1 Type []string `json:"type,omitempty" yaml:"type,omitempty" toml:"type,omitempty"` Enum []string `json:"enum,omitempty" yaml:"enum,omitempty" toml:"enum,omitempty"` Const any `json:"const,omitempty" yaml:"const,omitempty" toml:"const,omitempty"` // Validation for numeric instances. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.2 MulOf uint64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty" toml:"multipleOf,omitempty"` // 0 represents "missing". Max *int64 `json:"maximum,omitempty" yaml:"maximum,omitempty" toml:"maximum,omitempty"` ExlcMax *int64 `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty" toml:"exclusiveMaximum,omitempty"` Min *int64 `json:"minimum,omitempty" yaml:"minimum,omitempty" toml:"minimum,omitempty"` ExclMin *int64 `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty" toml:"exclusiveMinimum,omitempty"` // Validation for strings. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.3 MaxLen uint64 `json:"maxLength,omitempty" yaml:"maxLength,omitempty" toml:"maxLength,omitempty"` // 0 represents "missing". MinLen uint64 `json:"minLength,omitempty" yaml:"minLength,omitempty" toml:"minLength,omitempty"` Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty" toml:"pattern,omitempty"` // Validation for arrays. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.4 MaxItems uint64 `json:"maxItems,omitempty" yaml:"maxItems,omitempty" toml:"maxItems,omitempty"` MinItems uint64 `json:"minItems,omitempty" yaml:"minItems,omitempty" toml:"minItems,omitempty"` UniqItems bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty" toml:"uniqueItems,omitempty"` MaxCont uint64 `json:"maxContains,omitempty" yaml:"maxContains,omitempty" toml:"maxContains,omitempty"` MinCont uint64 `json:"minContains,omitempty" yaml:"minContains,omitempty" toml:"minContains,omitempty"` // Validation for objects. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.5 MaxProps uint64 `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty" toml:"maxProperties,omitempty"` MinProps uint64 `json:"minProperties,omitempty" yaml:"minProperties,omitempty" toml:"minProperties,omitempty"` Requ bool `json:"required,omitempty" yaml:"required,omitempty" toml:"required,omitempty"` DepRequ map[string][]string `json:"dependentRequired,omitempty" yaml:"dependentRequired,omitempty" toml:"dependentRequired,omitempty"` // Format. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-7 Format string `json:"format,omitempty" yaml:"format,omitempty" toml:"format,omitempty"` // Validation of string-encoded data. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-8 ContEnc string `json:"contentEncoding,omitempty" yaml:"contentEncoding,omitempty" toml:"contentEncoding,omitempty"` ContMedia string `json:"contentMediaType,omitempty" yaml:"contentMediaType,omitempty" toml:"contentMediaType,omitempty"` ContSchema string `json:"contentSchema,omitempty" yaml:"contentSchema,omitempty" toml:"contentSchema,omitempty"` // Metadata annotations. // https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-9 Title string `json:"title,omitempty" yaml:"title,omitempty" toml:"title,omitempty"` // Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Default any `json:"default,omitempty" yaml:"default,omitempty" toml:"default,omitempty"` Depr bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty" toml:"deprecated,omitempty"` Ronly bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty" toml:"readOnly,omitempty"` Wonly bool `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty" toml:"writeOnly,omitempty"` Examples Examples `json:"examples,omitempty" yaml:"examples,omitempty" toml:"examples,omitempty"` }
References:
https://spec.openapis.org/oas/v3.1.0#schema-object https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-00 https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00
The properties are listed in the order of their definition in the respective specifications, on a best-effort basis.
func NullSchema ¶
Shortcut for making a schema that wraps another and uses `.OneOf` with `oas.TypeNull` to indicate nullability. Mostly for internal use; you should never have to annotate nullability manually, as this package detects it automatically.
func (Schema) IsNullable ¶
True if either `.Type`, `.OneOf`, or `.AnyOf` indicates nullability. Note that while `true` indicates nullability, `false` does NOT indicate non-nullability, as the type may reference another, which in turn may be inherently nullable.
func (*Schema) Nullable ¶
func (self *Schema) Nullable()
Mostly for internal use. Mutates the receiver to indicate nullability by adding `oas.TypeNull` to the type. For indicating nullability by wrapping, see `NullSchema`.
func (*Schema) TypeReplace ¶
Replaces `.Type` with the given vals.
func (Schema) ValidTitle ¶
Returns `.Title` after validating that it's non-empty.
type SecScheme ¶
type SecScheme struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty" toml:"type,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty" toml:"name,omitempty"` In string `json:"in,omitempty" yaml:"in,omitempty" toml:"in,omitempty"` Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty" toml:"scheme,omitempty"` BearFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty" toml:"bearerFormat,omitempty"` Flows *Flows `json:"flows,omitempty" yaml:"flows,omitempty" toml:"flows,omitempty"` OidUrl string `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty" toml:"openIdConnectUrl,omitempty"` }
Short for "security scheme". https://spec.openapis.org/oas/v3.1.0#security-scheme-object
type SecSchemes ¶
type Server ¶
type Server struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Url string `json:"url,omitempty" yaml:"url,omitempty" toml:"url,omitempty"` Vars Vars `json:"variables,omitempty" yaml:"variables,omitempty" toml:"variables,omitempty"` }
type Tag ¶
type Tag struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty" toml:"name,omitempty"` ExtDoc *ExtDoc `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty" toml:"externalDocs,omitempty"` }
type Var ¶
type Var struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Enum []string `json:"enum,omitempty" yaml:"enum,omitempty" toml:"enum,omitempty"` Default string `json:"default,omitempty" yaml:"default,omitempty" toml:"default,omitempty"` }
type Xml ¶
type Xml struct { Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty" toml:"$ref,omitempty"` Sum string `json:"sum,omitempty" yaml:"sum,omitempty" toml:"sum,omitempty"` Desc string `json:"description,omitempty" yaml:"description,omitempty" toml:"description,omitempty"` Name string `json:"name,omitempty" yaml:"name,omitempty" toml:"name,omitempty"` Nspace string `json:"namespace,omitempty" yaml:"namespace,omitempty" toml:"namespace,omitempty"` Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty" toml:"prefix,omitempty"` Attr bool `json:"attribute,omitempty" yaml:"attribute,omitempty" toml:"attribute,omitempty"` Wrap bool `json:"wrapped,omitempty" yaml:"wrapped,omitempty" toml:"wrapped,omitempty"` }