openapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package openapi is a generated GoMock package.

Package openapi is a generated GoMock package.

Index

Constants

View Source
const (
	JSON    = "json"
	YAML    = "yaml"
	ALL     = "all"
	DotYAML = ".yaml"
	DotJSON = ".json"
)

Variables

This section is empty.

Functions

func CreateNormalizedOpenAPISpecFromPath

func CreateNormalizedOpenAPISpecFromPath(path string) (*load.SpecInfo, error)

CreateNormalizedOpenAPISpecFromPath reads the OpenAPI spec from the given path and normalizes it by replacing versioned media types (e.g. application/vnd.atlas.2023-01-01) with standard media types (e.g. application/json)..

func ExtractVersionsWithEnv

func ExtractVersionsWithEnv(oas *openapi3.T, env string) ([]string, error)

ExtractVersionsWithEnv extracts API version Content Type strings from the given OpenAPI specification and environment. When env is not set, the function returns the API Versions from all the environments.

func NewArrayBytesFromOAS

func NewArrayBytesFromOAS(oas *Spec, path, format string) ([]byte, error)

func Save

func Save(path string, oas *openapi3.T, format string, fs afero.Fs) error

Save saves the OpenAPI document to a file in the specified format. This is important for public OpenAPI documents as it ensures to follow the order of the Spec object.

func SaveToFile

func SaveToFile[T any](path, format string, content T, fs afero.Fs) error

SaveToFile saves the content to a file in the specified format. If format is empty or set to 'all', it saves the content in both JSON and YAML formats.

func SerializeToJSON

func SerializeToJSON[T any](data T) ([]byte, error)

func SerializeToYAML

func SerializeToYAML(data []byte) ([]byte, error)

func ValidateFormatAndOutput

func ValidateFormatAndOutput(format, output string) error

ValidateFormatAndOutput validates the format and output file match.

Types

type ByName

type ByName []*openapi3.Tag

func (ByName) Len

func (a ByName) Len() int

func (ByName) Less

func (a ByName) Less(i, j int) bool

func (ByName) Swap

func (a ByName) Swap(i, j int)

type Differ

type Differ interface {
	Get(config *diff.Config, base, revision *openapi3.T) (*diff.Diff, error)
	GetWithOperationsSourcesMap(config *diff.Config, base, revision *load.SpecInfo) (*diff.Diff, *diff.OperationsSourcesMap, error)
}

DiffGetter defines an interface for getting diffs.

func NewResultGetter

func NewResultGetter() Differ

type Merger

type Merger interface {
	MergeOpenAPISpecs([]string) (*Spec, error)
}

type MockDiffGetter

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

MockDiffGetter is a mock of DiffGetter interface.

func NewMockDiffGetter

func NewMockDiffGetter(ctrl *gomock.Controller) *MockDiffGetter

NewMockDiffGetter creates a new mock instance.

func (*MockDiffGetter) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockDiffGetter) Get

func (m *MockDiffGetter) Get(arg0 *diff.Config, arg1, arg2 *openapi3.T) (*diff.Diff, error)

Get mocks base method.

func (*MockDiffGetter) GetWithOperationsSourcesMap

func (m *MockDiffGetter) GetWithOperationsSourcesMap(arg0 *diff.Config, arg1, arg2 *load.SpecInfo) (*diff.Diff, *diff.OperationsSourcesMap, error)

GetWithOperationsSourcesMap mocks base method.

type MockDiffGetterMockRecorder

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

MockDiffGetterMockRecorder is the mock recorder for MockDiffGetter.

func (*MockDiffGetterMockRecorder) Get

func (mr *MockDiffGetterMockRecorder) Get(arg0, arg1, arg2 any) *gomock.Call

Get indicates an expected call of Get.

func (*MockDiffGetterMockRecorder) GetWithOperationsSourcesMap

func (mr *MockDiffGetterMockRecorder) GetWithOperationsSourcesMap(arg0, arg1, arg2 any) *gomock.Call

GetWithOperationsSourcesMap indicates an expected call of GetWithOperationsSourcesMap.

type MockMerger

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

MockMerger is a mock of Merger interface.

func NewMockMerger

func NewMockMerger(ctrl *gomock.Controller) *MockMerger

NewMockMerger creates a new mock instance.

func (*MockMerger) EXPECT

func (m *MockMerger) EXPECT() *MockMergerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockMerger) MergeOpenAPISpecs

func (m *MockMerger) MergeOpenAPISpecs(arg0 []string) (*Spec, error)

MergeOpenAPISpecs mocks base method.

type MockMergerMockRecorder

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

MockMergerMockRecorder is the mock recorder for MockMerger.

func (*MockMergerMockRecorder) MergeOpenAPISpecs

func (mr *MockMergerMockRecorder) MergeOpenAPISpecs(arg0 any) *gomock.Call

MergeOpenAPISpecs indicates an expected call of MergeOpenAPISpecs.

type MockParser

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

MockParser is a mock of Parser interface.

func NewMockParser

func NewMockParser(ctrl *gomock.Controller) *MockParser

NewMockParser creates a new mock instance.

func (*MockParser) CreateOpenAPISpecFromPath

func (m *MockParser) CreateOpenAPISpecFromPath(arg0 string) (*load.SpecInfo, error)

CreateOpenAPISpecFromPath mocks base method.

func (*MockParser) EXPECT

func (m *MockParser) EXPECT() *MockParserMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

type MockParserMockRecorder

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

MockParserMockRecorder is the mock recorder for MockParser.

func (*MockParserMockRecorder) CreateOpenAPISpecFromPath

func (mr *MockParserMockRecorder) CreateOpenAPISpecFromPath(arg0 any) *gomock.Call

CreateOpenAPISpecFromPath indicates an expected call of CreateOpenAPISpecFromPath.

type OasDiff

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

func NewOasDiff

func NewOasDiff(base string, excludePrivatePaths bool) (*OasDiff, error)

func NewOasDiffWithSpecInfo

func NewOasDiffWithSpecInfo(base, external *load.SpecInfo, config *diff.Config) *OasDiff

func (*OasDiff) GetDiffWithConfig

func (o *OasDiff) GetDiffWithConfig(base, revision *load.SpecInfo, config *diff.Config) (*OasDiffResult, error)

GetDiffWithConfig returns the diff between two OpenAPI specs with a custom config.

func (*OasDiff) GetFlattenedDiff

func (o *OasDiff) GetFlattenedDiff(base, revision *load.SpecInfo) (*OasDiffResult, error)

GetFlattenedDiff returns the diff between two OpenAPI specs after flattening them.

func (*OasDiff) GetSimpleDiff

func (o *OasDiff) GetSimpleDiff(base, revision *load.SpecInfo) (*OasDiffResult, error)

GetSimpleDiff returns the diff between two OpenAPI specs.

func (*OasDiff) MergeOpenAPISpecs

func (o *OasDiff) MergeOpenAPISpecs(paths []string) (*Spec, error)

type OasDiffResult

type OasDiffResult struct {
	Report       *diff.Diff
	SourceMap    *diff.OperationsSourcesMap
	SpecInfoPair *load.SpecInfoPair
	Config       *diff.Config
}

type OpenAPI3

type OpenAPI3 struct {
	IsExternalRefsAllowed    bool
	ExcludePrivatePaths      bool
	CircularReferenceCounter int
	Loader                   *openapi3.Loader
}

func NewOpenAPI3

func NewOpenAPI3() *OpenAPI3

func (*OpenAPI3) CreateOpenAPISpecFromPath

func (o *OpenAPI3) CreateOpenAPISpecFromPath(path string) (*load.SpecInfo, error)

func (*OpenAPI3) WithExcludedPrivatePaths

func (o *OpenAPI3) WithExcludedPrivatePaths() *OpenAPI3

type Parser

type Parser interface {
	CreateOpenAPISpecFromPath(string) (*load.SpecInfo, error)
}

type ResultGetter

type ResultGetter struct{}

func (ResultGetter) Get

func (ResultGetter) Get(config *diff.Config, base, revision *openapi3.T) (*diff.Diff, error)

func (ResultGetter) GetWithOperationsSourcesMap

func (ResultGetter) GetWithOperationsSourcesMap(
	config *diff.Config, base, revision *load.SpecInfo) (*diff.Diff, *diff.OperationsSourcesMap, error)

type Spec

type Spec struct {
	Extensions   map[string]any                `json:"-" yaml:"-"`
	OpenAPI      string                        `json:"openapi" yaml:"openapi"`
	Security     openapi3.SecurityRequirements `json:"security,omitempty" yaml:"security,omitempty"`
	Servers      openapi3.Servers              `json:"servers,omitempty" yaml:"servers,omitempty"`
	Tags         openapi3.Tags                 `json:"tags,omitempty" yaml:"tags,omitempty"`
	Info         *openapi3.Info                `json:"info" yaml:"info"`
	Paths        *openapi3.Paths               `json:"paths" yaml:"paths"`
	Components   *openapi3.Components          `json:"components,omitempty" yaml:"components,omitempty"`
	ExternalDocs *openapi3.ExternalDocs        `json:"externalDocs,omitempty" yaml:"externalDocs,omitempty"`
}

Spec is a struct is a 1-to-1 copy of the Spec struct in the openapi3 package. We need this to override the order of the fields in the struct.

func (*Spec) MarshalJSON

func (doc *Spec) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of Spec. We need a custom definition of MarshalJSON to include support for Extensions map[string]any `json:"-" yaml:"-"` where we only what to serialize the value of the field.

func (*Spec) MarshalYAML

func (doc *Spec) MarshalYAML() (any, error)

MarshalYAML returns the YAML encoding of Spec.

Directories

Path Synopsis
Package filter is a generated GoMock package.
Package filter is a generated GoMock package.

Jump to

Keyboard shortcuts

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