openapi

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cookie[T any](name string) *spec.Parameter

Cookie creates an OpenAPI cookie parameter with a schema inferred from T.

func GenerateSchema

func GenerateSchema(mux *mo.Mux, options *GenerateOptions) (*spec.Swagger, error)

GenerateSchema builds an OpenAPI 2.0 schema from the routes registered in mux.

func Header[T any](name string) *spec.Parameter

Header creates an OpenAPI header parameter with a schema inferred from T.

func Register

func Register(mux *mo.Mux, schema *spec.Swagger, options *RegisterOptions) error

Register mounts routes that serve the generated OpenAPI JSON and Swagger UI.

func TypeToSchema

func TypeToSchema(typ reflect.Type) *spec.Schema

TypeToSchema converts a Go reflection type into an OpenAPI schema.

Types

type AuthAttr

type AuthAttr struct {
	Name   string
	Scopes []string
}

AuthAttr describes an OpenAPI security requirement.

func Auth

func Auth(name string, scopes ...string) *AuthAttr

Auth declares a security requirement for a route operation.

type GenerateOptions

type GenerateOptions struct {
	Info spec.InfoProps
	Tags []spec.Tag
}

GenerateOptions configures top-level OpenAPI document metadata.

type RegisterOptions

type RegisterOptions struct {
	OpenApiPattern string
	SwaggerPattern string
}

RegisterOptions configures the OpenAPI JSON and Swagger UI route patterns.

type ResponseAttr

type ResponseAttr struct {
	Code        int
	ContentType string
	Type        reflect.Type
	Schema      *spec.Schema
	Description string
}

ResponseAttr describes an OpenAPI response attached to a route.

func Respond

func Respond[T any](code int) *ResponseAttr

Respond declares a JSON response with a schema inferred from T.

func RespondFile

func RespondFile(code int) *ResponseAttr

RespondFile declares a binary file response.

func RespondHtml

func RespondHtml(code int) *ResponseAttr

RespondHtml declares an HTML string response.

func (*ResponseAttr) WithContentType

func (attr *ResponseAttr) WithContentType(value string) *ResponseAttr

WithContentType sets the response media type and returns the same attribute.

func (*ResponseAttr) WithDescription

func (attr *ResponseAttr) WithDescription(value string) *ResponseAttr

WithDescription sets the response description and returns the same attribute.

type SummaryAttr

type SummaryAttr struct {
	Summary string
}

SummaryAttr describes a route operation summary.

func Summary

func Summary(summary string) *SummaryAttr

Summary declares the summary text for a route operation.

type TagAttr

type TagAttr struct {
	Name string
}

TagAttr describes a route operation tag.

func Tag

func Tag(name string) *TagAttr

Tag declares an OpenAPI tag for a route operation.

Jump to

Keyboard shortcuts

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