Documentation ¶
Index ¶
- Constants
- Variables
- type Content
- type ContentValue
- type Definitions
- type Operation
- type Options
- type Parameter
- type ParameterValue
- type Router
- func (r Router[HandlerFunc, Route]) AddRawRoute(method string, routePath string, handler HandlerFunc, operation Operation) (Route, error)
- func (r Router[HandlerFunc, Route]) AddRoute(method string, path string, handler HandlerFunc, schema Definitions) (Route, error)
- func (r Router[_, _]) GenerateAndExposeOpenapi() error
- func (r Router[HandlerFunc, Route]) SubRouter(router apirouter.Router[HandlerFunc, Route], opts SubRouterOptions) (*Router[HandlerFunc, Route], error)
- type Schema
- type SecurityRequirement
- type SecurityRequirements
- type SubRouterOptions
Constants ¶
const ( // DefaultJSONDocumentationPath is the path of the swagger documentation in json format. DefaultJSONDocumentationPath = "/documentation/json" // DefaultYAMLDocumentationPath is the path of the swagger documentation in yaml format. DefaultYAMLDocumentationPath = "/documentation/yaml" )
Variables ¶
var ( // ErrGenerateSwagger throws when fails the marshalling of the swagger struct. ErrGenerateSwagger = errors.New("fail to generate swagger") // ErrValidatingSwagger throws when given swagger params are not correct. ErrValidatingSwagger = errors.New("fails to validate swagger") )
var ( // ErrResponses is thrown if error occurs generating responses schemas. ErrResponses = errors.New("errors generating responses schema") // ErrRequestBody is thrown if error occurs generating responses schemas. ErrRequestBody = errors.New("errors generating request body schema") // ErrPathParams is thrown if error occurs generating path params schemas. ErrPathParams = errors.New("errors generating path parameters schema") // ErrQuerystring is thrown if error occurs generating querystring params schemas. ErrQuerystring = errors.New("errors generating querystring schema") )
Functions ¶
This section is empty.
Types ¶
type ContentValue ¶
ContentValue is the struct containing the content information.
type Definitions ¶
type Definitions struct { // Specification extensions https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specification-extensions Extensions map[string]interface{} // Optional field for documentation Tags []string Summary string Description string Deprecated bool // PathParams contains the path parameters. If empty is autocompleted from the path PathParams ParameterValue Querystring ParameterValue Headers ParameterValue Cookies ParameterValue RequestBody *ContentValue Responses map[int]ContentValue Security SecurityRequirements }
Definitions of the route. To see how to use, refer to https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md
type Operation ¶
Operation type
func (*Operation) AddRequestBody ¶
func (o *Operation) AddRequestBody(requestBody *openapi3.RequestBody)
AddRequestBody set request body into operation.
func (*Operation) AddResponse ¶
AddResponse add response to operation. It check if the description is present (otherwise default to empty string). This method does not add the default response, but it is always possible to add it manually.
type Options ¶
type Options struct { Context context.Context Openapi *openapi3.T // JSONDocumentationPath is the path exposed by json endpoint. Default to /documentation/json. JSONDocumentationPath string // YAMLDocumentationPath is the path exposed by yaml endpoint. Default to /documentation/yaml. YAMLDocumentationPath string // Add path prefix to add to every router path. PathPrefix string }
Options to be passed to create the new router and swagger
type ParameterValue ¶
ParameterValue is the struct containing the schema or the content information. If content is specified, it takes precedence.
type Router ¶
type Router[HandlerFunc, Route any] struct { // contains filtered or unexported fields }
Router handle the api router and the swagger schema. api router supported out of the box are: - gorilla mux
func NewRouter ¶
func NewRouter[HandlerFunc, Route any](router apirouter.Router[HandlerFunc, Route], options Options) (*Router[HandlerFunc, Route], error)
NewRouter generate new router with swagger. Default to OpenAPI 3.0.0
func (Router[HandlerFunc, Route]) AddRawRoute ¶
func (r Router[HandlerFunc, Route]) AddRawRoute(method string, routePath string, handler HandlerFunc, operation Operation) (Route, error)
AddRawRoute add route to router with specific method, path and handler. Add the router also to the swagger schema, after validating it
func (Router[HandlerFunc, Route]) AddRoute ¶
func (r Router[HandlerFunc, Route]) AddRoute(method string, path string, handler HandlerFunc, schema Definitions) (Route, error)
AddRoute add a route with json schema inferred by passed schema.
func (Router[_, _]) GenerateAndExposeOpenapi ¶ added in v0.7.0
GenerateAndExposeOpenapi creates a /documentation/json route on router and expose the generated swagger
type Schema ¶
type Schema struct { Value interface{} AllowAdditionalProperties bool }
Schema contains the value and if properties allow additional properties.
type SecurityRequirement ¶ added in v0.9.0
type SecurityRequirements ¶ added in v0.9.0
type SecurityRequirements []SecurityRequirement
type SubRouterOptions ¶ added in v0.3.0
type SubRouterOptions struct {
PathPrefix string
}