Documentation
¶
Index ¶
- func FilterByMethods(methods []string) option
- func FilterByOperationIds(operationIds []string) option
- func FilterByPaths(paths []string) option
- func FilterByTags(tags []string) option
- func LoadFromFile(path string) option
- func LoadFromURL(urlStr string) option
- func WithBasePath(basePath string) option
- func WithHeaders(provider func(ctx context.Context) (map[string]string, error)) option
- func WithHost(host string) option
- func WithUrlBuilder(urlBuilder func(operation *openapi2.Operation, method string, ...) string) option
- type OpenApiTools
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterByMethods ¶
func FilterByMethods(methods []string) option
FilterByMethods filters the OpenAPI specification to only include operations that use the specified HTTP methods.
func FilterByOperationIds ¶
func FilterByOperationIds(operationIds []string) option
FilterByOperationIds filters the OpenAPI specification to only include operations with the specified operation IDs.
func FilterByPaths ¶
func FilterByPaths(paths []string) option
FilterByPaths filters the OpenAPI specification to only include paths that match the specified paths.
func FilterByTags ¶
func FilterByTags(tags []string) option
FilterByTags filters the OpenAPI specification to only include operations that have at least one of the specified tags.
func LoadFromFile ¶
func LoadFromFile(path string) option
LoadFromFile loads an OpenAPI specification from a local file and applies it to the OpenApiTools instance.
func LoadFromURL ¶
func LoadFromURL(urlStr string) option
LoadFromURL loads an OpenAPI specification from a URL and applies it to the OpenApiTools instance.
func WithBasePath ¶
func WithBasePath(basePath string) option
WithBasePath allows you to set a custom base path for the OpenApiTools instance.
func WithHeaders ¶
WithHeaders allows you to set custom headers for the OpenApiTools instance. This can be useful for adding authentication tokens or other necessary headers when making requests to the API. Example usage:
o := NewOpenApiSpec(
LoadFromURL("https://example.com/api-docs.json"),
WithHeaders(func(ctx context.Context) map[string]string {
return map[string]string{
"Authorization": "Bearer <token>",
"Content-Type": "application/json",
}
}),
)
func WithHost ¶
func WithHost(host string) option
WithHost allows you to set a custom host for the OpenApiTools instance.
func WithUrlBuilder ¶
func WithUrlBuilder(urlBuilder func(operation *openapi2.Operation, method string, scheme, host, basePath, path, query string) string) option
WithUrlBuilder allows you to set a custom URL builder function for the OpenApiTools instance. This can be useful for customizing how URLs are constructed when making requests to the API. Example usage:
o := NewOpenApiSpec(
LoadFromURL("https://example.com/api-docs.json"),
WithUrlBuilder(func(scheme, host, basePath, path, query string) string {
base := scheme + "://" + host + basePath + "/custom" + path
if query != "" {
base += "?" + query
}
return base
}),
)
Types ¶
type OpenApiTools ¶
type OpenApiTools struct {
// contains filtered or unexported fields
}
func NewOpenApiSpec ¶
func NewOpenApiSpec(opts ...option) (*OpenApiTools, error)
func (*OpenApiTools) GetDoc ¶
func (o *OpenApiTools) GetDoc() *openapi2.T
GetDoc returns the OpenAPI specification document associated with the OpenApiTools instance.
func (*OpenApiTools) PrintOperationIds ¶
func (o *OpenApiTools) PrintOperationIds()
func (*OpenApiTools) RegisterToMcpServer ¶
func (o *OpenApiTools) RegisterToMcpServer(server *server.MCPServer) error
RegisterToMcpServer registers the OpenApiTools instance to the provided MCPServer. It builds the tools from the OpenAPI specification and adds them to the server. If there is an error during the tool building process, it returns the error.