apispec

package
v0.32.1 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package apispec parses an OpenAPI document (the embedded vendored control spec, or a --live one fetched from the server) to back the `jentic api` passthrough: path-allowlist matching, operation listing, and per-operation self-description (`api describe`). It reuses libopenapi — the same parser tools/specgen uses — so the module carries exactly one spec-parsing dependency (impl/5.0 §6a).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Operation

type Operation struct {
	Method         string   `json:"method"`
	Path           string   `json:"path"`
	OperationID    string   `json:"operation_id,omitempty"`
	Summary        string   `json:"summary,omitempty"`
	PathParams     []Param  `json:"path_params,omitempty"`
	QueryParams    []Param  `json:"query_params,omitempty"`
	RequestBody    any      `json:"request_body_schema,omitempty"`
	RequiredFields []string `json:"required_fields,omitempty"`
	ResponseSchema any      `json:"response_schema,omitempty"`
}

Operation is the self-description of a single spec operation, JSON-serializable for `api describe` in agent mode.

type Param

type Param struct {
	Name     string `json:"name"`
	Required bool   `json:"required"`
	Type     string `json:"type,omitempty"`
	Desc     string `json:"description,omitempty"`
}

Param is a query/path parameter description.

type Spec

type Spec struct {
	Version string
	// contains filtered or unexported fields
}

Spec is a parsed OpenAPI document with a compiled route table for concrete-path matching.

func Parse

func Parse(specBytes []byte) (*Spec, error)

Parse builds a Spec from raw OpenAPI bytes (YAML or JSON). External $refs are left unresolved (hermetic; the control spec has none that matter for our use) and libopenapi's logger is silenced.

func (*Spec) Describe

func (s *Spec) Describe(method, reqPath string) (*Operation, bool)

Describe returns the full self-description for a concrete method+path, or ok=false if unmatched.

func (*Spec) HasPath

func (s *Spec) HasPath(reqPath string) bool

HasPath reports whether any route matches reqPath (regardless of method). Used to give a better error ("path exists, wrong method") than a bare not-found.

func (*Spec) List

func (s *Spec) List(filter string) []Operation

List returns every operation (method+path+summary), sorted by path then method, for `api ops`. filter, when non-empty, keeps only operations whose path, operationId, or summary contains it (case-insensitive).

func (*Spec) Match

func (s *Spec) Match(method, reqPath string) (*Operation, bool)

Match resolves a concrete request path + method against the spec. It ignores any query string on reqPath. When multiple templated routes match, the most specific wins: a static route (no path params) beats a templated one, and among templated routes fewer params beats more (mirrors how HTTP routers disambiguate /credentials/providers from /credentials/{id}). Returns the matched Operation description, or ok=false if no route/method matches.

Jump to

Keyboard shortcuts

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