Documentation
¶
Index ¶
- Constants
- Variables
- type Components
- type DocIn
- type DocOut
- type Docs
- type Info
- type MediaType
- type Middleware
- type OpenAPI
- type Operation
- type Parameter
- type PathItem
- type RequestBody
- type Response
- type Router
- func (r *Router) AddServerEndpoint(url string, description string)
- func (r *Router) Delete(pattern string, handler http.HandlerFunc, doc ...Docs)
- func (r *Router) Get(pattern string, handler http.HandlerFunc, doc ...Docs)
- func (r *Router) Group(basePath string, fn func(*Router))
- func (r *Router) HandleStatus(httpStatus int, handler http.HandlerFunc)
- func (r *Router) Head(pattern string, handler http.HandlerFunc, doc ...Docs)
- func (r *Router) OpenAPI() *OpenAPI
- func (r *Router) OperationID(s string) string
- func (r *Router) Patch(pattern string, handler http.HandlerFunc, doc ...Docs)
- func (r *Router) Post(pattern string, handler http.HandlerFunc, doc ...Docs)
- func (r *Router) Put(pattern string, handler http.HandlerFunc, doc ...Docs)
- func (r *Router) RedirectTrailingSlash(redirect bool)
- func (r *Router) ServeFile(pattern string, filepath string)
- func (r *Router) ServeFiles(pattern string, fs http.FileSystem)
- func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *Router) Use(middleware Middleware)
- func (r *Router) UseOpenapiDocs(use bool)
- type Schema
- type SecurityScheme
- type Server
- type Tag
Constants ¶
View Source
const HeaderFlagDoNotIntercept = "do_not_intercept"
Variables ¶
View Source
var ( DefaultRedirectTrailingSlash = false DefaultRedirectStatusCode = http.StatusTemporaryRedirect // or http.StatusMovedPermanently DefaultUseOpenapiDocs = false OpenApiVersion = "3.0.1" )
Functions ¶
This section is empty.
Types ¶
type Components ¶
type Components struct {
Schemas map[string]Schema `json:"schemas,omitempty"` // Reusable schemas
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty"` // Security schemes
}
Components holds reusable components such as schemas and security schemes.
type Docs ¶
type Docs struct {
Tags []string // Tags for the operation
Summary string // Short summary of the operation
Description string // Operation description
Parameters []Parameter // Parameters for the operation
RequestBody *RequestBody // Request body for the operation
Responses map[string]Response // Expected responses
Security []map[string][]string // Security requirements
In map[string]DocIn
Out map[string]DocOut
}
type Info ¶
type Info struct {
Title string `json:"title" validate:"required"` // API title
Description string `json:"description,omitempty"` // API description
Version string `json:"version" validate:"required"` // API version
}
Info represents the API metadata.
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty"` // Schema describing the type
}
MediaType represents the media type of a request or response body.
type OpenAPI ¶
type OpenAPI struct {
Openapi string `json:"openapi" validate:"required"` // OpenAPI version (e.g., "3.0.1")
Info Info `json:"info" validate:"required"` // API information
Servers []Server `json:"servers,omitempty"` // Server details
Paths map[string]PathItem `json:"paths" validate:"required"` // Paths and operations
Components Components `json:"components,omitempty"` // Components such as schemas and security schemes
Security []map[string][]string `json:"security,omitempty"` // Global security settings
Tags []Tag `json:"tags,omitempty"` // Tags for API organization
}
OpenAPI represents the root OpenAPI document.
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty"` // Tags for the operation
Summary string `json:"summary,omitempty"` // Short summary of the operation
Description string `json:"description,omitempty"` // Operation description
OperationID string `json:"operationId,omitempty"` // Unique operation ID
Parameters []Parameter `json:"parameters,omitempty"` // Parameters for the operation
RequestBody *RequestBody `json:"requestBody,omitempty"` // Request body for the operation
Responses map[string]Response `json:"responses" validate:"required"` // Expected responses
Security []map[string][]string `json:"security,omitempty"` // Security requirements
}
Operation describes a single API operation on a path.
type Parameter ¶
type Parameter struct {
Name string `json:"name" validate:"required"` // Parameter name
In string `json:"in" validate:"required"` // Location (e.g., "query", "header", "path")
Description string `json:"description,omitempty"` // Parameter description
Required bool `json:"required,omitempty"` // Is parameter required?
Schema *Schema `json:"schema,omitempty"` // Schema defining the type
}
Parameter represents a single parameter for an operation.
type PathItem ¶
type PathItem struct {
Get *Operation `json:"get,omitempty"` // GET operation
Post *Operation `json:"post,omitempty"` // POST operation
Put *Operation `json:"put,omitempty"` // PUT operation
Delete *Operation `json:"delete,omitempty"` // DELETE operation
Patch *Operation `json:"patch,omitempty"` // PATCH operation
}
PathItem describes the operations available on a single path.
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty"` // Request body description
Content map[string]MediaType `json:"content"` // Media types supported by the request
Required bool `json:"required,omitempty"` // Is request body required?
}
RequestBody represents a request body for an operation.
type Response ¶
type Response struct {
Description string `json:"description" validate:"required"` // Response description
Content map[string]MediaType `json:"content,omitempty"` // Media types produced by the response
}
Response describes a single response from an API operation.
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) AddServerEndpoint ¶
func (*Router) Delete ¶
func (r *Router) Delete(pattern string, handler http.HandlerFunc, doc ...Docs)
func (*Router) HandleStatus ¶ added in v0.2.0
func (r *Router) HandleStatus(httpStatus int, handler http.HandlerFunc)
func (*Router) OperationID ¶
func (*Router) Patch ¶
func (r *Router) Patch(pattern string, handler http.HandlerFunc, doc ...Docs)
func (*Router) RedirectTrailingSlash ¶
func (*Router) ServeFiles ¶
func (r *Router) ServeFiles(pattern string, fs http.FileSystem)
func (*Router) Use ¶
func (r *Router) Use(middleware Middleware)
func (*Router) UseOpenapiDocs ¶
type Schema ¶
type Schema struct {
Ref string `json:"$ref,omitempty"` // Reference to a schema
Type string `json:"type,omitempty"` // Data type (e.g., "string", "object")
Format string `json:"format,omitempty"` // Data format (e.g., "uuid", "email")
Properties map[string]Schema `json:"properties,omitempty"` // Properties of the object
Items *Schema `json:"items,omitempty"` // Schema for array items
Required []string `json:"required,omitempty"` // Required properties
}
Schema represents the structure of a request or response body.
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type" validate:"required"` // Security scheme type (e.g., "http", "apiKey")
Scheme string `json:"scheme,omitempty"` // HTTP Authorization scheme (e.g., "bearer")
BearerFormat string `json:"bearerFormat,omitempty"` // Bearer token format
}
SecurityScheme defines a security scheme for the API.
Click to show internal directories.
Click to hide internal directories.