Module split

Module split 

Source
Expand description

OpenAPI specification splitting utilities.

This module provides tools for splitting a single OpenAPI specification into multiple files, allowing for better organization and reusability of schemas across different API specifications.

§Overview

When working with large APIs, it’s common to want to:

  • Extract common schemas (like error types) into a shared file
  • Organize schemas by domain or tag
  • Share schemas across multiple API specifications

This module provides the OpenApiSplitter trait and several implementations for common splitting strategies.

§Example

use clawspec_core::split::{OpenApiSplitter, SplitSchemasByTag};
use std::path::PathBuf;

let spec: OpenApi = /* your collected OpenAPI spec */;

// Split schemas by their tag usage
let splitter = SplitSchemasByTag::new(PathBuf::from("common-types.yaml"));
let result = splitter.split(spec);

// Write fragments using the convenient to_yaml() method
for fragment in &result.fragments {
    let content = fragment.to_yaml()?;
    std::fs::write(&fragment.path, content)?;
}

// Write main spec
let main_content = result.main_to_yaml()?;
std::fs::write("openapi.yaml", main_content)?;

§Using ToYaml trait directly

use clawspec_core::{ToYaml, split::{OpenApiSplitter, SplitSchemasByTag}};

let result = splitter.split(spec);

// The ToYaml trait is implemented for all Serialize types
let main_yaml = result.main.to_yaml()?;

Structs§

ExtractSchemasByPredicate
Extracts schemas matching a predicate into a separate file.
Fragment
A fragment extracted from an OpenAPI specification.
SplitResult
The result of splitting an OpenAPI specification.
SplitSchemasByTag
Splits schemas based on which tags use them.

Traits§

OpenApiSplitExt
Extension trait for convenient splitting of OpenAPI specifications.
OpenApiSplitter
Trait for splitting an OpenAPI specification into multiple files.