convert

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package convert provides OpenAPI specification version conversion.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToMultipleVersions

func ToMultipleVersions(spec *openapi.Spec, targets ...TargetVersion) (map[string]*openapi.Spec, error)

ToMultipleVersions converts an OpenAPI spec to multiple versions. Returns a map of version string to converted spec.

func ToVersion

func ToVersion(spec *openapi.Spec, target TargetVersion) (*openapi.Spec, error)

ToVersion converts an OpenAPI spec to the specified version. This creates a deep copy and modifies version-specific elements.

func VersionedFilename

func VersionedFilename(filename string, version TargetVersion) string

VersionedFilename generates a version-specific filename. Example: VersionedFilename("openapi.yaml", Version310) -> "openapi-3.1.0.yaml"

Types

type MultiVersionOutput

type MultiVersionOutput struct {
	Specs map[TargetVersion]*openapi.Spec
}

MultiVersionOutput contains specs converted to multiple versions.

func AllVersions

func AllVersions(spec *openapi.Spec) (*MultiVersionOutput, error)

AllVersions returns a MultiVersionOutput with all supported versions.

func NewMultiVersionOutput

func NewMultiVersionOutput(spec *openapi.Spec, targets ...TargetVersion) (*MultiVersionOutput, error)

NewMultiVersionOutput creates a MultiVersionOutput from a source spec.

func StandardVersions

func StandardVersions(spec *openapi.Spec) (*MultiVersionOutput, error)

StandardVersions returns a MultiVersionOutput with commonly used versions (3.0.3, 3.1.0).

func (*MultiVersionOutput) Get

func (m *MultiVersionOutput) Get(version TargetVersion) *openapi.Spec

Get returns the spec for a specific version.

func (*MultiVersionOutput) ToJSON

func (m *MultiVersionOutput) ToJSON() (map[TargetVersion][]byte, error)

ToJSON returns all specs as JSON bytes keyed by version.

func (*MultiVersionOutput) ToYAML

func (m *MultiVersionOutput) ToYAML() (map[TargetVersion][]byte, error)

ToYAML returns all specs as YAML bytes keyed by version.

func (*MultiVersionOutput) Versions

func (m *MultiVersionOutput) Versions() []TargetVersion

Versions returns a sorted list of versions in this output.

func (*MultiVersionOutput) WriteFiles

func (m *MultiVersionOutput) WriteFiles(basePath string, format openapi.Format) error

WriteFiles writes all specs to files with version-specific names. The basePath should include the base filename without extension. Example: basePath="./output/openapi" creates:

  • ./output/openapi-3.0.3.yaml
  • ./output/openapi-3.1.0.yaml
  • ./output/openapi-3.2.0.yaml

func (*MultiVersionOutput) WriteFilesToDir

func (m *MultiVersionOutput) WriteFilesToDir(dir, basename string, format openapi.Format) error

WriteFilesToDir writes all specs to a directory with version-specific names. Example: dir="./output", basename="openapi" creates:

  • ./output/openapi-3.0.3.yaml
  • ./output/openapi-3.1.0.yaml

type TargetVersion

type TargetVersion string

TargetVersion represents the target OpenAPI version for conversion.

const (
	// OpenAPI 3.0.x versions
	Version300 TargetVersion = "3.0.0"
	Version301 TargetVersion = "3.0.1"
	Version302 TargetVersion = "3.0.2"
	Version303 TargetVersion = "3.0.3"

	// OpenAPI 3.1.x versions
	Version310 TargetVersion = "3.1.0"
	Version311 TargetVersion = "3.1.1"

	// OpenAPI 3.2.x versions
	Version320 TargetVersion = "3.2.0"
)

func (TargetVersion) Is30x

func (v TargetVersion) Is30x() bool

Is30x returns true if this is an OpenAPI 3.0.x version.

func (TargetVersion) Is31x

func (v TargetVersion) Is31x() bool

Is31x returns true if this is an OpenAPI 3.1.x version.

func (TargetVersion) Is32x

func (v TargetVersion) Is32x() bool

Is32x returns true if this is an OpenAPI 3.2.x version.

Jump to

Keyboard shortcuts

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