Skip to main content

Crate gadk_openapi

Crate gadk_openapi 

Source
Expand description

gadk-openapi: an OpenAPI 3.0 and 3.1 toolset for gadk agents.

Load a document with OpenApiSpec (from a string with str::parse, a file with OpenApiSpec::from_file, or a URL with OpenApiSpec::fetch), then build an OpenApiToolset with an OpenApiConfig. Each operation becomes one tool, named after its operationId in snake_case. A tool’s arguments are the operation’s path, query and header parameters plus body for an application/json request body; a call returns {"status": <u16>, "body": <body>} for any HTTP status. Redirects are not followed: a 3xx response is returned as a result.

Calls of post, put, patch and delete operations need the user’s confirmation by default (RequireConfirmation::Mutating). Credentials come from a gadk_auth credential provider (OpenApiConfig::auth) or an API key in the query string (OpenApiConfig::query_api_key).

use gadk_openapi::{OpenApiConfig, OpenApiSpec, OpenApiToolset};

let spec = OpenApiSpec::fetch("https://petstore3.swagger.io/api/v3/openapi.json").await?;
let toolset = OpenApiToolset::new(&spec, OpenApiConfig::new().prefix("petstore"))?;
for skipped in toolset.skipped_operations() {
    println!("skipped {} {}: {}", skipped.method, skipped.path, skipped.reason);
}

Out of scope: Swagger 2.0, remote $refs, cookie parameters, form and multipart bodies, choosing credentials from securitySchemes, response schemas and streaming responses.

Structs§

OpenApiConfig
How OpenApiToolset calls the API. Start from OpenApiConfig::new (the same as Default) and chain the builder methods.
OpenApiSpec
An OpenAPI 3.0 or 3.1 document, parsed from JSON or YAML.
OpenApiToolset
The operations of one OpenAPI document as a Toolset named openapi_toolset: one tool per operation, in document order.
SkippedOperation
An operation that does not become a tool, and why.

Enums§

Error
An error loading an OpenAPI document, building the toolset, or sending a tool’s request.
RequireConfirmation
Which tool calls need the user’s confirmation before the request is sent.

Constants§

DEFAULT_MAX_RESPONSE_BYTES
The default largest response body kept in a tool result, in bytes (256 KiB).
DEFAULT_TIMEOUT
The default request timeout.