Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type OpenAPIMux ¶
type OpenAPIMux struct { Routers *legacyrouter.Routers ErrorHandler func(http.ResponseWriter, *http.Request, string, int) DetailedError bool // contains filtered or unexported fields }
OpenAPIMux is a "schema first" HTTP router. It takes one or multiple OpenAPI schema files as an input and then matches, validates and handles all incoming HTTP based on these schemas. Under the hood, it uses https://github.com/getkin/kin-openapi/ for OpenAPI schema parsing and validation.
Notes on routing: * Routers is a []*Router slice * Each router could be created from a openapi schema file or directly swagger object * "operationId" attribute of a path is used to resolve it to a handler * Multiple routers could be used to handle multiple schema versions * To handle multiple versions, use "servers.url" attribute in openapi schema. Eg servers:
- url: "/v1.2"
* When finding a matching route, routers with "servers" attribute set take priority
func NewRouter ¶
func NewRouter(apis ...string) (*OpenAPIMux, error)
NewRouter creates a OpenAPIMux from API definitions
func (*OpenAPIMux) ServeHTTP ¶
func (sr *OpenAPIMux) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is the single method of the http.Handler interface that makes swagger router interoperable with the standard library. It will run request through all regestered middlewares and finally pass to handler.
func (*OpenAPIMux) UseHandlers ¶
func (sr *OpenAPIMux) UseHandlers(handlers map[string]http.Handler)
UseHandlers appends a handlers to the handlers stack.
func (*OpenAPIMux) UseMiddleware ¶
func (sr *OpenAPIMux) UseMiddleware(middlewares ...func(http.Handler) http.Handler)
UseMiddleware appends a middleware handler to the middleware stack.