openapi

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package openapi loads and normalizes an OpenAPI 3 document into a model that the SpecRiot engine can execute. Only the information needed for generation and execution is retained.

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptySpec = errors.New("openapi: document contains no operations")

ErrEmptySpec is returned when a document contains no operations.

Functions

func MethodRank

func MethodRank(method string) int

MethodRank maps an HTTP method to a stable ordering rank.

Types

type Operation

type Operation struct {
	Method      string
	Path        string
	OperationID string
	Summary     string
	Description string
	Tags        []string
	Parameters  []*Parameter
	RequestBody *RequestBody
	Responses   []*Response
}

Operation is a normalized, executable HTTP operation.

func (*Operation) Key

func (o *Operation) Key() string

Key returns a stable identifier for the operation.

type Parameter

type Parameter struct {
	Name     string
	In       string // "path", "query", "header", "cookie"
	Required bool
	Schema   *schema.Schema
}

Parameter describes a request parameter in one of the standard locations.

type RequestBody

type RequestBody struct {
	ContentType string
	Required    bool
	Schema      *schema.Schema
}

RequestBody describes the request body of an operation.

type Response

type Response struct {
	StatusCode  int
	Description string
	ContentType string
	Schema      *schema.Schema
}

Response describes a declared response of an operation.

type Spec

type Spec struct {
	OpenAPI     string
	Title       string
	Version     string
	Description string
	Servers     []string
	Operations  []*Operation
}

Spec is a normalized OpenAPI document.

func LoadBytes

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

LoadBytes parses and normalizes an OpenAPI 3 document from raw bytes.

func LoadFile

func LoadFile(path string) (*Spec, error)

LoadFile parses and normalizes an OpenAPI 3 document from a file path. Local $refs are resolved during loading.

func (*Spec) SortedOperations

func (s *Spec) SortedOperations() []*Operation

SortedOperations returns operations sorted by (path, method) for a deterministic execution order. Methods follow a fixed rank rather than lexicographic order: get, put, post, delete, options, head, patch, trace.

Jump to

Keyboard shortcuts

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