openapi

package
v0.0.0-...-aa18534 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DownloadSpec

func DownloadSpec(url, destPath string) error

DownloadSpec downloads an OpenAPI specification from a URL to a file

func IsURL

func IsURL(s string) bool

IsURL checks if a string is a URL

func LoadSpec

func LoadSpec(specPath string) (*v3.Document, error)

LoadSpec loads an OpenAPI specification from a file or URL

Types

type DefaultSpecParser

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

DefaultSpecParser implements SpecParser

func NewSpecParser

func NewSpecParser() *DefaultSpecParser

NewSpecParser creates a new DefaultSpecParser

func (*DefaultSpecParser) GetEndpoint

func (p *DefaultSpecParser) GetEndpoint(doc *v3.Document, path, method string) (*Endpoint, error)

GetEndpoint returns a specific endpoint from an OpenAPI document

func (*DefaultSpecParser) GetEndpoints

func (p *DefaultSpecParser) GetEndpoints(doc *v3.Document) ([]Endpoint, error)

GetEndpoints returns a list of endpoints from an OpenAPI document

func (*DefaultSpecParser) ParseSpec

func (p *DefaultSpecParser) ParseSpec(specPath string) (*v3.Document, error)

ParseSpec parses an OpenAPI specification from a file or URL

type DefaultVersionDetector

type DefaultVersionDetector struct{}

DefaultVersionDetector implements VersionDetector

func NewVersionDetector

func NewVersionDetector() *DefaultVersionDetector

NewVersionDetector creates a new DefaultVersionDetector

func (*DefaultVersionDetector) DetectVersion

func (d *DefaultVersionDetector) DetectVersion(specPath string) (OpenAPIVersion, error)

DetectVersion detects the OpenAPI version from a file or URL

func (*DefaultVersionDetector) DetectVersionFromBytes

func (d *DefaultVersionDetector) DetectVersionFromBytes(data []byte) (OpenAPIVersion, error)

DetectVersionFromBytes detects the OpenAPI version from a byte slice

type Endpoint

type Endpoint struct {
	// Path is the URL path of the endpoint
	Path string

	// Method is the HTTP method (GET, POST, etc.)
	Method string

	// OperationID is the unique identifier for the operation
	OperationID string

	// Summary is a brief description of the endpoint
	Summary string

	// Description is a detailed description of the endpoint
	Description string

	// Parameters is a list of parameters for the endpoint
	Parameters []Parameter

	// RequestBody is the request body schema
	RequestBody *RequestBody

	// Responses is a map of response codes to response schemas
	Responses map[string]Response

	// Tags is a list of tags for the endpoint
	Tags []string

	// Security is a list of security requirements for the endpoint
	Security []map[string][]string

	// Deprecated indicates if the endpoint is deprecated
	Deprecated bool
}

Endpoint represents an API endpoint

type HTTPMethod

type HTTPMethod string

HTTPMethod represents an HTTP method

const (
	MethodGet     HTTPMethod = http.MethodGet
	MethodPost    HTTPMethod = http.MethodPost
	MethodPut     HTTPMethod = http.MethodPut
	MethodDelete  HTTPMethod = http.MethodDelete
	MethodPatch   HTTPMethod = http.MethodPatch
	MethodHead    HTTPMethod = http.MethodHead
	MethodOptions HTTPMethod = http.MethodOptions
	MethodTrace   HTTPMethod = http.MethodTrace
)

HTTP methods

type LibOpenAPISpecParser

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

LibOpenAPISpecParser implements SpecParser using libopenapi

func NewLibOpenAPISpecParser

func NewLibOpenAPISpecParser() *LibOpenAPISpecParser

NewLibOpenAPISpecParser creates a new LibOpenAPISpecParser

func (*LibOpenAPISpecParser) GetEndpoint

func (p *LibOpenAPISpecParser) GetEndpoint(doc *v3.Document, path, method string) (*Endpoint, error)

GetEndpoint returns a specific endpoint from an OpenAPI document

func (*LibOpenAPISpecParser) GetEndpoints

func (p *LibOpenAPISpecParser) GetEndpoints(doc *v3.Document) ([]Endpoint, error)

GetEndpoints returns a list of endpoints from an OpenAPI document

func (*LibOpenAPISpecParser) ParseSpec

func (p *LibOpenAPISpecParser) ParseSpec(specPath string) (*v3.Document, error)

ParseSpec parses an OpenAPI specification from a file or URL

type MediaType

type MediaType struct {
	// Schema is the schema of the media type
	Schema *Schema

	// Example is an example value for the media type
	Example interface{}
}

MediaType represents a media type

type OpenAPIVersion

type OpenAPIVersion string

OpenAPIVersion represents an OpenAPI specification version

const (
	// OpenAPIV30 represents OpenAPI 3.0.x
	OpenAPIV30 OpenAPIVersion = "3.0"

	// OpenAPIV31 represents OpenAPI 3.1.x
	OpenAPIV31 OpenAPIVersion = "3.1"

	// OpenAPIUnknown represents an unknown OpenAPI version
	OpenAPIUnknown OpenAPIVersion = "unknown"
)

type Parameter

type Parameter struct {
	// Name is the name of the parameter
	Name string

	// In is the location of the parameter (path, query, header, cookie)
	In string

	// Description is a description of the parameter
	Description string

	// Required indicates if the parameter is required
	Required bool

	// Schema is the schema of the parameter
	Schema *Schema

	// Example is an example value for the parameter
	Example interface{}

	// Deprecated indicates if the parameter is deprecated
	Deprecated bool
}

Parameter represents an API parameter

type ParameterLocation

type ParameterLocation string

ParameterLocation represents the location of a parameter

const (
	ParameterInPath   ParameterLocation = "path"
	ParameterInQuery  ParameterLocation = "query"
	ParameterInHeader ParameterLocation = "header"
	ParameterInCookie ParameterLocation = "cookie"
)

Parameter locations

type RequestBody

type RequestBody struct {
	// Description is a description of the request body
	Description string

	// Required indicates if the request body is required
	Required bool

	// Content is a map of media types to schemas
	Content map[string]*MediaType
}

RequestBody represents a request body

type Response

type Response struct {
	// Description is a description of the response
	Description string

	// Content is a map of media types to schemas
	Content map[string]*MediaType

	// Headers is a map of header names to schemas
	Headers map[string]*Schema
}

Response represents an API response

type Schema

type Schema struct {
	// Type is the type of the schema (string, number, integer, boolean, array, object)
	Type string

	// Format is the format of the schema (date-time, email, etc.)
	Format string

	// Description is a description of the schema
	Description string

	// Default is the default value for the schema
	Default interface{}

	// Enum is a list of allowed values for the schema
	Enum []interface{}

	// Minimum is the minimum value for the schema
	Minimum *float64

	// Maximum is the maximum value for the schema
	Maximum *float64

	// MinLength is the minimum length for the schema
	MinLength *uint64

	// MaxLength is the maximum length for the schema
	MaxLength *uint64

	// Pattern is a regex pattern for the schema
	Pattern string

	// Properties is a map of property names to schemas (for object types)
	Properties map[string]*Schema

	// Items is the schema for array items (for array types)
	Items *Schema

	// Required is a list of required properties (for object types)
	Required []string

	// Example is an example value for the schema
	Example interface{}
}

Schema represents a JSON Schema

type SchemaType

type SchemaType string

SchemaType represents a schema type

const (
	SchemaTypeString  SchemaType = "string"
	SchemaTypeNumber  SchemaType = "number"
	SchemaTypeInteger SchemaType = "integer"
	SchemaTypeBoolean SchemaType = "boolean"
	SchemaTypeArray   SchemaType = "array"
	SchemaTypeObject  SchemaType = "object"
)

Schema types

type SecurityRequirement

type SecurityRequirement struct {
	// Name is the name of the security scheme
	Name string

	// Scopes is a list of scopes required for the security scheme
	Scopes []string
}

SecurityRequirement represents a security requirement

type SpecParser

type SpecParser interface {
	// ParseSpec parses an OpenAPI specification from a file or URL
	ParseSpec(specPath string) (*v3.Document, error)

	// GetEndpoints returns a list of endpoints from an OpenAPI document
	GetEndpoints(doc *v3.Document) ([]Endpoint, error)

	// GetEndpoint returns a specific endpoint from an OpenAPI document
	GetEndpoint(doc *v3.Document, path, method string) (*Endpoint, error)
}

SpecParser is the interface for parsing OpenAPI specifications

type VersionDetector

type VersionDetector interface {
	// DetectVersion detects the OpenAPI version from a file or URL
	DetectVersion(specPath string) (OpenAPIVersion, error)

	// DetectVersionFromBytes detects the OpenAPI version from a byte slice
	DetectVersionFromBytes(data []byte) (OpenAPIVersion, error)
}

VersionDetector is the interface for detecting OpenAPI versions

Jump to

Keyboard shortcuts

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