openapi

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalSpec added in v1.2.0

func MarshalSpec(spec *OpenAPISpec, format Format) ([]byte, error)

MarshalSpec serializes the generated OpenAPI spec in the requested format. The spec's JSON tags are the source of truth for both formats: YAML is produced by round-tripping the spec through JSON so the emitted document has exactly the shape of the JSON output.

Types

type Format added in v1.2.0

type Format string

Format identifies a serialization format for generated specs.

const (
	// FormatJSON serializes the spec as indented JSON. It is the default format.
	FormatJSON Format = "json"
	// FormatYAML serializes the spec as YAML.
	FormatYAML Format = "yaml"
)

type OpenAPIConfig

type OpenAPIConfig struct {
	Title           string
	Description     string
	Version         string
	Servers         []OpenAPIServer
	TagMappings     map[string]string // Maps path prefixes to custom tags
	UsePathGroups   bool              // Whether to group APIs by path segments
	VersionPrefixes map[string]bool   // Custom version prefixes to detect
}

OpenAPIConfig holds configuration for the generator

type OpenAPIGenerator

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

OpenAPIGenerator generates OpenAPI specs from API transactions

func NewOpenAPIGenerator

func NewOpenAPIGenerator(config OpenAPIConfig) *OpenAPIGenerator

NewOpenAPIGenerator creates a new OpenAPI generator

func (*OpenAPIGenerator) AddTransaction

func (g *OpenAPIGenerator) AddTransaction(tx proxy.APITransaction)

AddTransaction adds an API transaction to be analyzed

func (*OpenAPIGenerator) GenerateSpec

func (g *OpenAPIGenerator) GenerateSpec() (*OpenAPISpec, error)

GenerateSpec generates an OpenAPI spec from the collected transactions

func (*OpenAPIGenerator) LoadTransactionsFromDirectory

func (g *OpenAPIGenerator) LoadTransactionsFromDirectory(dirPath string) error

LoadTransactionsFromDirectory loads API transactions from all JSON files in a directory

func (*OpenAPIGenerator) LoadTransactionsFromFile

func (g *OpenAPIGenerator) LoadTransactionsFromFile(filename string) error

LoadTransactionsFromFile loads API transactions from a file

type OpenAPIServer

type OpenAPIServer struct {
	URL         string
	Description string
}

OpenAPIServer represents an API server in the OpenAPI spec

type OpenAPISpec

type OpenAPISpec = openapi3.T

OpenAPISpec is an alias for openapi3.T to make it clearer

Jump to

Keyboard shortcuts

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