openapi

package
v0.0.0-...-37ae4d6 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InjectContext

func InjectContext(ctx context.Context, o *OpenAPI) context.Context

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

https://spec.openapis.org/oas/latest.html#components-object FIXME now only support schemas

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

https://spec.openapis.org/oas/latest.html#infoObject

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 FromContext

func FromContext(ctx context.Context) *OpenAPI

func NewOpenAPI

func NewOpenAPI() *OpenAPI

func (*OpenAPI) AddOperation

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

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
}

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

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
Package jsonschema GENERATED BY gengo:deepcopy DON'T EDIT THIS FILE
Package jsonschema GENERATED BY gengo:deepcopy DON'T EDIT THIS FILE
extractors
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