spec

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package spec loads and normalizes Swagger 2.0 / OpenAPI 3.x definitions from JSON, YAML, or JavaScript-embedded sources into a single openapi3 document.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind string

Kind identifies the family/version of a parsed definition.

const (
	KindSwagger2  Kind = "Swagger 2.0"
	KindOpenAPI30 Kind = "OpenAPI 3.0"
	KindOpenAPI31 Kind = "OpenAPI 3.1"
	KindUnknown   Kind = "Unknown"
)

func Detect

func Detect(b []byte) (Kind, string)

Detect inspects raw bytes and returns the Kind plus the raw version string without fully parsing. Handles JSON and YAML (a JSON superset).

type Spec

type Spec struct {
	Kind      Kind
	Version   string // raw version string e.g. "2.0", "3.0.1"
	Title     string
	Doc       *openapi3.T
	Raw       map[string]any
	SourceURL string
}

Spec is a normalized API definition. Doc is always a v3 document (v2 is converted on load) so downstream code only handles one shape.

func Load

func Load(b []byte, sourceURL string) (*Spec, error)

Load parses raw bytes into a normalized Spec.

Jump to

Keyboard shortcuts

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