Documentation
¶
Index ¶
- func Delete[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Get[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Head[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Initialize(srv *mizu.Server, title string, opts ...OaiOption) error
- func Options[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Patch[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Path(server *mizu.Server, pattern string, opts ...PathOption)
- func Post[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Put[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- func Trace[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), ...) *v3.Operation
- type OaiOption
- func WithOaiContact(name string, url string, email string, extensions ...map[string]any) OaiOption
- func WithOaiDescription(description string) OaiOption
- func WithOaiDocumentation() OaiOption
- func WithOaiExtensions(extensions map[string]any) OaiOption
- func WithOaiExternalDocs(url string, description string, extensions ...map[string]any) OaiOption
- func WithOaiLicense(name string, url string, extensions ...map[string]any) OaiOption
- func WithOaiPreLoad(data []byte) OaiOption
- func WithOaiRenderJson() OaiOption
- func WithOaiSecurity(requirement map[string][]string) OaiOption
- func WithOaiServePath(path string) OaiOption
- func WithOaiServer(url string, desc string, variables map[string]*v3.ServerVariable, ...) OaiOption
- func WithOaiTag(name string, desc string, externalDocs *base.ExternalDoc, ...) OaiOption
- func WithOaiTermsOfService(url string) OaiOption
- type OperationOption
- func WithOperationCallback(key string, value *v3.Callback) OperationOption
- func WithOperationDeprecated() OperationOption
- func WithOperationDescription(description string) OperationOption
- func WithOperationExternalDocs(url string, description string, extensions ...map[string]any) OperationOption
- func WithOperationOperationId(operationId string) OperationOption
- func WithOperationParameters(parameters ...*v3.Parameter) OperationOption
- func WithOperationSecurity(requirement map[string][]string) OperationOption
- func WithOperationServer(url string, desc string, variables map[string]*v3.ServerVariable, ...) OperationOption
- func WithOperationSummary(summary string) OperationOption
- func WithOperationTags(tags ...string) OperationOption
- func WithResponseOverride(code int, links map[string]*v3.Link, headers map[string]*v3.Header) OperationOption
- type PathOption
- func WithPathDescription(desc string) PathOption
- func WithPathExtensions(extensions ...map[string]any) PathOption
- func WithPathParameters(parameters ...*v3.Parameter) PathOption
- func WithPathServer(url string, desc string, variables map[string]*v3.ServerVariable, ...) PathOption
- func WithPathSummary(summary string) PathOption
- type Rx
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Delete ¶
func Delete[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), opts ...OperationOption, ) *v3.Operation
Delete registers a generic handler for DELETE requests. It uses reflection to parse request data into the input type `I` and generate OpenAPI documentation.
func Get ¶
func Get[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), opts ...OperationOption, ) *v3.Operation
Get registers a generic handler for GET requests. It uses reflection to parse request data into the input type `I` and generate OpenAPI documentation.
func Head ¶
func Head[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), opts ...OperationOption, ) *v3.Operation
Head registers a generic handler for HEAD requests. It uses reflection to parse request data into the input type `I` and generate OpenAPI documentation.
func Initialize ¶
Initialize inject OpenAPI config into mizu.Server with the given path and options. openapi.json will be served at /{path}/openapi.json. HTML will be served at /{path}/openapi if enabled. {path} can be set using WithOaiServePath
func Options ¶
func Options[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), opts ...OperationOption, ) *v3.Operation
Options registers a generic handler for OPTIONS requests. It uses reflection to parse request data into the input type `I` and generate OpenAPI documentation.
func Patch ¶
func Patch[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), opts ...OperationOption, ) *v3.Operation
Patch registers a generic handler for PATCH requests. It uses reflection to parse request data into the input type `I` and generate OpenAPI documentation.
func Path ¶
func Path(server *mizu.Server, pattern string, opts ...PathOption)
Path registers a new path in the OpenAPI spec. It can be used to set the path field that can't be accessed via Get, Post, etc.
See: https://spec.openapis.org/oas/v3.0.4.html#path-item-object
func Post ¶
func Post[I any, O any](srv *mizu.Server, pattern string, oaiHandler func(Tx[O], Rx[I]), opts ...OperationOption, ) *v3.Operation
POST registers a generic handler for POST requests. It uses reflection to parse request data into the input type `I` and generate OpenAPI documentation.
Types ¶
type OaiOption ¶
type OaiOption func(*oaiConfig)
func WithOaiContact ¶
WithOaiContact provides contact information for the exposed API.
func WithOaiDescription ¶
WithOaiDescription provides a verbose description of the API. CommonMark syntax MAY be used for rich text representation.
func WithOaiDocumentation ¶
func WithOaiDocumentation() OaiOption
WithOaiDocumentation enables documentation generation.
func WithOaiExtensions ¶
WithOaiExtensions adds extensions to the operation.
func WithOaiExternalDocs ¶
WithOaiExternalDocs provides a reference to an external resource for extended documentation.
- https://spec.openapis.org/oas/v3.0.4.html#external-documentation-object
func WithOaiLicense ¶
WithOaiLicense provides the license information for the exposed API.
func WithOaiPreLoad ¶
WithOaiPreLoad loads an OpenAPI document from data.
func WithOaiSecurity ¶
WithOaiSecurity adds a security requirement to the operation. Each name MUST correspond to a security scheme which is declared in the Security Schemes under the Components Object.
- https://spec.openapis.org/oas/v3.0.4.html#security-requirement-object
func WithOaiServePath ¶
WithOaiServePath sets the path to serve openapi.json.
func WithOaiServer ¶
func WithOaiServer(url string, desc string, variables map[string]*v3.ServerVariable, extensions ...map[string]any, ) OaiOption
WithOaiServers adds an array of Server Objects, which provide connectivity information to a target server. If the servers field is not provided, or is an empty array, the default value would be a Server Object with a url value of /.
func WithOaiTag ¶
func WithOaiTag(name string, desc string, externalDocs *base.ExternalDoc, extensions ...map[string]any) OaiOption
WithOaiTags adds tags to the operation.
func WithOaiTermsOfService ¶
WithOaiTermsOfService provides a URL to the Terms of Service for the API. Must be in the form of URI.
type OperationOption ¶
type OperationOption func(*operationConfig)
func WithOperationCallback ¶
func WithOperationCallback(key string, value *v3.Callback) OperationOption
WithOperationCallback adds a callback to the operation. A possible out-of band callbacks related to the parent operation. The key is a unique identifier for the Callback Object. Value is a Callback Object that describes a request that may be initiated by the API provider and the expected responses.
- https://spec.openapis.org/oas/v3.0.4.html#operation-object
func WithOperationDeprecated ¶
func WithOperationDeprecated() OperationOption
WithOperationDeprecated marks the operation as deprecated.
- https://spec.openapis.org/oas/v3.0.4.html#operation-object
func WithOperationDescription ¶
func WithOperationDescription(description string) OperationOption
WithOperationDescription provides a verbose explanation of the operation behavior. CommonMark syntax MAY be used for rich text representation.
- https://spec.openapis.org/oas/v3.0.4.html#operation-object
func WithOperationExternalDocs ¶
func WithOperationExternalDocs(url string, description string, extensions ...map[string]any) OperationOption
WithOperationExternalDocs provides a reference to an external resource for extended documentation.
- https://spec.openapis.org/oas/v3.0.4.html#external-documentation-object
func WithOperationOperationId ¶
func WithOperationOperationId(operationId string) OperationOption
WithOperationOperationId provides a unique string used to identify the operation. Unique string used to identify the operation. The id MUST be unique among all operations described in the API. The operationId value is case-sensitive.
- https://spec.openapis.org/oas/v3.0.4.html#operation-object
func WithOperationParameters ¶
func WithOperationParameters(parameters ...*v3.Parameter) OperationOption
WithOperationParameters adds parameters to the operation. A list of parameters that are applicable for this operation. If a parameter is already defined in the Path Item, the new definition will override it but can never remove it. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. The list can use the Reference Object to link to parameters that are defined in the OpenAPI Object’s
- https://spec.openapis.org/oas/v3.0.4.html#path-item-object
func WithOperationSecurity ¶
func WithOperationSecurity(requirement map[string][]string) OperationOption
WithOperationSecurity adds security requirements to the operation. Each name MUST correspond to a security scheme which is declared in the Security Schemes under the Components Object.
- https://spec.openapis.org/oas/v3.0.4.html#security-requirement-object
func WithOperationServer ¶
func WithOperationServer(url string, desc string, variables map[string]*v3.ServerVariable, extensions ...map[string]any, ) OperationOption
WithOperationServer adds an Server Objects to the operation. An alternative servers array to service this operation. If a servers array is specified at the Path Item Object or OpenAPI Object level, it will be overridden by this value.
func WithOperationSummary ¶
func WithOperationSummary(summary string) OperationOption
WithOperationSummary provides a summary of what the operation does.
- https://spec.openapis.org/oas/v3.0.4.html#operation-object
func WithOperationTags ¶
func WithOperationTags(tags ...string) OperationOption
WithOperationTags adds tags to the operation, for logical grouping of operations.
- https://spec.openapis.org/oas/v3.0.4.html#operation-object
func WithResponseOverride ¶
func WithResponseOverride(code int, links map[string]*v3.Link, headers map[string]*v3.Header) OperationOption
WithResponseOverride overrides the default response for the operation. Links and headers can be added if needed.
type PathOption ¶
type PathOption func(*pathConfig)
func WithPathDescription ¶
func WithPathDescription(desc string) PathOption
WithPathDescription adds a description for the path. An optional string summary, intended to apply to all operations in this path.
- https://spec.openapis.org/oas/v3.0.4.html#path-item-object
func WithPathExtensions ¶
func WithPathExtensions(extensions ...map[string]any) PathOption
WithPathExtensions adds extensions to the operation.
- https://spec.openapis.org/oas/v3.0.4.html#path-item-object
func WithPathParameters ¶
func WithPathParameters(parameters ...*v3.Parameter) PathOption
WithPathParameters adds parameters to the path. A list of parameters that are applicable for all the operations described under this path. These parameters can be overridden at the operation level, but cannot be removed there. The list MUST NOT include duplicated parameters. A unique parameter is defined by a combination of a name and location. The list can use the Reference Object to link to parameters that are defined in the OpenAPI Object’s components.parameters.
- https://spec.openapis.org/oas/v3.0.4.html#path-item-object
func WithPathServer ¶
func WithPathServer(url string, desc string, variables map[string]*v3.ServerVariable, extensions ...map[string]any, ) PathOption
WithPathServers adds an Server Objects in Path Item Object, which provide connectivity information to a target server. If the servers field is not provided, or is an empty array, the default value would be a Server Object with a url value of /.
func WithPathSummary ¶
func WithPathSummary(summary string) PathOption
WithPathSummary adds a summary for the path. An optional. An optional string summary, intended to apply to all operations in this path.
- https://spec.openapis.org/oas/v3.0.4.html#path-item-object
type Rx ¶
Rx represents the request side of an API endpoint. It provides access to the parsed request data and the original request context.
type Tx ¶
type Tx[T any] struct { http.ResponseWriter // contains filtered or unexported fields }
Tx represents the response side of an API endpoint. It provides methods to write the response.