Documentation ¶
Index ¶
- Constants
- Variables
- func AddComponent(name string, v interface{})
- func DocList(w http.ResponseWriter, r *http.Request)
- func GetDoc(realPath, modName string) *openapi3.T
- func Markdown(w http.ResponseWriter, r *http.Request)
- func NilDoc()
- func OpenApi(mux *http.ServeMux, uriPrefix, dir string)
- func Redoc(opts RedocOpts, next http.Handler) http.Handler
- func Swagger(w http.ResponseWriter, r *http.Request)
- func WriteToFile(realPath, modName string)
- type ComponentType
- type RedocOpts
- type UIOption
Constants ¶
const MarkDownEXT = ".apidoc.md"
const SwaggerEXT = ".swagger.json"
const TypeMarkdown = "markdown"
const TypeSwagger = "swagger"
Variables ¶
var Dir = "./apidoc/"
var Doc *openapi3.T
var UriPrefix = "/apidoc"
目录结构 ./api/mod/mod.swagger.json ./api/mod/mod.apidoc.md 请求路由 /apidoc /apidoc/openapi/mod/mod.swagger.json /apidoc/markdown/mod/mod.apidoc.md
Functions ¶
func AddComponent ¶ added in v0.3.4
func AddComponent(name string, v interface{})
func Redoc ¶ added in v0.3.4
Redoc creates a middleware to serve a documentation site for a swagger spec.
This allows for altering the spec before starting the http listener.
func WriteToFile ¶
func WriteToFile(realPath, modName string)
Types ¶
type ComponentType ¶ added in v0.3.4
type ComponentType int
const ( ComponentTypeParameters ComponentType = iota ComponentTypeHeaders ComponentTypeRequestBodies ComponentTypeResponses ComponentTypeSecuritySchemes ComponentTypeExamples ComponentTypeLinks ComponentTypeCallbacks )
type RedocOpts ¶ added in v0.3.4
type RedocOpts struct { // BasePath for the UI, defaults to: / BasePath string // Path combines with BasePath to construct the path to the UI, defaults to: "docs". Path string // SpecURL is the URL of the spec document. // // Defaults to: /swagger.json SpecURL string // Title for the documentation site, default to: API documentation Title string // Template specifies a custom template to serve the UI Template string // RedocURL points to the js that generates the redoc site. // // Defaults to: https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js RedocURL string }
RedocOpts configures the Redoc middlewares
func (*RedocOpts) EnsureDefaults ¶ added in v0.3.4
func (r *RedocOpts) EnsureDefaults()
EnsureDefaults in case some options are missing
type UIOption ¶ added in v0.3.4
type UIOption func(*uiOptions)
UIOption can be applied to UI serving middleware, such as Context.APIHandler or Context.APIHandlerSwaggerUI to alter the defaut behavior.
func WithTemplate ¶ added in v0.3.4
WithTemplate allows to set a custom template for the UI.
UI middleware will panic if the template does not parse or execute properly.
func WithUIBasePath ¶ added in v0.3.4
WithUIBasePath sets the base path from where to serve the UI assets.
By default, Context middleware sets this value to the API base path.
func WithUIPath ¶ added in v0.3.4
WithUIPath sets the path from where to serve the UI assets (i.e. /{basepath}/{path}.
func WithUISpecURL ¶ added in v0.3.4
WithUISpecURL sets the path from where to serve swagger spec document.
This may be specified as a full URL or a path.
By default, this is "/swagger.json"
func WithUITitle ¶ added in v0.3.4
WithUITitle sets the title of the UI.
By default, Context middleware sets this value to the title found in the API spec.