openapi

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package openapi parses the subset of an OpenAPI 3.x document that mcpify needs to expose each operation as an MCP tool: the servers, and for every operation its method, path, parameters, and JSON request body. Schemas are returned as generic JSON-compatible trees with local $refs inlined, so a tool's input schema is self-contained for clients that cannot resolve references.

Swagger 2.0 documents are accepted too: they are converted into the same Document model at parse time (see swagger2.go), so nothing downstream needs a second code path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Document

type Document struct {
	Title      string
	APIVersion string
	Servers    []Server
	Operations []Operation
	// Warnings collects non-fatal notes from parsing, such as operations skipped
	// because they consume formData. Callers surface these to the operator.
	Warnings []string
}

Document is the parsed, mcpify-relevant view of an OpenAPI spec.

func Load

func Load(data []byte) (*Document, error)

Load parses an OpenAPI 3.x or Swagger 2.0 document from JSON or YAML bytes. JSON is a subset of YAML, so one decoder handles both. A Swagger 2.0 document is converted into the same Document model as 3.x, so callers see one shape.

type Operation

type Operation struct {
	Method      string // upper-case: GET, POST, ...
	Path        string // template form, e.g. /pets/{petId}
	OperationID string
	Summary     string
	Description string
	Tags        []string
	Parameters  []Parameter
	RequestBody *RequestBody
}

Operation is a single path+method, the unit that becomes one MCP tool.

type Parameter

type Parameter struct {
	Name        string
	In          string // path | query | header | cookie
	Description string
	Required    bool
	Schema      map[string]any // JSON-schema fragment, $refs inlined
}

Parameter is a path, query, header, or cookie parameter.

type RequestBody

type RequestBody struct {
	Description string
	Required    bool
	Schema      map[string]any // JSON-schema fragment, $refs inlined
}

RequestBody is the application/json request body of an operation.

type Server

type Server struct {
	URL         string
	Description string
	Variables   map[string]string
}

Server is one entry from the spec's top-level servers list. Variables holds the default value of each server variable, used to fill a templated URL.

Jump to

Keyboard shortcuts

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