openapi

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package openapi provides OpenAPI 3.0 specification generation from CodeAI AST.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSON

func ToJSON(spec *OpenAPI) (string, error)

ToJSON converts the spec to a JSON string.

func ToYAML

func ToYAML(spec *OpenAPI) (string, error)

ToYAML converts the spec to a YAML string.

Types

type Annotation

type Annotation struct {
	Type   string   // The annotation type (e.g., "Summary", "Description", "Param")
	Name   string   // The name (for @Param, @Success, @Failure)
	Values []string // The values/arguments
	Raw    string   // The raw annotation text
}

Annotation represents a parsed annotation from a comment.

type AnnotationParser

type AnnotationParser struct {
	// contains filtered or unexported fields
}

AnnotationParser parses OpenAPI annotations from comments.

func NewAnnotationParser

func NewAnnotationParser() *AnnotationParser

NewAnnotationParser creates a new annotation parser.

func (*AnnotationParser) ParseComment

func (p *AnnotationParser) ParseComment(comment string) []Annotation

ParseComment parses annotations from a single comment string.

func (*AnnotationParser) ParseComments

func (p *AnnotationParser) ParseComments(comments []string) []Annotation

ParseComments parses annotations from a slice of comment lines.

type Callback

type Callback map[string]PathItem

Callback represents a callback object.

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.

type Config

type Config struct {
	// Metadata
	Title          string `json:"title" yaml:"title"`
	Description    string `json:"description" yaml:"description"`
	Version        string `json:"version" yaml:"version"`
	TermsOfService string `json:"terms_of_service" yaml:"terms_of_service"`

	// Contact info
	ContactName  string `json:"contact_name" yaml:"contact_name"`
	ContactURL   string `json:"contact_url" yaml:"contact_url"`
	ContactEmail string `json:"contact_email" yaml:"contact_email"`

	// License info
	LicenseName string `json:"license_name" yaml:"license_name"`
	LicenseURL  string `json:"license_url" yaml:"license_url"`

	// Servers
	Servers []ServerConfig `json:"servers" yaml:"servers"`

	// Security
	DefaultSecurity []string `json:"default_security" yaml:"default_security"`

	// Output
	OutputFormat string `json:"output_format" yaml:"output_format"` // json or yaml
}

Config holds the configuration for OpenAPI generation.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a default configuration.

func LoadConfig

func LoadConfig(path string) (*Config, error)

LoadConfig loads configuration from a file. Supports JSON and YAML formats based on file extension.

func (*Config) ToInfo

func (c *Config) ToInfo() Info

ToInfo converts the config to an OpenAPI Info object.

func (*Config) ToServers

func (c *Config) ToServers() []Server

ToServers converts the config to OpenAPI Server objects.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks if the configuration is valid.

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 provides contact information for the API.

type Discriminator

type Discriminator struct {
	PropertyName string            `json:"propertyName" yaml:"propertyName"`
	Mapping      map[string]string `json:"mapping,omitempty" yaml:"mapping,omitempty"`
}

Discriminator can be used to aid in serialization, deserialization, and validation.

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 provides encoding information for a property.

type Example

type Example 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"`
	Value         any    `json:"value,omitempty" yaml:"value,omitempty"`
	ExternalValue string `json:"externalValue,omitempty" yaml:"externalValue,omitempty"`
}

Example represents an example value.

type ExternalDocs

type ExternalDocs struct {
	Description string `json:"description,omitempty" yaml:"description,omitempty"`
	URL         string `json:"url" yaml:"url"`
}

ExternalDocs provides a link to external documentation.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates OpenAPI specifications from CodeAI AST.

func NewGenerator

func NewGenerator(config *Config) *Generator

NewGenerator creates a new OpenAPI generator with the given configuration.

func (*Generator) AddAPIKeyAuth

func (g *Generator) AddAPIKeyAuth(name, headerName string)

AddAPIKeyAuth adds an API key authentication scheme.

func (*Generator) AddBearerAuth

func (g *Generator) AddBearerAuth(name string)

AddBearerAuth adds a bearer token authentication scheme.

func (*Generator) AddRoute

func (g *Generator) AddRoute(method, path, summary, description string) *Operation

AddRoute adds a route definition to the generator's mapper.

func (*Generator) AddSchema

func (g *Generator) AddSchema(name string, schema *Schema)

AddSchema adds a schema definition to the generator.

func (*Generator) AddSchemaFromType

func (g *Generator) AddSchemaFromType(name string, t interface{})

AddSchemaFromType adds a schema generated from a Go type.

func (*Generator) AddSecurityScheme

func (g *Generator) AddSecurityScheme(name string, scheme *SecurityScheme)

AddSecurityScheme adds a security scheme definition.

func (*Generator) AddTag

func (g *Generator) AddTag(name, description string)

AddTag adds a tag definition.

func (*Generator) GenerateFromAST

func (g *Generator) GenerateFromAST(program *ast.Program) (*OpenAPI, error)

GenerateFromAST generates an OpenAPI specification from a parsed AST.

func (*Generator) GenerateFromFile

func (g *Generator) GenerateFromFile(path string) (*OpenAPI, error)

GenerateFromFile generates an OpenAPI specification from a CodeAI source file.

func (*Generator) GenerateFromSource

func (g *Generator) GenerateFromSource(source string) (*OpenAPI, error)

GenerateFromSource generates an OpenAPI specification from CodeAI source code.

func (*Generator) GenerateFromTypes

func (g *Generator) GenerateFromTypes(types ...interface{}) (*OpenAPI, error)

GenerateFromTypes generates an OpenAPI specification from Go types. This is useful for generating specs from existing Go struct definitions.

func (*Generator) GetSpec

func (g *Generator) GetSpec() *OpenAPI

GetSpec returns the current OpenAPI specification.

func (*Generator) WriteJSON

func (g *Generator) WriteJSON(w io.Writer, spec *OpenAPI) error

WriteJSON writes the spec to a writer in JSON format.

func (*Generator) WriteToFile

func (g *Generator) WriteToFile(path string, spec *OpenAPI) error

WriteToFile writes the spec to a file in the configured format.

func (*Generator) WriteYAML

func (g *Generator) WriteYAML(w io.Writer, spec *OpenAPI) error

WriteYAML writes the spec to a writer in YAML format.

type Header struct {
	Ref             string  `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	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"`
	Schema          *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         any     `json:"example,omitempty" yaml:"example,omitempty"`
}

Header represents a header parameter.

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 contains metadata about the API.

type License

type License struct {
	Name string `json:"name" yaml:"name"`
	URL  string `json:"url,omitempty" yaml:"url,omitempty"`
}

License provides license information for the API.

type Link struct {
	Ref          string         `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	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 Mapper

type Mapper struct {
	// Spec is the OpenAPI specification being built
	Spec *OpenAPI
	// SchemaGen generates schemas from types
	SchemaGen *SchemaGenerator
}

Mapper converts CodeAI AST to OpenAPI structures.

func NewMapper

func NewMapper() *Mapper

NewMapper creates a new AST to OpenAPI mapper.

func (*Mapper) AddRoute

func (m *Mapper) AddRoute(method, path string, op *Operation)

AddRoute adds a route to the OpenAPI spec.

func (*Mapper) AddSchema

func (m *Mapper) AddSchema(name string, schema *Schema)

AddSchema adds a schema to the components.

func (*Mapper) AddSecurityScheme

func (m *Mapper) AddSecurityScheme(name string, scheme *SecurityScheme)

AddSecurityScheme adds a security scheme to the components.

func (*Mapper) AddTag

func (m *Mapper) AddTag(tag Tag)

AddTag adds a tag to the spec.

func (*Mapper) GetSpec

func (m *Mapper) GetSpec() *OpenAPI

GetSpec returns the built OpenAPI specification.

func (*Mapper) MapProgram

func (m *Mapper) MapProgram(program *ast.Program) error

MapProgram maps a CodeAI Program AST to OpenAPI paths and schemas.

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 a media type.

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 defines the configuration details for a specific 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 defines the configuration for OAuth flows.

type OpenAPI

type OpenAPI 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"`
}

OpenAPI represents a complete OpenAPI 3.0 specification.

func Merge

func Merge(base, addition *OpenAPI) *OpenAPI

Merge merges another OpenAPI spec into this one.

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 *ExternalDocs         `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"`

	// CodeAI extensions
	XCodeAIHandler    string   `json:"x-codeai-handler,omitempty" yaml:"x-codeai-handler,omitempty"`
	XCodeAIMiddleware []string `json:"x-codeai-middleware,omitempty" yaml:"x-codeai-middleware,omitempty"`
	XCodeAISource     string   `json:"x-codeai-source,omitempty" yaml:"x-codeai-source,omitempty"`
}

Operation describes a single API operation on a path.

type OperationMeta

type OperationMeta struct {
	Summary     string
	Description string
	Tags        []string
	OperationID string
	Deprecated  bool
	Accept      []string
	Produce     []string
	Security    []string
	Router      *RouterMeta
	Params      []ParamMeta
	Responses   []ResponseMeta
}

OperationMeta holds parsed metadata for an operation.

func ExtractOperationMeta

func ExtractOperationMeta(annotations []Annotation) *OperationMeta

ExtractOperationMeta extracts operation metadata from annotations.

func (*OperationMeta) ToOperation

func (m *OperationMeta) ToOperation() *Operation

ToOperation converts OperationMeta to an OpenAPI Operation.

type ParamMeta

type ParamMeta struct {
	Name        string
	In          string // path, query, header, body, formData
	Type        string
	Required    bool
	Description string
}

ParamMeta holds parameter metadata.

type Parameter

type Parameter struct {
	Ref             string  `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Name            string  `json:"name,omitempty" yaml:"name,omitempty"`
	In              string  `json:"in,omitempty" yaml:"in,omitempty"` // query, header, path, cookie
	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"`
	Schema          *Schema `json:"schema,omitempty" yaml:"schema,omitempty"`
	Example         any     `json:"example,omitempty" yaml:"example,omitempty"`
}

Parameter describes a single operation parameter.

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"`
	Parameters  []Parameter `json:"parameters,omitempty" yaml:"parameters,omitempty"`
}

PathItem describes the operations available on a single path.

type RequestBody

type RequestBody struct {
	Ref         string               `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Description string               `json:"description,omitempty" yaml:"description,omitempty"`
	Content     map[string]MediaType `json:"content,omitempty" yaml:"content,omitempty"`
	Required    bool                 `json:"required,omitempty" yaml:"required,omitempty"`
}

RequestBody describes a request body.

type Response

type Response struct {
	Ref         string               `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	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 ResponseMeta

type ResponseMeta struct {
	StatusCode  int
	Type        string // success or failure
	Schema      string
	Description string
}

ResponseMeta holds response metadata.

type RouterMeta

type RouterMeta struct {
	Path   string
	Method string
}

RouterMeta holds router metadata.

type Schema

type Schema struct {
	Ref          string        `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Type         string        `json:"type,omitempty" yaml:"type,omitempty"`
	Format       string        `json:"format,omitempty" yaml:"format,omitempty"`
	Title        string        `json:"title,omitempty" yaml:"title,omitempty"`
	Description  string        `json:"description,omitempty" yaml:"description,omitempty"`
	Default      any           `json:"default,omitempty" yaml:"default,omitempty"`
	Nullable     bool          `json:"nullable,omitempty" yaml:"nullable,omitempty"`
	ReadOnly     bool          `json:"readOnly,omitempty" yaml:"readOnly,omitempty"`
	WriteOnly    bool          `json:"writeOnly,omitempty" yaml:"writeOnly,omitempty"`
	Deprecated   bool          `json:"deprecated,omitempty" yaml:"deprecated,omitempty"`
	Example      any           `json:"example,omitempty" yaml:"example,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`

	// Validation keywords
	MultipleOf       *float64 `json:"multipleOf,omitempty" yaml:"multipleOf,omitempty"`
	Maximum          *float64 `json:"maximum,omitempty" yaml:"maximum,omitempty"`
	ExclusiveMaximum *float64 `json:"exclusiveMaximum,omitempty" yaml:"exclusiveMaximum,omitempty"`
	Minimum          *float64 `json:"minimum,omitempty" yaml:"minimum,omitempty"`
	ExclusiveMinimum *float64 `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"`

	// Object keywords
	Properties           map[string]*Schema `json:"properties,omitempty" yaml:"properties,omitempty"`
	AdditionalProperties *Schema            `json:"additionalProperties,omitempty" yaml:"additionalProperties,omitempty"`
	Required             []string           `json:"required,omitempty" yaml:"required,omitempty"`

	// Array keywords
	Items *Schema `json:"items,omitempty" yaml:"items,omitempty"`

	// Composition keywords
	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"`
	Discriminator *Discriminator `json:"discriminator,omitempty" yaml:"discriminator,omitempty"`

	// Enumeration
	Enum []any `json:"enum,omitempty" yaml:"enum,omitempty"`

	// CodeAI MongoDB extensions
	XMongoCollection string `json:"x-mongo-collection,omitempty" yaml:"x-mongo-collection,omitempty"`
	XDatabaseType    string `json:"x-database-type,omitempty" yaml:"x-database-type,omitempty"`
}

Schema defines the structure of input and output data.

func GenerateRef

func GenerateRef(name string) *Schema

GenerateRef generates a reference schema to a named type.

func SchemaFromType

func SchemaFromType(typeName string) *Schema

SchemaFromType creates a schema from a type name.

type SchemaGenerator

type SchemaGenerator struct {
	// Definitions stores schema definitions for complex types
	Definitions map[string]*Schema
	// contains filtered or unexported fields
}

SchemaGenerator generates JSON Schemas from Go types.

func NewSchemaGenerator

func NewSchemaGenerator() *SchemaGenerator

NewSchemaGenerator creates a new schema generator.

func (*SchemaGenerator) GenerateSchema

func (g *SchemaGenerator) GenerateSchema(t reflect.Type) *Schema

GenerateSchema generates an OpenAPI schema from a Go type.

func (*SchemaGenerator) GenerateSchemaFromValue

func (g *SchemaGenerator) GenerateSchemaFromValue(v interface{}) *Schema

GenerateSchemaFromValue generates an OpenAPI schema from a Go value.

type SecurityRequirement

type SecurityRequirement map[string][]string

SecurityRequirement lists the required security schemes to execute an operation.

type SecurityScheme

type SecurityScheme struct {
	Ref              string      `json:"$ref,omitempty" yaml:"$ref,omitempty"`
	Type             string      `json:"type,omitempty" yaml:"type,omitempty"` // apiKey, http, oauth2, openIdConnect
	Description      string      `json:"description,omitempty" yaml:"description,omitempty"`
	Name             string      `json:"name,omitempty" yaml:"name,omitempty"`                         // for apiKey
	In               string      `json:"in,omitempty" yaml:"in,omitempty"`                             // for apiKey: query, header, cookie
	Scheme           string      `json:"scheme,omitempty" yaml:"scheme,omitempty"`                     // for http
	BearerFormat     string      `json:"bearerFormat,omitempty" yaml:"bearerFormat,omitempty"`         // for http bearer
	Flows            *OAuthFlows `json:"flows,omitempty" yaml:"flows,omitempty"`                       // for oauth2
	OpenIDConnectURL string      `json:"openIdConnectUrl,omitempty" yaml:"openIdConnectUrl,omitempty"` // for openIdConnect
}

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 an API server.

type ServerConfig

type ServerConfig struct {
	URL         string `json:"url" yaml:"url"`
	Description string `json:"description" yaml:"description"`
}

ServerConfig represents a server configuration.

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 variable for server URL template substitution.

type Tag

type Tag struct {
	Name         string        `json:"name" yaml:"name"`
	Description  string        `json:"description,omitempty" yaml:"description,omitempty"`
	ExternalDocs *ExternalDocs `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}

Tag adds metadata to a single tag.

type ValidationError

type ValidationError struct {
	Path    string
	Message string
}

ValidationError represents a validation error.

func (ValidationError) Error

func (e ValidationError) Error() string

type ValidationResult

type ValidationResult struct {
	Valid    bool
	Errors   []ValidationError
	Warnings []ValidationError
}

ValidationResult contains the result of validating an OpenAPI spec.

func ValidateSpec

func ValidateSpec(spec *OpenAPI) *ValidationResult

ValidateSpec is a convenience function to validate an OpenAPI spec.

func ValidateSpecStrict

func ValidateSpecStrict(spec *OpenAPI) *ValidationResult

ValidateSpecStrict is a convenience function to validate with strict mode.

type Validator

type Validator struct {
	// StrictMode enables strict validation
	StrictMode bool
}

Validator validates OpenAPI specifications.

func NewValidator

func NewValidator() *Validator

NewValidator creates a new validator.

func (*Validator) Validate

func (v *Validator) Validate(spec *OpenAPI) *ValidationResult

Validate validates an OpenAPI specification.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL