Documentation ¶
Overview ¶
Package compoas provides structs for building OpenAPI specification and HTTP handler for serving Swagger UI.
Index ¶
- func UIHandler(uiBundle SwaggerUIBundleConfig, pathPrefix string, log func(v ...interface{})) (http.Handler, error)
- type Components
- type Info
- type MediaType
- type OAS
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type Schema
- type SecurityRequirement
- type SecurityScheme
- type SwaggerUIBundleConfig
- type SwaggerUIBundleUrl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UIHandler ¶
func UIHandler(uiBundle SwaggerUIBundleConfig, pathPrefix string, log func(v ...interface{})) (http.Handler, error)
UIHandler serves Swagger UI (index.html and all required js, css assets)
uiBundle argument is a configuration that will be rendered inside index.html as input to the SwaggerUIBundle.
pathPrefix argument allows for setting path under which Swagger UI will be accessible. Eg If we want to have Swagger UI under http://example.com/swagger-ui, we would set pathPrefix to "/swagger-ui" (leading slash, no trailing slash). If no nesting is needed, set pathPrefix to "/".
log argument is being used for logging error when http.ResponseWriter could not write a response
Types ¶
type Components ¶
type Components struct { SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"` Schemas map[string]Schema `json:"schemas,omitempty"` }
Components https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#componentsObject
type Info ¶
Info https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#info-object
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty"`
}
MediaType https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#mediaTypeObject
type OAS ¶
type OAS struct { Openapi string `json:"openapi"` Info Info `json:"info"` Components *Components `json:"components,omitempty"` Paths map[string]PathItem `json:"paths"` }
OAS https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schema
func (*OAS) Merge ¶
Merge allows for merging multiple specifications. It merges paths, components.schemas and components.securitySchemes. Root specification must have initialized these fields:
rootOpenapi := compoas.OAS{ Openapi: "3.0.0", Info: compoas.Info{ Title: "merged spec", Version: "1.0.0", }, Components: &compoas.Components{ Schemas: map[string]compoas.Schema{}, SecuritySchemes: map[string]compoas.SecurityScheme{}, }, Paths: map[string]compoas.PathItem{}, } rootOpenapi.Merge(anotherOpenapi)
type Operation ¶
type Operation struct { Tags []string `json:"tags,omitempty"` RequestBody *RequestBody `json:"requestBody,omitempty"` Responses map[string]Response `json:"responses"` Parameters []Parameter `json:"parameters,omitempty"` Security []SecurityRequirement `json:"security,omitempty"` }
Operation https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#operationObject
type Parameter ¶
type Parameter struct { Name string `json:"name"` In string `json:"in"` Description string `json:"description,omitempty"` Required bool `json:"required,omitempty"` Style string `json:"style,omitempty"` Explode bool `json:"explode,omitempty"` Schema *Schema `json:"schema,omitempty"` Example interface{} `json:"example,omitempty"` }
Parameter https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameterObject
type PathItem ¶
type PathItem struct { Post *Operation `json:"post,omitempty"` Put *Operation `json:"put,omitempty"` Get *Operation `json:"get,omitempty"` Delete *Operation `json:"delete,omitempty"` }
PathItem https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#path-item-object
type RequestBody ¶
RequestBody https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#requestBodyObject
type Response ¶
type Response struct { Description string `json:"description"` Content map[string]MediaType `json:"content,omitempty"` }
Response https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#responseObject
type Schema ¶
type Schema struct { Type string `json:"type,omitempty"` Format string `json:"format,omitempty"` Properties map[string]Schema `json:"properties,omitempty"` Enum []string `json:"enum,omitempty"` Items *Schema `json:"items,omitempty"` Nullable bool `json:"nullable,omitempty"` Ref string `json:"$ref,omitempty"` Required []string `json:"required,omitempty"` MinLength int `json:"minLength,omitempty"` MaxLength int `json:"maxLength,omitempty"` MinItems int `json:"minItems,omitempty"` MaxItems int `json:"maxItems,omitempty"` Description string `json:"description,omitempty"` OneOf []Schema `json:"oneOf,omitempty"` }
Schema https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#schemaObject
type SecurityRequirement ¶
SecurityRequirement https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securityRequirementObject
type SecurityScheme ¶
type SecurityScheme struct { Type string `json:"type"` Scheme string `json:"scheme"` BearerFormat string `json:"bearerFormat,omitempty"` }
SecurityScheme https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#securitySchemeObject
type SwaggerUIBundleConfig ¶
type SwaggerUIBundleConfig struct { Url string `json:"url,omitempty"` Urls []SwaggerUIBundleUrl `json:"urls,omitempty"` }
SwaggerUIBundleConfig reflects config to the SwaggerUIBundle. https://github.com/swagger-api/swagger-ui/blob/bb21c6df52eb12cd4bdbf8c29feb500795595fa8/dist/index.html#L41