Documentation
¶
Index ¶
Constants ¶
const ( PathParamBrace = "brace" PathParamColon = "colon" )
Path parameter styles understood by PathParamStyle.
Variables ¶
This section is empty.
Functions ¶
func PathParamNames ¶ added in v1.0.0
PathParamNames returns the parameter names in an already-normalised path.
Types ¶
type Config ¶
type Config struct {
// Info is the information about the API.
Info *openapi3.Info `yaml:"info"`
// SecuritySchemes is a map of security schemes.
SecuritySchemes map[string]any `yaml:"securitySchemes"`
// RouterDefinitions is a list of router definitions.
RouterDefinitions []RouterDefinition `yaml:"routerDefinitions"`
// HandlerPatterns is the handler patterns configuration.
HandlerPatterns *HandlerPatternsConfig `yaml:"handlerPatterns"`
// SecurityPatterns is a list of security patterns.
SecurityPatterns []SecurityPattern `yaml:"securityPatterns"`
// Servers is a list of server URLs.
Servers []ServerUrl `yaml:"servers,omitempty"`
}
Config represents a configuration.
func (*Config) GetSecuritySchemes ¶ added in v0.2.8
func (c *Config) GetSecuritySchemes() openapi3.SecuritySchemes
GetSecuritySchemes is a helper to get sanitized security schemes.
type EndpointPattern ¶ added in v1.0.0
type EndpointPattern struct {
// Methods are the Go method names this pattern applies to.
Methods []string `yaml:"methods"`
// MethodArg is the index of an argument holding the HTTP method, as in
// echo's e.Add("GET", "/x", h). Nil means the verb comes from elsewhere.
MethodArg *int `yaml:"methodArg,omitempty"`
// PathArg is the index of the argument holding the route path.
PathArg int `yaml:"pathArg"`
// HandlerArg is the index of the argument holding the handler.
HandlerArg int `yaml:"handlerArg"`
// MethodInPath marks the path argument as carrying a leading HTTP method,
// as in net/http's mux.HandleFunc("GET /users/{id}", h).
MethodInPath bool `yaml:"methodInPath,omitempty"`
// DefaultMethods are the HTTP methods to document when the registration
// names none. Such a pattern matches every method, but emitting one
// operation per verb turns a single static file tree into five endpoints,
// so the default is a single GET. Set this to widen or narrow that.
DefaultMethods []string `yaml:"defaultMethods,omitempty"`
}
EndpointPattern describes the argument layout of a route registration call.
The common case needs no entry: any name listed in EndpointMethods is assumed to be `Verb(path, handler)` with the HTTP verb taken from the method name. Routers that pass the verb as an argument, or fold it into the path string, need an explicit pattern.
type HandlerPatternsConfig ¶ added in v0.1.7
type HandlerPatternsConfig struct {
// RequestBody is a list of request body patterns.
RequestBody []RequestBodyPattern `yaml:"requestBody"`
// ResponseBody is a list of response body patterns.
ResponseBody []ResponseBodyPattern `yaml:"responseBody"`
// QueryParameter is a list of query parameter patterns.
QueryParameter []ParameterPattern `yaml:"queryParameter"`
// HeaderParameter is a list of header parameter patterns.
HeaderParameter []ParameterPattern `yaml:"headerParameter"`
}
HandlerPatternsConfig represents a handler patterns configuration.
type ParameterPattern ¶ added in v0.1.7
type ParameterPattern struct {
// FunctionPath is the path to the function.
FunctionPath string `yaml:"functionPath"`
// NameIndex is the index of the name.
NameIndex int `yaml:"nameIndex"`
}
ParameterPattern represents a parameter pattern.
type RequestBodyPattern ¶ added in v0.1.7
type RequestBodyPattern struct {
// FunctionPath is the path to the function.
FunctionPath string `yaml:"functionPath"`
// ArgIndex is the index of the argument.
ArgIndex int `yaml:"argIndex"`
}
RequestBodyPattern represents a request body pattern.
type ResponseBodyPattern ¶ added in v0.1.7
type ResponseBodyPattern struct {
// FunctionPath is the path to the function.
FunctionPath string `yaml:"functionPath"`
// DataIndex is the index of the data.
DataIndex int `yaml:"dataIndex"`
// StatusCodeIndex is the index of the status code.
StatusCodeIndex *int `yaml:"statusCodeIndex,omitempty"`
// DescriptionIndex is the index of the description.
DescriptionIndex *int `yaml:"descriptionIndex,omitempty"`
}
ResponseBodyPattern represents a response body pattern.
type RouterDefinition ¶
type RouterDefinition struct {
// Type is the type of the router.
Type string `yaml:"type"`
// EndpointMethods is a list of endpoint methods.
EndpointMethods []string `yaml:"endpointMethods"`
// GroupMethods is a list of group methods.
GroupMethods []string `yaml:"groupMethods"`
// MiddlewareWrapperMethods is a list of middleware wrapper methods.
MiddlewareWrapperMethods []string `yaml:"middlewareWrapperMethods"`
// MountMethods is a list of methods that attach an already-built sub-router
// under a path prefix, such as chi's Mount. The first argument is the
// prefix and the second is the sub-router.
MountMethods []string `yaml:"mountMethods,omitempty"`
// EndpointPatterns describes registration calls whose shape differs from the
// default `Verb(path, handler)` covered by EndpointMethods. This is what
// lets one config model chi's r.Get("/x", h), echo's e.Add("GET", "/x", h),
// and net/http's mux.HandleFunc("GET /x", h) without framework-specific code.
EndpointPatterns []EndpointPattern `yaml:"endpointPatterns,omitempty"`
// PathParamStyle names the syntax this router uses for path parameters, so
// paths can be normalised to the OpenAPI `{name}` form. Supported values
// are "brace" (/users/{id}, the default) and "colon" (/users/:id).
PathParamStyle string `yaml:"pathParamStyle,omitempty"`
}
RouterDefinition represents a router definition.
func (*RouterDefinition) NormalizePath ¶ added in v1.0.0
func (d *RouterDefinition) NormalizePath(path string) string
NormalizePath rewrites a framework-native path into OpenAPI path-template form. OpenAPI only understands `{name}`, so a gin route registered as `/users/:id` has to be emitted as `/users/{id}` or the path parameter can never be matched to its declaration.
type SecurityPattern ¶ added in v0.1.7
type SecurityPattern struct {
// FunctionPath is the path to the function.
FunctionPath string `yaml:"functionPath"`
// SchemeName is the name of the scheme.
SchemeName string `yaml:"schemeName"`
}
SecurityPattern represents a security pattern.