ApiClient

Struct ApiClient 

Source
pub struct ApiClient { /* private fields */ }

Implementations§

Source§

impl ApiClient

Source§

impl ApiClient

Source

pub async fn collected_paths(&mut self) -> Paths

Source

pub async fn collected_openapi(&mut self) -> OpenApi

Generates a complete OpenAPI specification from collected request/response data.

This method aggregates all the information collected during API calls and produces a comprehensive OpenAPI 3.1 specification including paths, components, schemas, operation metadata, and server information.

§Features
  • Automatic Path Collection: All endpoint calls are automatically documented
  • Schema Generation: Request/response schemas are extracted from Rust types
  • Operation Metadata: Includes operation IDs, descriptions, and tags
  • Server Information: Configurable server URLs and descriptions
  • Tag Collection: Automatically computed from all operations
  • Component Schemas: Reusable schema definitions with proper references
§Example
use clawspec_core::{ApiClient, ToSchema};
use serde::{Serialize, Deserialize};

#[derive(Serialize, Deserialize, ToSchema)]
struct UserData { name: String }

let mut client = ApiClient::builder()
    .with_host("api.example.com")
    .with_info_simple("My API", "1.0.0")
    .add_server_simple("https://api.example.com", "Production server")
    .build()?;

let user_data = UserData { name: "John".to_string() };

// Make some API calls to collect data
client.get("/users")?.await?.as_json::<Vec<UserData>>().await?;
client.post("/users")?.json(&user_data)?.await?.as_json::<UserData>().await?;

// Generate complete OpenAPI specification
let openapi = client.collected_openapi().await;

// The generated spec includes:
// - API info (title, version, description)
// - Server definitions
// - All paths with operations
// - Component schemas
// - Computed tags from operations

// Export to different formats
let yaml = serde_saphyr::to_string(&openapi)?;
let json = serde_json::to_string_pretty(&openapi)?;
§Generated Content

The generated OpenAPI specification includes:

  • Info: API metadata (title, version, description) if configured
  • Servers: Server URLs and descriptions if configured
  • Paths: All documented endpoints with operations
  • Components: Reusable schema definitions
  • Tags: Automatically computed from operation tags
§Tag Generation

Tags are automatically computed from all operations and include:

  • Explicit tags set on operations
  • Auto-generated tags based on path patterns
  • Deduplicated and sorted alphabetically
§Performance Notes
  • This method acquires read locks on internal collections
  • Schema processing is cached to avoid redundant work
  • Tags are computed on-demand from operation metadata
Source

pub async fn register_schema<T>(&mut self)
where T: ToSchema + 'static,

Manually registers a type in the schema collection.

This method allows you to explicitly add types to the OpenAPI schema collection that might not be automatically detected. This is useful for types that are referenced indirectly, such as nested types.

§Type Parameters
  • T - The type to register, must implement ToSchema and 'static
§Example
use clawspec_core::ApiClient;

#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
struct NestedErrorType {
    message: String,
}

let mut client = ApiClient::builder().build()?;

// Register the nested type that might not be automatically detected
client.register_schema::<NestedErrorType>().await;

// Now when you generate the OpenAPI spec, NestedErrorType will be included
let openapi = client.collected_openapi().await;
Source§

impl ApiClient

Source

pub fn call( &self, method: Method, path: CallPath, ) -> Result<ApiCall, ApiClientError>

Source

pub fn get(&self, path: impl Into<CallPath>) -> Result<ApiCall, ApiClientError>

Source

pub fn post(&self, path: impl Into<CallPath>) -> Result<ApiCall, ApiClientError>

Source

pub fn put(&self, path: impl Into<CallPath>) -> Result<ApiCall, ApiClientError>

Source

pub fn delete( &self, path: impl Into<CallPath>, ) -> Result<ApiCall, ApiClientError>

Source

pub fn patch( &self, path: impl Into<CallPath>, ) -> Result<ApiCall, ApiClientError>

Trait Implementations§

Source§

impl Clone for ApiClient

Source§

fn clone(&self) -> ApiClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ApiClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more