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 sectionOpenApi- 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
SplitSchemasByTag- Split schemas based on which tags use themExtractSchemasByPredicate- Extract schemas matching a predicate
Required Associated Types§
Required Methods§
Sourcefn split(&self, spec: OpenApi) -> SplitResult<Self::Fragment>
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
$refpointing 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.