apidoc

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT, Apache-2.0 Imports: 18 Imported by: 3

Documentation

Index

Constants

View Source
const MarkDownEXT = ".apidoc.md"
View Source
const SwaggerEXT = ".swagger.json"
View Source
const TypeMarkdown = "markdown"
View Source
const TypeSwagger = "swagger"

Variables

View Source
var Dir = "./apidoc/"
View Source
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 DocList

func DocList(w http.ResponseWriter, r *http.Request)

func GetDoc

func GetDoc(realPath, modName string) *openapi3.T

参数为路径和格式

func Markdown

func Markdown(w http.ResponseWriter, r *http.Request)

func NilDoc

func NilDoc()

func OpenApi

func OpenApi(mux *http.ServeMux, uriPrefix, dir string)

func Redoc added in v0.3.4

func Redoc(opts RedocOpts, next http.Handler) http.Handler

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 Swagger

func Swagger(w http.ResponseWriter, r *http.Request)

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

func WithTemplate(tpl string) UIOption

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

func WithUIBasePath(base string) UIOption

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

func WithUIPath(pth string) UIOption

WithUIPath sets the path from where to serve the UI assets (i.e. /{basepath}/{path}.

func WithUISpecURL added in v0.3.4

func WithUISpecURL(specURL string) UIOption

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

func WithUITitle(title string) UIOption

WithUITitle sets the title of the UI.

By default, Context middleware sets this value to the title found in the API spec.

Jump to

Keyboard shortcuts

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