openapi

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: MIT Imports: 19 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 is om's OpenAPI protocol: it compiles an OpenAPI 3.0–3.2 document into a core.Draft of operations, and each operation sends itself as an HTTP request with parameters serialized in the styles OpenAPI defines.

Only this package knows OpenAPI, kin-openapi, HTTP methods and parameter styles.

Index

Constants

View Source
const Format = 1

Format is the version of the OpenAPI model this package writes and serves. Raise it when a model of the current format can no longer be served the way this package would serve it, including when core's shared encoding of tools, inputs, credentials or definitions changes; every stored OpenAPI model then needs compiling again, and no other protocol's model is affected.

Variables

This section is empty.

Functions

func Decode

func Decode(data json.RawMessage) ([]core.Operation, error)

Decode reads the operations of a model whose format is Format. An operation this package cannot send, such as one with an unknown parameter location or credential, or a path that does not begin with "/", fails the whole model.

func Draft

func Draft(ctx context.Context, data []byte, location *url.URL) (core.Draft, error)

Draft compiles one OpenAPI 3.0–3.2 document. location resolves a relative server URL. An operation the document describes in a way om cannot send is omitted with its reason; core.Finish decides the rest.

Types

type Location

type Location string

Location is where an argument is sent, serialized in the style OpenAPI defines for it there: simple in a path or header, form in a query or cookie, and deepObject for a query object. https://spec.openapis.org/oas/v3.2.0.html#style-values

const (
	Path       Location = "path"
	Header     Location = "header"
	Query      Location = "query"
	DeepObject Location = "deepObject"
	Cookie     Location = "cookie"
)

func (*Location) UnmarshalText

func (l *Location) UnmarshalText(text []byte) error

type Operation

type Operation struct {
	core.Tool
	Method     string        `json:"method"`
	Path       string        `json:"path"`
	Parameters []Parameter   `json:"parameters,omitempty"`
	Body       bool          `json:"body,omitempty"`
	Security   core.Security `json:"security,omitempty"`
}

Operation is one OpenAPI operation: the tool it is listed as and the HTTP request it sends.

func (Operation) Annotations

func (o Operation) Annotations() *mcp.ToolAnnotations

Annotations follow HTTP's method semantics: GET, HEAD and OPTIONS are safe, PUT and DELETE idempotent. https://www.rfc-editor.org/rfc/rfc9110.html#section-9.2

func (Operation) Request

func (o Operation) Request(arguments core.Arguments) (core.Request, error)

Request serializes each parameter in its location's style, substitutes the path, and sends the body argument's raw bytes as the JSON body, so numbers keep their precision.

func (Operation) Result

func (o Operation) Result(response core.Response) (core.Outcome, error)

Result treats any 2xx as success. The whole body is the text, and, when the operation has an output schema, the structured result: the body parsed as JSON, or null when it is empty.

type Parameter

type Parameter struct {
	Name    string   `json:"name"`
	In      Location `json:"in"`
	Explode bool     `json:"explode,omitempty"`
}

Jump to

Keyboard shortcuts

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