Skip to main content

gadk_openapi/
lib.rs

1// Copyright 2026 Chris Olson
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! gadk-openapi: an OpenAPI 3.0 and 3.1 toolset for gadk agents.
16//!
17//! Load a document with [`OpenApiSpec`] (from a string with [`str::parse`], a file with
18//! [`OpenApiSpec::from_file`], or a URL with [`OpenApiSpec::fetch`]), then build an
19//! [`OpenApiToolset`] with an [`OpenApiConfig`]. Each operation becomes one tool, named after
20//! its `operationId` in snake_case. A tool's arguments are the operation's path, query and
21//! header parameters plus `body` for an `application/json` request body; a call returns
22//! `{"status": <u16>, "body": <body>}` for any HTTP status. Redirects are not followed: a 3xx
23//! response is returned as a result.
24//!
25//! Calls of `post`, `put`, `patch` and `delete` operations need the user's confirmation by
26//! default ([`RequireConfirmation::Mutating`]). Credentials come from a `gadk_auth` credential
27//! provider ([`OpenApiConfig::auth`]) or an API key in the query string
28//! ([`OpenApiConfig::query_api_key`]).
29//!
30//! ```no_run
31//! # async fn example() -> Result<(), gadk_openapi::Error> {
32//! use gadk_openapi::{OpenApiConfig, OpenApiSpec, OpenApiToolset};
33//!
34//! let spec = OpenApiSpec::fetch("https://petstore3.swagger.io/api/v3/openapi.json").await?;
35//! let toolset = OpenApiToolset::new(&spec, OpenApiConfig::new().prefix("petstore"))?;
36//! for skipped in toolset.skipped_operations() {
37//!     println!("skipped {} {}: {}", skipped.method, skipped.path, skipped.reason);
38//! }
39//! # Ok(())
40//! # }
41//! ```
42//!
43//! Out of scope: Swagger 2.0, remote `$ref`s, cookie parameters, form and multipart bodies,
44//! choosing credentials from `securitySchemes`, response schemas and streaming responses.
45
46mod config;
47mod error;
48mod operation;
49mod request;
50mod resolve;
51mod spec;
52mod tool;
53mod toolset;
54
55pub use config::{DEFAULT_MAX_RESPONSE_BYTES, DEFAULT_TIMEOUT, OpenApiConfig, RequireConfirmation};
56pub use error::Error;
57pub use operation::SkippedOperation;
58pub use spec::OpenApiSpec;
59pub use toolset::OpenApiToolset;