OpenApiSplitter

Trait OpenApiSplitter 

Source
pub trait OpenApiSplitter {
    type Fragment: Serialize;

    // Required method
    fn split(&self, spec: OpenApi) -> SplitResult<Self::Fragment>;
}
Expand description

Trait for splitting an OpenAPI specification into multiple files.

Implementations of this trait define different strategies for organizing schemas and other components into separate files for better modularity.

§Type Parameters

The associated type Fragment defines what type of content is extracted into separate files. Common choices include:

  • Components - Extract just the components section
  • OpenApi - Extract complete sub-specifications
  • Custom types implementing Serialize

§Implementing Custom Splitters

use clawspec_core::split::{OpenApiSplitter, SplitResult, Fragment};
use utoipa::openapi::{Components, OpenApi};
use std::path::PathBuf;

struct MyCustomSplitter {
    output_dir: PathBuf,
}

impl OpenApiSplitter for MyCustomSplitter {
    type Fragment = Components;

    fn split(&self, spec: OpenApi) -> SplitResult<Self::Fragment> {
        // Analyze the spec and extract schemas
        // Update refs in main spec to point to external files
        // Return the modified main spec and fragments
        todo!()
    }
}

§Built-in Implementations

Required Associated Types§

Source

type Fragment: Serialize

The type of content extracted into fragments.

Required Methods§

Source

fn split(&self, spec: OpenApi) -> SplitResult<Self::Fragment>

Splits the OpenAPI specification into a main spec and fragments.

This method consumes the input specification and returns:

  • A modified main spec with $ref pointing to external files
  • A collection of fragments to be written to separate files
§Arguments
  • spec - The OpenAPI specification to split
§Returns

A SplitResult containing the main spec and extracted fragments.

Implementors§