Documentation
¶
Overview ¶
Package openapi provides comprehensive OpenAPI 3.0 documentation generation for Go web applications. It supports automatic schema generation from Go types, endpoint documentation, and multiple output formats including JSON, YAML, and HTML.
Index ¶
- Constants
- func AuthEndpoints(generator *Generator) error
- func BoolPtr(b bool) *bool
- func CRUDEndpoints(generator *Generator, basePath string, resourceType reflect.Type, ...) error
- func CommonHeaders() map[string]HeaderInfo
- func ExampleUsage()
- func Float64Ptr(f float64) *float64
- func GenerateAndServe(generator *Generator, port int) error
- func GenerateExample(schema Schema) any
- func GeneratedAt() string
- func HTTPMethodFromString(method string) string
- func HealthCheckEndpoint(generator *Generator) error
- func IntPtr(i int) *int
- func IsValidHTTPMethod(method string) bool
- func SimpleServe(outputDir string, port int) error
- func StandardResponses() map[int]ResponseInfo
- func StringPtr(s string) *string
- func ValidateRequest(generator *Generator, method, path string, body any) error
- func ValidateSchema(schema Schema) error
- type Callback
- type Components
- type Config
- type Contact
- type Encoding
- type EndpointBuilder
- func (eb *EndpointBuilder) Build() EndpointOptions
- func (eb *EndpointBuilder) ConvertToOperation() Operation
- func (eb *EndpointBuilder) Deprecated() *EndpointBuilder
- func (eb *EndpointBuilder) Description(description string) *EndpointBuilder
- func (eb *EndpointBuilder) HeaderParam(name, description string, required bool, t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) OperationID(id string) *EndpointBuilder
- func (eb *EndpointBuilder) PathParam(name, description string, t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) QueryParam(name, description string, required bool, t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) RequestBody(description string, required bool, contentTypes []string, t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) RequestExample(example any) *EndpointBuilder
- func (eb *EndpointBuilder) RequestType(t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) Response(statusCode int, description string, contentTypes []string, t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) ResponseExample(example any) *EndpointBuilder
- func (eb *EndpointBuilder) ResponseHeader(statusCode int, name, description string, t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) ResponseType(t reflect.Type) *EndpointBuilder
- func (eb *EndpointBuilder) Security(requirements ...SecurityRequirement) *EndpointBuilder
- func (eb *EndpointBuilder) Summary(summary string) *EndpointBuilder
- func (eb *EndpointBuilder) Tags(tags ...string) *EndpointBuilder
- type EndpointOptions
- type ErrorResponse
- type Example
- type ExternalDocumentation
- type Generator
- func (g *Generator) AddCustomParameter(name string, parameter Parameter)
- func (g *Generator) AddCustomResponse(name string, response Response)
- func (g *Generator) AddCustomSchema(name string, schema Schema)
- func (g *Generator) AddEndpoint(method, path string, options EndpointOptions) error
- func (g *Generator) AddEndpointWithBuilder(method, path string, builder *EndpointBuilder) error
- func (g *Generator) AddGlobalSecurity(requirements ...SecurityRequirement)
- func (g *Generator) AddSecurityScheme(name string, scheme SecurityScheme)
- func (g *Generator) AddServer(server Server)
- func (g *Generator) AddTag(tag Tag)
- func (g *Generator) Clone() *Generator
- func (g *Generator) GenerateSpec() (*OpenAPISpec, error)
- func (g *Generator) GetEndpoint(method, path string) (EndpointOptions, bool)
- func (g *Generator) GetOutputPath(filename string) string
- func (g *Generator) GetSchemaGenerator() *SchemaGenerator
- func (g *Generator) GetSpec() *OpenAPISpec
- func (g *Generator) GetStatistics() Statistics
- func (g *Generator) ListEndpoints() map[string][]string
- func (g *Generator) Merge(other *Generator) error
- func (g *Generator) RemoveEndpoint(method, path string)
- func (g *Generator) Reset()
- func (g *Generator) SetExternalDocs(docs ExternalDocumentation)
- func (g *Generator) UpdateInfo(info Info)
- type Header
- type HeaderInfo
- type Info
- type License
- type Link
- type MediaType
- type OAuthFlow
- type OAuthFlows
- type OpenAPISpec
- type Operation
- type PaginatedResponse
- type Parameter
- type ParameterInfo
- type PathItem
- type RequestBody
- type RequestBodyInfo
- type Response
- type ResponseInfo
- type Schema
- type SchemaGenerator
- type SecurityRequirement
- type SecurityScheme
- type Server
- type ServerVariable
- type Statistics
- type SuccessResponse
- type Tag
- type Writer
- func (w *Writer) CleanOutputDir() error
- func (w *Writer) GenerateMarkdownDocs() error
- func (w *Writer) GetGeneratedFiles() []string
- func (w *Writer) WatchAndRegenerate(interval time.Duration, callback func() error)
- func (w *Writer) WriteFiles() error
- func (w *Writer) WriteHTML(spec *OpenAPISpec) error
- func (w *Writer) WriteJSON(spec *OpenAPISpec) error
- func (w *Writer) WriteToFile(filename string, format string) error
- func (w *Writer) WriteYAML(spec *OpenAPISpec) error
- type XML
Constants ¶
const Version = "0.1.0"
Version of the OpenAPI generator package
Variables ¶
This section is empty.
Functions ¶
func AuthEndpoints ¶
AuthEndpoints creates standard authentication endpoints
func CRUDEndpoints ¶
func CRUDEndpoints(generator *Generator, basePath string, resourceType reflect.Type, resourceName string) error
CRUDEndpoints creates a complete set of CRUD endpoints for a resource
func CommonHeaders ¶
func CommonHeaders() map[string]HeaderInfo
CommonHeaders returns common HTTP headers for API responses
func GenerateAndServe ¶
GenerateAndServe generates documentation and starts a simple HTTP server to serve it
func GenerateExample ¶
GenerateExample generates an example value for a schema
func GeneratedAt ¶
func GeneratedAt() string
GeneratedAt returns the current timestamp for documentation generation
func HTTPMethodFromString ¶
HTTPMethodFromString converts a string to an HTTP method
func HealthCheckEndpoint ¶
HealthCheckEndpoint creates a standard health check endpoint
func IsValidHTTPMethod ¶
IsValidHTTPMethod checks if a method is a valid HTTP method
func SimpleServe ¶
func StandardResponses ¶
func StandardResponses() map[int]ResponseInfo
StandardResponses returns common HTTP response definitions
func ValidateRequest ¶
ValidateRequest validates a request against the OpenAPI specification
func ValidateSchema ¶
ValidateSchema performs basic validation on a schema
Types ¶
type Components ¶
type Components struct {
Schemas map[string]Schema `json:"schemas,omitempty" yaml:"schemas,omitempty"`
Responses map[string]Response `json:"responses,omitempty" yaml:"responses,omitempty"`
Parameters map[string]Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
Examples map[string]Example `json:"examples,omitempty" yaml:"examples,omitempty"`
RequestBodies map[string]RequestBody `json:"requestBodies,omitempty" yaml:"requestBodies,omitempty"`
Headers map[string]Header `json:"headers,omitempty" yaml:"headers,omitempty"`
SecuritySchemes map[string]SecurityScheme `json:"securitySchemes,omitempty" yaml:"securitySchemes,omitempty"`
Links map[string]Link `json:"links,omitempty" yaml:"links,omitempty"`
Callbacks map[string]Callback `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
}
Components holds a set of reusable objects for different aspects of the OAS
type Config ¶
type Config struct {
// API Information
Title string
Description string
Version string
TermsOfService string
Contact *Contact
License *License
// Server Information
Servers []Server
// Security
SecuritySchemes map[string]SecurityScheme
GlobalSecurity []SecurityRequirement
// Tags
Tags []Tag
// External Documentation
ExternalDocs *ExternalDocumentation
// Output Configuration
OutputDir string
GenerateJSON bool
GenerateYAML bool
GenerateHTML bool
PrettyPrint bool
// Schema Generation Options
UseReferences bool
IncludeExamples bool
ValidateSchemas bool
CustomTypeMapping map[reflect.Type]Schema
}
Config contains configuration for the OpenAPI generator
type Contact ¶
type Contact struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
Email string `json:"email,omitempty" yaml:"email,omitempty"`
}
Contact information for the exposed API
type Encoding ¶
type Encoding struct {
ContentType string `json:"contentType,omitempty" yaml:"contentType,omitempty"`
Headers map[string]Header `json:"headers,omitempty" yaml:"headers,omitempty"`
Style string `json:"style,omitempty" yaml:"style,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
}
Encoding defines encoding definition applied to a single schema property
type EndpointBuilder ¶
type EndpointBuilder struct {
// contains filtered or unexported fields
}
EndpointBuilder helps build endpoint documentation
func NewEndpointBuilder ¶
func NewEndpointBuilder() *EndpointBuilder
NewEndpointBuilder creates a new endpoint builder
func RESTEndpoint ¶
func RESTEndpoint(method, path, summary string, resourceType reflect.Type) *EndpointBuilder
RESTEndpoint creates a REST endpoint with standard responses
func SimpleEndpoint ¶
func SimpleEndpoint(method, path, summary string) *EndpointBuilder
SimpleEndpoint creates a simple endpoint with minimal configuration
func (*EndpointBuilder) Build ¶
func (eb *EndpointBuilder) Build() EndpointOptions
Build builds the endpoint options
func (*EndpointBuilder) ConvertToOperation ¶
func (eb *EndpointBuilder) ConvertToOperation() Operation
ConvertToOperation converts endpoint options to an OpenAPI operation
func (*EndpointBuilder) Deprecated ¶
func (eb *EndpointBuilder) Deprecated() *EndpointBuilder
Deprecated marks the endpoint as deprecated
func (*EndpointBuilder) Description ¶
func (eb *EndpointBuilder) Description(description string) *EndpointBuilder
Description sets the endpoint description
func (*EndpointBuilder) HeaderParam ¶
func (eb *EndpointBuilder) HeaderParam(name, description string, required bool, t reflect.Type) *EndpointBuilder
HeaderParam adds a header parameter
func (*EndpointBuilder) OperationID ¶
func (eb *EndpointBuilder) OperationID(id string) *EndpointBuilder
OperationID sets the operation ID
func (*EndpointBuilder) PathParam ¶
func (eb *EndpointBuilder) PathParam(name, description string, t reflect.Type) *EndpointBuilder
PathParam adds a path parameter
func (*EndpointBuilder) QueryParam ¶
func (eb *EndpointBuilder) QueryParam(name, description string, required bool, t reflect.Type) *EndpointBuilder
QueryParam adds a query parameter
func (*EndpointBuilder) RequestBody ¶
func (eb *EndpointBuilder) RequestBody(description string, required bool, contentTypes []string, t reflect.Type) *EndpointBuilder
RequestBody sets the request body information
func (*EndpointBuilder) RequestExample ¶
func (eb *EndpointBuilder) RequestExample(example any) *EndpointBuilder
RequestExample sets the request example
func (*EndpointBuilder) RequestType ¶
func (eb *EndpointBuilder) RequestType(t reflect.Type) *EndpointBuilder
RequestType sets the request body type
func (*EndpointBuilder) Response ¶
func (eb *EndpointBuilder) Response(statusCode int, description string, contentTypes []string, t reflect.Type) *EndpointBuilder
Response adds a response definition
func (*EndpointBuilder) ResponseExample ¶
func (eb *EndpointBuilder) ResponseExample(example any) *EndpointBuilder
ResponseExample sets the response example
func (*EndpointBuilder) ResponseHeader ¶
func (eb *EndpointBuilder) ResponseHeader(statusCode int, name, description string, t reflect.Type) *EndpointBuilder
ResponseHeader adds a header to a response
func (*EndpointBuilder) ResponseType ¶
func (eb *EndpointBuilder) ResponseType(t reflect.Type) *EndpointBuilder
ResponseType sets the response type
func (*EndpointBuilder) Security ¶
func (eb *EndpointBuilder) Security(requirements ...SecurityRequirement) *EndpointBuilder
Security adds security requirements
func (*EndpointBuilder) Summary ¶
func (eb *EndpointBuilder) Summary(summary string) *EndpointBuilder
Summary sets the endpoint summary
func (*EndpointBuilder) Tags ¶
func (eb *EndpointBuilder) Tags(tags ...string) *EndpointBuilder
Tags sets the endpoint tags
type EndpointOptions ¶
type EndpointOptions struct {
// Basic information
Summary string
Description string
Tags []string
OperationID string
Deprecated bool
// Request/Response types
RequestType reflect.Type
ResponseType reflect.Type
// Parameters
PathParams []ParameterInfo
QueryParams []ParameterInfo
HeaderParams []ParameterInfo
// Request body
RequestBody *RequestBodyInfo
// Responses
Responses map[int]ResponseInfo
// Security
Security []SecurityRequirement
// Examples
RequestExample any
ResponseExample any
}
EndpointOptions contains all the options for documenting an endpoint
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error" description:"Error message"`
Code int `json:"code" description:"Error code"`
Details string `json:"details,omitempty" description:"Additional error details"`
}
ErrorResponse represents a standard error response
type Example ¶
type Example struct {
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Value any `json:"value,omitempty" yaml:"value,omitempty"`
ExternalValue string `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
}
Example object
type ExternalDocumentation ¶
type ExternalDocumentation struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
URL string `json:"url" yaml:"url"`
}
ExternalDocumentation allows referencing an external resource for extended documentation
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator is the main OpenAPI documentation generator
func NewBasicGenerator ¶
func NewGenerator ¶
NewGenerator creates a new OpenAPI generator
func QuickStart ¶
QuickStart creates a generator with sensible defaults and basic configuration
func (*Generator) AddCustomParameter ¶
AddCustomParameter adds a custom parameter to the components
func (*Generator) AddCustomResponse ¶
AddCustomResponse adds a custom response to the components
func (*Generator) AddCustomSchema ¶
AddCustomSchema adds a custom schema to the components
func (*Generator) AddEndpoint ¶
func (g *Generator) AddEndpoint(method, path string, options EndpointOptions) error
AddEndpoint adds an endpoint to the documentation
func (*Generator) AddEndpointWithBuilder ¶
func (g *Generator) AddEndpointWithBuilder(method, path string, builder *EndpointBuilder) error
AddEndpointWithBuilder adds an endpoint using the builder pattern
func (*Generator) AddGlobalSecurity ¶
func (g *Generator) AddGlobalSecurity(requirements ...SecurityRequirement)
AddGlobalSecurity adds global security requirements
func (*Generator) AddSecurityScheme ¶
func (g *Generator) AddSecurityScheme(name string, scheme SecurityScheme)
AddSecurityScheme adds a security scheme
func (*Generator) GenerateSpec ¶
func (g *Generator) GenerateSpec() (*OpenAPISpec, error)
GenerateSpec generates the complete OpenAPI specification
func (*Generator) GetEndpoint ¶
func (g *Generator) GetEndpoint(method, path string) (EndpointOptions, bool)
GetEndpoint retrieves an endpoint's documentation
func (*Generator) GetOutputPath ¶
GetOutputPath returns the full output path for a given filename
func (*Generator) GetSchemaGenerator ¶
func (g *Generator) GetSchemaGenerator() *SchemaGenerator
GetSchemaGenerator returns the schema generator for advanced usage
func (*Generator) GetSpec ¶
func (g *Generator) GetSpec() *OpenAPISpec
GetSpec returns the current specification
func (*Generator) GetStatistics ¶
func (g *Generator) GetStatistics() Statistics
GetStatistics returns statistics about the current documentation
func (*Generator) ListEndpoints ¶
ListEndpoints returns all registered endpoints
func (*Generator) RemoveEndpoint ¶
RemoveEndpoint removes an endpoint from the documentation
func (*Generator) Reset ¶
func (g *Generator) Reset()
Reset clears all endpoints and resets the specification
func (*Generator) SetExternalDocs ¶
func (g *Generator) SetExternalDocs(docs ExternalDocumentation)
SetExternalDocs sets external documentation
func (*Generator) UpdateInfo ¶
UpdateInfo updates the API information
type Header ¶
type Header struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
Style string `json:"style,omitempty" yaml:"style,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Examples map[string]Example `json:"examples,omitempty" yaml:"examples,omitempty"`
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
}
Header follows the structure of the Parameter Object
type HeaderInfo ¶
HeaderInfo contains information about a response header
type Info ¶
type Info struct {
Title string `json:"title" yaml:"title"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
TermsOfService string `json:"termsOfService,omitempty" yaml:"termsOfService,omitempty"`
Contact *Contact `json:"contact,omitempty" yaml:"contact,omitempty"`
License *License `json:"license,omitempty" yaml:"license,omitempty"`
Version string `json:"version" yaml:"version"`
}
Info provides metadata about the API
type License ¶
type License struct {
Name string `json:"name" yaml:"name"`
URL string `json:"url,omitempty" yaml:"url,omitempty"`
}
License information for the exposed API
type Link ¶
type Link struct {
OperationRef string `json:"operationRef,omitempty" yaml:"operationRef,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Parameters map[string]any `json:"parameters,omitempty" yaml:"parameters,omitempty"`
RequestBody any `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Server *Server `json:"server,omitempty" yaml:"server,omitempty"`
}
Link represents a possible design-time link for a response
type MediaType ¶
type MediaType struct {
Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Examples map[string]Example `json:"examples,omitempty" yaml:"examples,omitempty"`
Encoding map[string]Encoding `json:"encoding,omitempty" yaml:"encoding,omitempty"`
}
MediaType provides schema and examples for the media type identified by its key
type OAuthFlow ¶
type OAuthFlow struct {
AuthorizationURL string `json:"authorizationUrl,omitempty" yaml:"authorizationUrl,omitempty"`
TokenURL string `json:"tokenUrl,omitempty" yaml:"tokenUrl,omitempty"`
RefreshURL string `json:"refreshUrl,omitempty" yaml:"refreshUrl,omitempty"`
Scopes map[string]string `json:"scopes" yaml:"scopes"`
}
OAuthFlow configuration details for a supported OAuth Flow
type OAuthFlows ¶
type OAuthFlows struct {
Implicit *OAuthFlow `json:"implicit,omitempty" yaml:"implicit,omitempty"`
Password *OAuthFlow `json:"password,omitempty" yaml:"password,omitempty"`
ClientCredentials *OAuthFlow `json:"clientCredentials,omitempty" yaml:"clientCredentials,omitempty"`
AuthorizationCode *OAuthFlow `json:"authorizationCode,omitempty" yaml:"authorizationCode,omitempty"`
}
OAuthFlows allows configuration of the supported OAuth Flows
type OpenAPISpec ¶
type OpenAPISpec struct {
OpenAPI string `json:"openapi" yaml:"openapi"`
Info Info `json:"info" yaml:"info"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
Paths map[string]PathItem `json:"paths" yaml:"paths"`
Components *Components `json:"components,omitempty" yaml:"components,omitempty"`
Security []SecurityRequirement `json:"security,omitempty" yaml:"security,omitempty"`
Tags []Tag `json:"tags,omitempty" yaml:"tags,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}
OpenAPISpec represents the root OpenAPI 3.0 specification
func NewOpenAPISpec ¶
func NewOpenAPISpec() *OpenAPISpec
NewOpenAPISpec creates a new OpenAPI specification with default values
func (*OpenAPISpec) ToJSON ¶
func (spec *OpenAPISpec) ToJSON() ([]byte, error)
ToJSON converts the OpenAPI spec to JSON
type Operation ¶
type Operation struct {
Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"`
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
OperationID string `json:"operationId,omitempty" yaml:"operationId,omitempty"`
Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
RequestBody *RequestBody `json:"requestBody,omitempty" yaml:"requestBody,omitempty"`
Responses map[string]Response `json:"responses" yaml:"responses"`
Callbacks map[string]Callback `json:"callbacks,omitempty" yaml:"callbacks,omitempty"`
Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
Security []SecurityRequirement `json:"security,omitempty" yaml:"security,omitempty"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
}
Operation describes a single API operation on a path
type PaginatedResponse ¶
type PaginatedResponse struct {
Data any `json:"data" description:"Response data"`
Page int `json:"page" description:"Current page number"`
PerPage int `json:"per_page" description:"Items per page"`
Total int `json:"total" description:"Total number of items"`
TotalPages int `json:"total_pages" description:"Total number of pages"`
}
PaginatedResponse represents a paginated response
type Parameter ¶
type Parameter struct {
Name string `json:"name" yaml:"name"`
In string `json:"in" yaml:"in"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
Deprecated bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
AllowEmptyValue bool `json:"allowEmptyValue,omitempty" yaml:"allowEmptyValue,omitempty"`
Style string `json:"style,omitempty" yaml:"style,omitempty"`
Explode *bool `json:"explode,omitempty" yaml:"explode,omitempty"`
AllowReserved bool `json:"allowReserved,omitempty" yaml:"allowReserved,omitempty"`
Schema *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
Examples map[string]Example `json:"examples,omitempty" yaml:"examples,omitempty"`
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
}
Parameter describes a single operation parameter
type ParameterInfo ¶
type ParameterInfo struct {
Name string
Description string
Required bool
Type reflect.Type
Example any
Schema *Schema
}
ParameterInfo contains information about a parameter
func FilterParams ¶
func FilterParams() []ParameterInfo
FilterParams returns common filtering parameters
func PaginationParams ¶
func PaginationParams() []ParameterInfo
PaginationParams returns common pagination parameters
type PathItem ¶
type PathItem struct {
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
Summary string `json:"summary,omitempty" yaml:"summary,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Get *Operation `json:"get,omitempty" yaml:"get,omitempty"`
Put *Operation `json:"put,omitempty" yaml:"put,omitempty"`
Post *Operation `json:"post,omitempty" yaml:"post,omitempty"`
Delete *Operation `json:"delete,omitempty" yaml:"delete,omitempty"`
Options *Operation `json:"options,omitempty" yaml:"options,omitempty"`
Head *Operation `json:"head,omitempty" yaml:"head,omitempty"`
Patch *Operation `json:"patch,omitempty" yaml:"patch,omitempty"`
Trace *Operation `json:"trace,omitempty" yaml:"trace,omitempty"`
Servers []Server `json:"servers,omitempty" yaml:"servers,omitempty"`
Parameters []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}
PathItem describes the operations available on a single path
type RequestBody ¶
type RequestBody struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Content map[string]MediaType `json:"content" yaml:"content"`
Required bool `json:"required,omitempty" yaml:"required,omitempty"`
}
RequestBody describes a single request body
type RequestBodyInfo ¶
type RequestBodyInfo struct {
Description string
Required bool
ContentTypes []string
Type reflect.Type
Example any
Schema *Schema
}
RequestBodyInfo contains information about request body
type Response ¶
type Response struct {
Description string `json:"description" yaml:"description"`
Headers map[string]Header `json:"headers,omitempty" yaml:"headers,omitempty"`
Content map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
Links map[string]Link `json:"links,omitempty" yaml:"links,omitempty"`
}
Response describes a single response from an API Operation
type ResponseInfo ¶
type ResponseInfo struct {
Description string
ContentTypes []string
Type reflect.Type
Example any
Schema *Schema
Headers map[string]HeaderInfo
}
ResponseInfo contains information about a response
type Schema ¶
type Schema struct {
// Core schema properties
Type string `json:"type,omitempty" yaml:"type,omitempty"`
AllOf []Schema `json:"allOf,omitempty" yaml:"allOf,omitempty"`
OneOf []Schema `json:"oneOf,omitempty" yaml:"oneOf,omitempty"`
AnyOf []Schema `json:"anyOf,omitempty" yaml:"anyOf,omitempty"`
Not *Schema `json:"not,omitempty" yaml:"not,omitempty"`
Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`
Properties map[string]Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
AdditionalProperties any `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Format string `json:"format,omitempty" yaml:"format,omitempty"`
Default any `json:"default,omitempty" yaml:"default,omitempty"`
// Validation properties
MultipleOf *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
Maximum *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
ExclusiveMaximum *bool `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
Minimum *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
ExclusiveMinimum *bool `json:"exclusiveMinimum,omitempty" yaml:"exclusiveMinimum,omitempty"`
MaxLength *int `json:"maxLength,omitempty" yaml:"maxLength,omitempty"`
MinLength *int `json:"minLength,omitempty" yaml:"minLength,omitempty"`
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`
MaxItems *int `json:"maxItems,omitempty" yaml:"maxItems,omitempty"`
MinItems *int `json:"minItems,omitempty" yaml:"minItems,omitempty"`
UniqueItems *bool `json:"uniqueItems,omitempty" yaml:"uniqueItems,omitempty"`
MaxProperties *int `json:"maxProperties,omitempty" yaml:"maxProperties,omitempty"`
MinProperties *int `json:"minProperties,omitempty" yaml:"minProperties,omitempty"`
Required []string `json:"required,omitempty" yaml:"required,omitempty"`
Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"`
// OpenAPI-specific properties
Title string `json:"title,omitempty" yaml:"title,omitempty"`
Example any `json:"example,omitempty" yaml:"example,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
Deprecated *bool `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
ReadOnly *bool `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
WriteOnly *bool `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
XML *XML `json:"xml,omitempty" yaml:"xml,omitempty"`
// Reference
Ref string `json:"$ref,omitempty" yaml:"$ref,omitempty"`
}
Schema represents a schema object
type SchemaGenerator ¶
type SchemaGenerator struct {
// contains filtered or unexported fields
}
SchemaGenerator handles the generation of OpenAPI schemas from Go types
func NewSchemaGenerator ¶
func NewSchemaGenerator() *SchemaGenerator
NewSchemaGenerator creates a new schema generator
func (*SchemaGenerator) GenerateSchema ¶
func (sg *SchemaGenerator) GenerateSchema(t reflect.Type) Schema
GenerateSchema generates an OpenAPI schema from a Go type
func (*SchemaGenerator) GenerateSchemaFromValue ¶
func (sg *SchemaGenerator) GenerateSchemaFromValue(v any) Schema
GenerateSchemaFromValue generates a schema from a value (useful for examples)
func (*SchemaGenerator) GenerateSchemaWithName ¶
func (sg *SchemaGenerator) GenerateSchemaWithName(t reflect.Type, name string) Schema
GenerateSchemaWithName generates an OpenAPI schema with a specific name
func (*SchemaGenerator) GetSchemas ¶
func (sg *SchemaGenerator) GetSchemas() map[string]Schema
GetSchemas returns all generated schemas
type SecurityRequirement ¶
SecurityRequirement lists the required security schemes to execute this operation
type SecurityScheme ¶
type SecurityScheme struct {
Type string `json:"type" yaml:"type"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
In string `json:"in,omitempty" yaml:"in,omitempty"`
Scheme string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
BearerFormat string `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`
Flows *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`
OpenIDConnectURL string `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"`
}
SecurityScheme defines a security scheme that can be used by the operations
type Server ¶
type Server struct {
URL string `json:"url" yaml:"url"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Variables map[string]ServerVariable `json:"variables,omitempty" yaml:"variables,omitempty"`
}
Server represents a server
type ServerVariable ¶
type ServerVariable struct {
Enum []string `json:"enum,omitempty" yaml:"enum,omitempty"`
Default string `json:"default" yaml:"default"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
}
ServerVariable represents a server variable for server URL template substitution
type Statistics ¶
type Statistics struct {
TotalEndpoints int
TotalSchemas int
EndpointsByMethod map[string]int
EndpointsByTag map[string]int
}
Statistics returns statistics about the generated documentation
type SuccessResponse ¶
type SuccessResponse struct {
Message string `json:"message" description:"Success message"`
Data any `json:"data,omitempty" description:"Response data"`
}
SuccessResponse represents a standard success response
type Tag ¶
type Tag struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
ExternalDocs *ExternalDocumentation `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}
Tag adds metadata to a single tag that is used by the Operation Object
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer handles writing OpenAPI documentation to various formats
func (*Writer) CleanOutputDir ¶
CleanOutputDir removes all generated files
func (*Writer) GenerateMarkdownDocs ¶
GenerateMarkdownDocs generates markdown documentation
func (*Writer) GetGeneratedFiles ¶
GetGeneratedFiles returns a list of files that would be generated
func (*Writer) WatchAndRegenerate ¶
WatchAndRegenerate watches for changes and regenerates documentation
func (*Writer) WriteFiles ¶
WriteFiles generates and writes all configured output formats
func (*Writer) WriteHTML ¶
func (w *Writer) WriteHTML(spec *OpenAPISpec) error
WriteHTML writes the specification as HTML with Swagger UI
func (*Writer) WriteJSON ¶
func (w *Writer) WriteJSON(spec *OpenAPISpec) error
WriteJSON writes the specification as JSON
func (*Writer) WriteToFile ¶
WriteToFile writes the specification to a specific file
func (*Writer) WriteYAML ¶
func (w *Writer) WriteYAML(spec *OpenAPISpec) error
WriteYAML writes the specification as YAML
type XML ¶
type XML struct {
Name string `json:"name,omitempty" yaml:"name,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
Attribute bool `json:"attribute,omitempty" yaml:"attribute,omitempty"`
Wrapped bool `json:"wrapped,omitempty" yaml:"wrapped,omitempty"`
}
XML metadata object