openapi

package
v1.0.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	From  = contextx.From[tCtxOpenAPI, *OpenAPI]
	Must  = contextx.Must[tCtxOpenAPI, *OpenAPI]
	With  = contextx.With[tCtxOpenAPI, *OpenAPI]
	Carry = contextx.Carry[tCtxOpenAPI, *OpenAPI]
)

Functions

This section is empty.

Types

type CallbacksObject

type CallbacksObject struct {
	Callbacks internal.Record[string, *PathItemObject] `json:"callbacks,omitzero"`
}

func (*CallbacksObject) AddCallback

func (o *CallbacksObject) AddCallback(name string, c *PathItemObject)

type ComponentsObject

type ComponentsObject struct {
	Schemas map[string]jsonschema.Schema `json:"schemas,omitzero"`
}

func (*ComponentsObject) AddSchema

func (o *ComponentsObject) AddSchema(id string, s jsonschema.Schema)

func (*ComponentsObject) RefSchema

func (o *ComponentsObject) RefSchema(id string) jsonschema.Schema

type Contact

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

type ContentObject

type ContentObject struct {
	Content map[string]*MediaTypeObject `json:"content,omitzero"`
}

func (*ContentObject) AddContent

func (o *ContentObject) AddContent(contentType string, mt *MediaTypeObject)

type EncodingObject

type EncodingObject struct {
	ContentType string `json:"contentType"`

	HeadersObject

	Style         ParameterStyle `json:"style,omitzero"`
	Explode       bool           `json:"explode,omitzero"`
	AllowReserved bool           `json:"allowReserved,omitzero"`

	jsonschema.Ext
}

type HeaderObject

type HeaderObject = Parameter

type HeadersObject

type HeadersObject struct {
	Headers map[string]*HeaderObject `json:"headers,omitzero"`
}

func (*HeadersObject) AddHeader

func (object *HeadersObject) AddHeader(name string, h *Parameter)

type InfoObject

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

type License

type License struct {
	Name string `json:"name"`
	URL  string `json:"url,omitzero"`
}

type MediaTypeObject

type MediaTypeObject struct {
	Schema   jsonschema.Schema          `json:"schema,omitzero"`
	Encoding map[string]*EncodingObject `json:"encoding,omitzero"`

	jsonschema.Ext
}

func (*MediaTypeObject) AddEncoding

func (o *MediaTypeObject) AddEncoding(name string, e *EncodingObject)

type OpenAPI

type OpenAPI struct {
	OpenAPI string `json:"openapi"`

	InfoObject       `json:"info"`
	ComponentsObject `json:"components"`

	Paths internal.Record[string, *PathItemObject] `json:"paths"`

	jsonschema.Ext
}

func NewOpenAPI

func NewOpenAPI() *OpenAPI

func (*OpenAPI) AddOperation

func (p *OpenAPI) AddOperation(method string, path string, op *OperationObject)

func (*OpenAPI) AddServers

func (p *OpenAPI) AddServers(addresses ...string)

type OperationObject

type OperationObject struct {
	Tags []string `json:"tags,omitzero"`

	Summary     string `json:"summary,omitzero"`
	Description string `json:"description,omitzero"`

	OperationId string `json:"operationId"`

	Parameters  []*ParameterObject `json:"parameters,omitzero"`
	RequestBody *RequestBodyObject `json:"requestBody,omitzero"`

	ResponsesObject

	CallbacksObject

	Deprecated *bool `json:"deprecated,omitzero"`

	jsonschema.Ext
}

func NewOperation

func NewOperation(operationId string) *OperationObject

func (*OperationObject) AddParameter

func (o *OperationObject) AddParameter(name string, in ParameterIn, p *Parameter)

func (*OperationObject) SetRequestBody

func (o *OperationObject) SetRequestBody(rb *RequestBodyObject)

func (OperationObject) WithDesc

func (o OperationObject) WithDesc(desc string) *OperationObject

func (OperationObject) WithSummary

func (o OperationObject) WithSummary(summary string) *OperationObject

func (OperationObject) WithTags

func (o OperationObject) WithTags(tags ...string) *OperationObject

type Parameter

type Parameter struct {
	Schema      jsonschema.Schema `json:"schema"`
	Description string            `json:"description,omitzero"`
	Required    *bool             `json:"required,omitzero"`
	Deprecated  *bool             `json:"deprecated,omitzero"`

	// https://spec.openapis.org/oas/latest.html#parameter-object
	Style   ParameterStyle `json:"style,omitzero"`
	Explode *bool          `json:"explode,omitzero"`

	jsonschema.Ext
}

type ParameterIn

type ParameterIn string
const (
	InQuery  ParameterIn = "query"
	InPath   ParameterIn = "path"
	InHeader ParameterIn = "header"
	InCookie ParameterIn = "cookie"
)

type ParameterObject

type ParameterObject struct {
	Name string      `json:"name"`
	In   ParameterIn `json:"in"`

	Parameter
}

ParameterObject https://spec.openapis.org/oas/latest.html#parameter-object

func NewParameter

func NewParameter(name string, in ParameterIn) *ParameterObject

func (*ParameterObject) SetDefaultStyle

func (o *ParameterObject) SetDefaultStyle()

type ParameterStyle

type ParameterStyle string
const (
	ParameterStyleMatrix         ParameterStyle = "matrix"         // https://tools.ietf.org/html/rfc6570#section-3.2.7
	ParameterStyleLabel          ParameterStyle = "label"          // https://tools.ietf.org/html/rfc6570#section-3.2.5
	ParameterStyleForm           ParameterStyle = "form"           // https://tools.ietf.org/html/rfc6570#section-3.2.8
	ParameterStyleSimple         ParameterStyle = "simple"         // for array, csv https://tools.ietf.org/html/rfc6570#section-3.2.2
	ParameterStyleSpaceDelimited ParameterStyle = "spaceDelimited" // for array, ssv
	ParameterStylePipeDelimited  ParameterStyle = "pipeDelimited"  // for array, pipes
	ParameterStyleDeepObject     ParameterStyle = "deepObject"     // for object
)

type PathItemObject

type PathItemObject = internal.Record[string, *OperationObject]

PathItemObject https://spec.openapis.org/oas/latest.html#pathItemObject no need $ref, server, parameters

type Payload

type Payload struct {
	OpenAPI
}

func (Payload) MarshalJSON

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

func (*Payload) UnmarshalJSON

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

type RequestBodyObject

type RequestBodyObject struct {
	Description string `json:"description,omitzero"`
	Required    bool   `json:"required,omitzero"`

	ContentObject

	jsonschema.Ext
}

type ResponseObject

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

	HeadersObject
	ContentObject

	jsonschema.Ext
}

type ResponsesObject

type ResponsesObject struct {
	Responses map[string]*ResponseObject `json:"responses"`
}

func (*ResponsesObject) AddResponse

func (o *ResponsesObject) AddResponse(statusCode int, r *ResponseObject)

func (*ResponsesObject) SetDefaultResponse

func (o *ResponsesObject) SetDefaultResponse(r *ResponseObject)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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