openApi3Schema

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 2 Imported by: 8

Documentation

Index

Constants

View Source
const (
	OpenAPIVersion = "3.0.0"

	ContentTypeText = "text/plain"
	ContentTypeJson = "application/json"
	ContentTypeForm = "multipart/form-data"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ComponentsObject

type ComponentsObject struct {
	Schemas         map[string]*SchemaObject         `json:"schemas,omitempty"`
	SecuritySchemes map[string]*SecuritySchemeObject `json:"securitySchemes,omitempty"`
	Parameters      map[string]*ParameterObject      `json:"parameters,omitempty"`
	Responses       map[string]*ResponseObject       `json:"responses,omitempty"`
	RequestBodies   map[string]*RequestBodyObject    `json:"requestBodies,omitempty"`
}

type ContactObject

type ContactObject struct {
	Name  string `json:"name,omitempty"`
	URL   string `json:"url,omitempty"`
	Email string `json:"email,omitempty"`
}

type DiscriminatorObject

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

type ExternalDocumentationObject

type ExternalDocumentationObject struct {
	Description string `json:"description,omitempty"`
	URL         string `json:"url"` // Required
}

type HeaderObject

type HeaderObject struct {
	Description string        `json:"description,omitempty"`
	Schema      *SchemaObject `json:"schema,omitempty"`

	// Ref is used when HeaderObject is as a ReferenceObject
	Ref string `json:"$ref,omitempty"`
}

type InfoObject

type InfoObject struct {
	Title          string         `json:"title"`
	Description    string         `json:"description,omitempty"`
	TermsOfService string         `json:"termsOfService,omitempty"`
	Contact        *ContactObject `json:"contact,omitempty"`
	License        *LicenseObject `json:"license,omitempty"`
	Version        string         `json:"version"`
}

type LicenseObject

type LicenseObject struct {
	Name string `json:"name,omitempty"`
	URL  string `json:"url,omitempty"`
}

type MediaTypeObject

type MediaTypeObject struct {
	Schema SchemaObject `json:"schema,omitempty"`
}

type OpenAPIObject

type OpenAPIObject struct {
	Version      string                       `json:"openapi"` // Required
	Info         InfoObject                   `json:"info"`    // Required
	Servers      []ServerObject               `json:"servers,omitempty"`
	Paths        PathsObject                  `json:"paths"`                // Required
	Components   ComponentsObject             `json:"components,omitempty"` // Required for Authorization header
	Security     []map[string][]string        `json:"security,omitempty"`
	Tags         []TagObject                  `json:"tags,omitempty"`
	ExternalDocs *ExternalDocumentationObject `json:"externalDocs,omitempty"`
}

type OperationObject

type OperationObject struct {
	Responses ResponsesObject `json:"responses"` // Required

	Tags         []string                     `json:"tags,omitempty"`
	Summary      string                       `json:"summary,omitempty"`
	Description  string                       `json:"description,omitempty"`
	OperationID  string                       `json:"operationId,omitempty"`
	Parameters   []ParameterObject            `json:"parameters,omitempty"`
	RequestBody  *RequestBodyObject           `json:"requestBody,omitempty"`
	Deprecated   bool                         `json:"deprecated,omitempty"`
	Security     []map[string][]string        `json:"security,omitempty"`
	ExternalDocs *ExternalDocumentationObject `json:"externalDocs,omitempty"`

	// Extensions holds OpenAPI x-* vendor extensions; flattened by MarshalJSON.
	Extensions map[string]interface{} `json:"-"`

	// Accept / Produce are internal (not serialized); used when building content maps.
	Accept  []string `json:"-"`
	Produce []string `json:"-"`
}

func (OperationObject) MarshalJSON

func (o OperationObject) MarshalJSON() ([]byte, error)

MarshalJSON flattens Extensions as top-level x-* keys.

type ParameterObject

type ParameterObject struct {
	Name        string        `json:"name,omitempty"` // Required
	In          string        `json:"in,omitempty"`   // Required. Possible values are "query", "header", "path" or "cookie"
	Description string        `json:"description,omitempty"`
	Required    bool          `json:"required,omitempty"`
	Example     interface{}   `json:"example,omitempty"`
	Schema      *SchemaObject `json:"schema,omitempty"`
	Style       string        `json:"style,omitempty"`
	Explode     *bool         `json:"explode,omitempty"`

	// Ref is used when ParameterOjbect is as a ReferenceObject
	Ref string `json:"$ref,omitempty"`
}

type PathItemObject

type PathItemObject struct {
	Ref         string           `json:"$ref,omitempty"`
	Summary     string           `json:"summary,omitempty"`
	Description string           `json:"description,omitempty"`
	Get         *OperationObject `json:"get,omitempty"`
	Post        *OperationObject `json:"post,omitempty"`
	Patch       *OperationObject `json:"patch,omitempty"`
	Put         *OperationObject `json:"put,omitempty"`
	Delete      *OperationObject `json:"delete,omitempty"`
	Options     *OperationObject `json:"options,omitempty"`
	Head        *OperationObject `json:"head,omitempty"`
	Trace       *OperationObject `json:"trace,omitempty"`
}

type PathsObject

type PathsObject map[string]*PathItemObject

type RequestBodyObject

type RequestBodyObject struct {
	Content map[string]*MediaTypeObject `json:"content,omitempty"` // Required when not a $ref

	Description string `json:"description,omitempty"`
	Required    bool   `json:"required,omitempty"`

	// Ref is used when RequestBodyObject is as a ReferenceObject
	Ref string `json:"$ref,omitempty"`
}

type ResponseObject

type ResponseObject struct {
	Description string `json:"description"` // Required

	Headers map[string]*HeaderObject    `json:"headers,omitempty"`
	Content map[string]*MediaTypeObject `json:"content,omitempty"`

	// Ref is for ReferenceObject
	Ref string `json:"$ref,omitempty"`
}

type ResponsesObject

type ResponsesObject map[string]*ResponseObject // [status]ResponseObject

type SchemaObject

type SchemaObject struct {
	ID                   string                 `json:"-"` // For go-swagger3
	PkgName              string                 `json:"-"` // For go-swagger3
	FieldName            string                 `json:"-"` // For go-swagger3
	DisabledFieldNames   map[string]struct{}    `json:"-"` // For go-swagger3
	Type                 string                 `json:"type,omitempty"`
	Format               string                 `json:"format,omitempty"`
	Required             []string               `json:"required,omitempty"`
	Properties           *orderedmap.OrderedMap `json:"properties,omitempty"`
	Description          string                 `json:"description,omitempty"`
	Items                *SchemaObject          `json:"items,omitempty"` // use ptr to prevent recursive error
	Example              interface{}            `json:"example,omitempty"`
	Deprecated           bool                   `json:"deprecated,omitempty"`
	Ref                  string                 `json:"$ref,omitempty"` // Ref is used when SchemaObject is as a ReferenceObject
	Enum                 interface{}            `json:"enum,omitempty"`
	Title                string                 `json:"title,omitempty"`
	Default              interface{}            `json:"default,omitempty"`
	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"`
	MaxLength            uint                   `json:"maxLength,omitempty"`
	MinLength            uint                   `json:"minLength,omitempty"`
	Pattern              string                 `json:"pattern,omitempty"`
	MaxItems             uint                   `json:"maxItems,omitempty"`
	MinItems             uint                   `json:"minItems,omitempty"`
	UniqueItems          bool                   `json:"uniqueItems,omitempty"`
	MaxProperties        uint                   `json:"maxProperties,omitempty"`
	MinProperties        uint                   `json:"minProperties,omitempty"`
	AdditionalProperties interface{}            `json:"additionalProperties,omitempty"`
	Nullable             bool                   `json:"nullable,omitempty"`
	ReadOnly             bool                   `json:"readOnly,omitempty"`
	WriteOnly            bool                   `json:"writeOnly,omitempty"`
	AllOf                []*SchemaObject        `json:"allOf,omitempty"`
	OneOf                []*SchemaObject        `json:"oneOf,omitempty"`
	AnyOf                []*SchemaObject        `json:"anyOf,omitempty"`
	Discriminator        *DiscriminatorObject   `json:"discriminator,omitempty"`

	// Extensions holds OpenAPI x-* vendor extensions; flattened by MarshalJSON.
	Extensions map[string]interface{} `json:"-"`
}

func (SchemaObject) MarshalJSON

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

MarshalJSON flattens Extensions as top-level x-* keys.

type SecuritySchemeOauthFlowObject

type SecuritySchemeOauthFlowObject struct {
	AuthorizationUrl string            `json:"authorizationUrl,omitempty"`
	TokenUrl         string            `json:"tokenUrl,omitempty"`
	Scopes           map[string]string `json:"scopes"`
}

type SecuritySchemeOauthObject

type SecuritySchemeOauthObject struct {
	Implicit              *SecuritySchemeOauthFlowObject `json:"implicit,omitempty"`
	AuthorizationCode     *SecuritySchemeOauthFlowObject `json:"authorizationCode,omitempty"`
	ResourceOwnerPassword *SecuritySchemeOauthFlowObject `json:"password,omitempty"`
	ClientCredentials     *SecuritySchemeOauthFlowObject `json:"clientCredentials,omitempty"`
}

func (*SecuritySchemeOauthObject) ApplyScopes

func (s *SecuritySchemeOauthObject) ApplyScopes(scopes map[string]string)

type SecuritySchemeObject

type SecuritySchemeObject struct {
	// Generic fields
	Type        string `json:"type"` // Required
	Description string `json:"description,omitempty"`

	// http
	Scheme string `json:"scheme,omitempty"`

	// apiKey
	In   string `json:"in,omitempty"`
	Name string `json:"name,omitempty"`

	// OpenID
	OpenIdConnectUrl string `json:"openIdConnectUrl,omitempty"`

	// OAuth2
	OAuthFlows *SecuritySchemeOauthObject `json:"flows,omitempty"`
}

type ServerObject

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

type TagObject

type TagObject struct {
	Name         string                       `json:"name"`
	Description  string                       `json:"description,omitempty"`
	ExternalDocs *ExternalDocumentationObject `json:"externalDocs,omitempty"`
}

Jump to

Keyboard shortcuts

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