openapi

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package openapi provides OpenAPI integration for the upstream service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewOpenAPIUpstream

func NewOpenAPIUpstream() upstream.Upstream

NewOpenAPIUpstream creates a new instance of OpenAPIUpstream. It initializes a cache for storing parsed OpenAPI documents to avoid redundant parsing.

Types

type McpOperation

type McpOperation struct {
	OperationID string
	Summary     string
	Description string
	Method      string // e.g., GET, POST
	Path        string
	// Simplified schema representation for request body
	// Key: content type (e.g., "application/json")
	// Value: schema reference
	RequestBodySchema map[string]*openapi3.SchemaRef
	// Simplified schema representation for responses
	// Key: status code (e.g., "200")
	// Value: map of content type to schema reference
	ResponseSchemas map[string]map[string]*openapi3.SchemaRef
	Parameters      openapi3.Parameters // Store operation parameters (query, path, header, cookie)
}

McpOperation provides a simplified, MCP-centric representation of an OpenAPI operation. It contains the essential details needed to convert an API endpoint into an executable tool.

type OpenAPIUpstream

type OpenAPIUpstream struct {
	// contains filtered or unexported fields
}

OpenAPIUpstream implements the upstream.Upstream interface for services that are defined by an OpenAPI specification. It parses the spec, discovers the available operations, and registers them as tools.

func (*OpenAPIUpstream) Register

func (u *OpenAPIUpstream) Register(
	ctx context.Context,
	serviceConfig *configv1.UpstreamServiceConfig,
	toolManager tool.ManagerInterface,
	promptManager prompt.ManagerInterface,
	resourceManager resource.ManagerInterface,
	isReload bool,
) (string, []*configv1.ToolDefinition, []*configv1.ResourceDefinition, error)

Register processes an OpenAPI service configuration. It parses the OpenAPI specification, extracts the operations, converts them into tools, and registers them with the tool manager.

func (*OpenAPIUpstream) Shutdown

func (u *OpenAPIUpstream) Shutdown(_ context.Context) error

Shutdown gracefully terminates the OpenAPI upstream service. For HTTP-based services, this typically means closing any persistent connections.

type ParsedOpenAPIData

type ParsedOpenAPIData struct {
	Info    openapi3.Info
	Servers openapi3.Servers
	Paths   map[string]*PathItem
}

ParsedOpenAPIData holds the high-level information extracted from an OpenAPI specification, such as metadata, server details, and the defined paths.

type PathItem

type PathItem struct {
	PathRef *openapi3.PathItem
}

PathItem represents a single path within an OpenAPI specification and holds a reference to its corresponding openapi3.PathItem.

Jump to

Keyboard shortcuts

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