openapi

package
v0.38.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMultiDocument = errors.New("multi-document YAML not supported for OpenAPI specs")
	ErrNoDocument    = errors.New("YAML has no documents")
	ErrNotMapping    = errors.New("document root is not a YAML mapping")
)

Parse errors.

View Source
var ReservedKeys = []string{"operation", "operations", "schemas", "info", "servers", "security"}

ReservedKeys are the vars namespaces ExtractOperation produces. On collision with template- or config-declared vars these win (they are reserved for OpenAPI input); an explicit --meta flag still overrides them, as --meta is applied later at the highest precedence by the engine.

Functions

func ExtractOperation added in v0.37.0

func ExtractOperation(spec []byte, selector string) (map[string]any, error)

ExtractOperation parses an OpenAPI 3.x spec and extracts a single operation (selected by operationId or "METHOD /path") into a map[string]any suitable for the template `vars` namespace. See claudedocs/openapi-input-plan.md.

func ExtractOperations added in v0.38.0

func ExtractOperations(spec []byte, tag string) (map[string]any, error)

ExtractOperations parses an OpenAPI 3.x spec and extracts many operations into a map[string]any for the template `vars` namespace. An empty tag selects every operation; otherwise only operations carrying that OpenAPI tag. Operations are ordered by path then method for deterministic output, and each entry carries its own effective security (op-level, else spec-level) — there is no top-level `security` key in multi-op mode, since it differs per operation. vars.schemas is the deduped union of components referenced by all selected operations. See #327.

Types

type ConflictPolicy

type ConflictPolicy string

ConflictPolicy defines how to handle merge conflicts.

const (
	// ConflictError returns an error when a key exists with different content.
	ConflictError ConflictPolicy = "error"
	// ConflictSkip silently skips conflicting keys.
	ConflictSkip ConflictPolicy = "skip"
)

type Editor

type Editor struct{}

Editor provides structural merge of OpenAPI YAML fragments.

func NewEditor

func NewEditor() *Editor

NewEditor creates a new OpenAPI editor.

func (*Editor) Merge

func (e *Editor) Merge(spec, fragment []byte, opts MergeOptions) ([]byte, MergeResult, error)

Merge merges an OpenAPI YAML fragment into a target spec. The fragment should contain top-level `paths` and/or `components` sections. Returns the merged YAML, a result summary, and any error.

type MergeOptions

type MergeOptions struct {
	ValidateResult bool           // run kin-openapi validation after merge
	ConflictPolicy ConflictPolicy // skip | error (default: error)
}

MergeOptions controls merge behavior.

type MergeResult

type MergeResult struct {
	Changed        bool
	AddedPaths     []string
	AddedSchemas   []string
	SkippedPaths   []string
	SkippedSchemas []string
	Conflicts      []string
}

MergeResult describes what the merge operation did.

type Spec

type Spec struct {
	File   *ast.File
	Root   *ast.MappingNode
	Indent int // detected indentation (2 or 4 spaces)
}

Spec wraps a parsed OpenAPI YAML AST with indexed access to top-level sections.

func ParseSpec

func ParseSpec(data []byte) (*Spec, error)

ParseSpec parses an OpenAPI YAML spec into an indexed Spec structure.

func (*Spec) HasComponents

func (s *Spec) HasComponents() bool

HasComponents returns true if the spec has a `components` section.

func (*Spec) HasPaths

func (s *Spec) HasPaths() bool

HasPaths returns true if the spec has a `paths` section (even if empty).

func (*Spec) HasSchemas

func (s *Spec) HasSchemas() bool

HasSchemas returns true if the spec has a `components.schemas` section (even if empty).

func (*Spec) Paths

func (s *Spec) Paths() *ast.MappingNode

Paths returns the `paths` mapping node, or nil if absent.

func (*Spec) Schemas

func (s *Spec) Schemas() *ast.MappingNode

Schemas returns the `components.schemas` mapping node, or nil if absent.

func (*Spec) String

func (s *Spec) String() string

String serializes the spec back to YAML, preserving comments and formatting.

Jump to

Keyboard shortcuts

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