openapi

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package openapi turns an OpenAPI 3.0/3.1 or Swagger 2.0 document into a model.Manifest (SPEC §3.4, §3.5).

The spec is untrusted input (SPEC §5.3, T1/T2/T4). Defenses, each tested in this package and in testdata/hostile:

  • only local "#/..." $refs resolve; libopenapi's file and remote lookups are switched off, and a pre-pass over the parsed node tree (refcheck.go) rejects ref chains deeper than MaxRefDepth and pure ref cycles without relying on those switches;
  • YAML alias expansion is limited (libopenapi's limit, never relaxed);
  • schema conversion is capped at MaxSchemaDepth levels and MaxSchemaNodes nodes per tool, degrading to {} with an Issue;
  • all spec text that reaches the model is cleaned (naming.CleanText);
  • libopenapi never logs to stdout, and its panics become errors.

Index

Constants

View Source
const (
	MaxSchemaDepth = 12
	MaxSchemaNodes = 5000
	MaxRefDepth    = 32
)

Limits on untrusted spec structure.

Variables

View Source
var (
	ErrUnsupportedSpec = errors.New("unsupported spec: need OpenAPI 3.0, 3.1 or Swagger 2.0")
	ErrRefTooDeep      = errors.New("$ref chain too deep")
	ErrRefCycle        = errors.New("$ref cycle")
	ErrParserPanic     = errors.New("spec parser failed")
	ErrInvalidSpec     = errors.New("invalid spec")
)

Sentinel errors callers can match with errors.Is.

Functions

func Parse

func Parse(data []byte, opts Options) (m *model.Manifest, err error)

Parse builds a Manifest from spec bytes (JSON or YAML).

Types

type Options

type Options struct {
	Prefix           string
	MaxDescription   int
	AllowUnsafePaths bool
	Logger           *slog.Logger
}

Options configures Parse.

Jump to

Keyboard shortcuts

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