Documentation
¶
Index ¶
- func OpenAPIHandler(router chi.Router, cfg config.OpenAPI) http.HandlerFunc
- func SaveOpenAPISpec(spec OpenAPISpec, filePath string) error
- type Components
- type Contact
- type Encoding
- type Example
- type ExternalDocumentation
- type Header
- type Info
- type License
- type Link
- type MediaTypeObject
- type OAuthFlow
- type OAuthFlows
- type OpenAPISpec
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type Schema
- type SecurityScheme
- type Server
- type ServerVariable
- type Tag
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenAPIHandler ¶
func OpenAPIHandler(router chi.Router, cfg config.OpenAPI) http.HandlerFunc
OpenAPIHandler returns an HTTP handler that serves the OpenAPI JSON
func SaveOpenAPISpec ¶
func SaveOpenAPISpec(spec OpenAPISpec, filePath string) error
SaveOpenAPISpec saves the OpenAPI specification to a file
Types ¶
type Components ¶
type Components struct {
Schemas map[string]Schema `json:"schemas,omitempty"`
Responses map[string]Response `json:"responses,omitempty"`
Parameters map[string]Parameter `json:"parameters,omitempty"`
Examples map[string]Example `json:"examples,omitempty"`
RequestBodies map[string]RequestBody `json:"requestBodies,omitempty"`
Headers map[string]Header `json:"headers,omitempty"`
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"`
Links map[string]Link `json:"links,omitempty"`
Callbacks map[string]PathItem `json:"callbacks,omitempty"`
PathItems map[string]PathItem `json:"pathItems,omitempty"` // OpenAPI 3.1 addition
}
Components holds a set of reusable objects
type Contact ¶
type Contact struct {
Name string `json:"name,omitempty"`
URL string `json:"url,omitempty"`
Email string `json:"email,omitempty"`
}
Contact information for the exposed API
type Encoding ¶
type Encoding struct {
ContentType string `json:"contentType,omitempty"`
Headers map[string]Header `json:"headers,omitempty"`
Style string `json:"style,omitempty"`
Explode bool `json:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty"`
}
Encoding for a request body parameter
type Example ¶
type Example struct {
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
Value interface{} `json:"value,omitempty"`
ExternalValue string `json:"externalValue,omitempty"`
}
Example of a media type
type ExternalDocumentation ¶
type ExternalDocumentation struct {
Description string `json:"description,omitempty"`
URL string `json:"url"`
}
ExternalDocumentation allows referencing an external resource for extended documentation
type Header ¶
type Header struct {
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Header follows the structure of Parameter but excluded name and in properties
type Info ¶
type Info struct {
Title string `json:"title"`
Description string `json:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty"`
License *License `json:"license,omitempty"`
Version string `json:"version"`
Summary string `json:"summary,omitempty"`
}
Info provides metadata about the API
type License ¶
type License struct {
Name string `json:"name"`
URL string `json:"url,omitempty"`
Identifier string `json:"identifier,omitempty"`
}
License information for the exposed API
type Link ¶
type Link struct {
OperationID string `json:"operationId,omitempty"`
OperationRef string `json:"operationRef,omitempty"`
Parameters map[string]interface{} `json:"parameters,omitempty"`
RequestBody interface{} `json:"requestBody,omitempty"`
Description string `json:"description,omitempty"`
Server *Server `json:"server,omitempty"`
}
Link represents a possible design-time link for a response
type MediaTypeObject ¶
type MediaTypeObject struct {
Schema *Schema `json:"schema,omitempty"`
Example interface{} `json:"example,omitempty"`
Examples map[string]Example `json:"examples,omitempty"`
Encoding map[string]Encoding `json:"encoding,omitempty"`
}
MediaTypeObject provides schema and examples for the media type identified by its key
type OAuthFlow ¶
type OAuthFlow struct {
AuthorizationURL string `json:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty"`
Scopes map[string]string `json:"scopes"`
}
OAuthFlow configuration details for a supported OAuth Flow
type OAuthFlows ¶
type OAuthFlows struct {
Implicit *OAuthFlow `json:"implicit,omitempty"`
Password *OAuthFlow `json:"password,omitempty"`
ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty"`
AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty"`
}
OAuthFlows allows configuration of the supported OAuth Flows
type OpenAPISpec ¶
type OpenAPISpec struct {
OpenAPI string `json:"openapi"` // Should be "3.1.0"
Info Info `json:"info"`
Servers []Server `json:"servers,omitempty"`
Paths map[string]PathItem `json:"paths"`
Components *Components `json:"components,omitempty"`
Tags []Tag `json:"tags,omitempty"`
Security []map[string][]string `json:"security,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
Webhooks map[string]PathItem `json:"webhooks,omitempty"`
JsonSchemaDialect string `json:"jsonSchemaDialect,omitempty"`
}
OpenAPISpec defines the root structure for an OpenAPI 3.1 document
func GenerateOpenAPISpec ¶
func GenerateOpenAPISpec(r chi.Router, cfg config.OpenAPI) OpenAPISpec
GenerateOpenAPISpec iterates over the router's registered routes and builds an OpenAPI 3.1 document
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"`
Summary string `json:"summary,omitempty"`
Description string `json:"description,omitempty"`
OperationID string `json:"operationId,omitempty"`
Parameters []Parameter `json:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty"`
Responses map[string]Response `json:"responses"`
Deprecated bool `json:"deprecated,omitempty"`
Security []map[string][]string `json:"security,omitempty"`
Servers []Server `json:"servers,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
}
Operation represents an HTTP operation on a path
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
In string `json:"in"` // "query", "header", "path", "cookie"
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
Deprecated bool `json:"deprecated,omitempty"`
Schema *Schema `json:"schema,omitempty"`
}
Parameter describes a single operation parameter
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"`
Content map[string]MediaTypeObject `json:"content"`
Required bool `json:"required,omitempty"`
}
RequestBody describes a single request body
type Response ¶
type Response struct {
Description string `json:"description"`
Headers map[string]Header `json:"headers,omitempty"`
Content map[string]MediaTypeObject `json:"content,omitempty"`
Links map[string]Link `json:"links,omitempty"`
}
Response describes a single response from an API operation
type Schema ¶
type Schema struct {
Ref string `json:"$ref,omitempty"`
Type string `json:"type,omitempty"`
Format string `json:"format,omitempty"`
Items *Schema `json:"items,omitempty"`
Properties map[string]*Schema `json:"properties,omitempty"`
AdditionalProperties interface{} `json:"additionalProperties,omitempty"`
Description string `json:"description,omitempty"`
Default interface{} `json:"default,omitempty"`
Required []string `json:"required,omitempty"`
Enum []interface{} `json:"enum,omitempty"`
Example interface{} `json:"example,omitempty"`
OneOf []*Schema `json:"oneOf,omitempty"`
AnyOf []*Schema `json:"anyOf,omitempty"`
AllOf []*Schema `json:"allOf,omitempty"`
Not *Schema `json:"not,omitempty"`
Title string `json:"title,omitempty"`
ReadOnly bool `json:"readOnly,omitempty"`
WriteOnly bool `json:"writeOnly,omitempty"`
}
Schema Object allows the definition of input and output data types
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
In string `json:"in,omitempty"`
Scheme string `json:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty"`
Flows *OAuthFlows `json:"flows,omitempty"`
OpenIDConnectURL string `json:"openIdConnectUrl,omitempty"`
}
SecurityScheme defines a security scheme
type Server ¶
type Server struct {
URL string `json:"url"`
Description string `json:"description,omitempty"`
Variables map[string]ServerVariable `json:"variables,omitempty"`
}
Server represents a server
type ServerVariable ¶
type ServerVariable struct {
Enum []string `json:"enum,omitempty"`
Default string `json:"default"`
Description string `json:"description,omitempty"`
}
ServerVariable represents a server variable for server URL template substitution
type Tag ¶
type Tag struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty"`
}
Tag adds metadata to a single tag that is used by Operation