openapi

package
v4.24.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FetchOrCacheSpec added in v4.5.1

func FetchOrCacheSpec(specURL string, refresh bool, skipCache bool) ([]byte, error)

FetchOrCacheSpec downloads a spec over http(s) with a 24h on-disk cache. Exported so packages outside internal/cli (notably internal/pipeline) can route URL-sourced specs through the same fetch path the generator uses, keeping scorer subcommands and generate in sync.

func IsGraphQLSDL

func IsGraphQLSDL(data []byte) bool

func IsOpenAPI

func IsOpenAPI(data []byte) bool

func IsRemoteSpecSource added in v4.1.0

func IsRemoteSpecSource(source string) bool

IsRemoteSpecSource reports whether a spec source should be loaded as a URL.

func LoadSpecBytes added in v4.5.1

func LoadSpecBytes(source string, refresh bool, skipCache bool) ([]byte, error)

LoadSpecBytes reads OpenAPI spec bytes from either a local filesystem path or an http(s) URL, picking the right transport from the source string. Callers that previously wrapped os.ReadFile gain URL support transparently; the local-path branch is identical to the prior os.ReadFile call.

URL responses are cached under ~/.cache/printing-press/specs for 24h to match the generator's intake behavior; pass refresh=true to bypass the cache and skipCache=true to skip writing it.

func Parse

func Parse(data []byte) (*spec.APISpec, error)

Parse parses an OpenAPI spec strictly. Use ParseLenient for specs with broken $refs.

func ParseFile added in v4.1.0

func ParseFile(path string) (*spec.APISpec, error)

ParseFile parses an OpenAPI spec from a file and resolves local external refs relative to that file.

func ParseFileLenient added in v4.1.0

func ParseFileLenient(path string) (*spec.APISpec, error)

ParseFileLenient parses an OpenAPI spec from a file and skips validation errors from broken $refs after resolving local external refs relative to that file.

func ParseLenient

func ParseLenient(data []byte) (*spec.APISpec, error)

ParseLenient parses an OpenAPI spec, skipping validation errors from broken $refs. It logs warnings to stderr for any issues found but continues parsing.

func ParseWithOptions added in v4.9.0

func ParseWithOptions(data []byte, opts ParseOptions) (*spec.APISpec, error)

ParseWithOptions is the canonical parser entry point; the older Parse* and ParseFile* helpers delegate to it with default ParseOptions plus their own path/lenient settings.

func ParseWithPath added in v4.1.0

func ParseWithPath(data []byte, path string) (*spec.APISpec, error)

ParseWithPath parses OpenAPI spec bytes and resolves local external refs relative to the given file path.

func ParseWithPathLenient added in v4.1.0

func ParseWithPathLenient(data []byte, path string) (*spec.APISpec, error)

ParseWithPathLenient parses OpenAPI spec bytes, resolving local external refs relative to the given file path and skipping validation errors from broken refs.

func SetMaxEndpointsPerResource

func SetMaxEndpointsPerResource(n int)

SetMaxEndpointsPerResource overrides the default limit and disables auto-calibration. When not called, the parser auto-calibrates the limit from the spec so well-formed specs never have endpoints silently skipped.

func SetMaxResources

func SetMaxResources(n int)

SetMaxResources overrides the default resource limit. When not called, the parser uses a default of 500 which accommodates all known APIs.

Types

type ParseOptions added in v4.9.0

type ParseOptions struct {
	// Path resolves local external refs relative to a file location. Empty
	// means the spec is treated as remote/in-memory only.
	Path string
	// Lenient skips validation errors from broken $refs.
	Lenient bool
	// Set when callers need other lenient cleanup while preserving missing-ref
	// failures.
	StrictRefs bool
	// AuthPreference names a security scheme from components.securitySchemes
	// that should win over the parser's default selection priority. Used when
	// a spec exposes multiple valid schemes (e.g. OAuth2 + basic) and the
	// caller knows which one fits the printed CLI's intended auth model.
	// Unknown names are ignored (default selection runs).
	AuthPreference string
	// SourceURL is the http(s) URL the spec was fetched from, when the spec
	// is remote. Used to derive an absolute BaseURL for specs whose servers:
	// block is relative-only (e.g. {url: /api/v3}). It does NOT affect $ref
	// resolution (that uses Path/location).
	SourceURL string
}

ParseOptions carries optional hints that influence parsing without changing the existing single-purpose Parse* signatures. New behavioral knobs (e.g. auth-scheme preference) should be added here rather than as new positional parameters across every entry point.

Jump to

Keyboard shortcuts

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