clawspec_core/split/
mod.rs

1//! OpenAPI specification splitting utilities.
2//!
3//! This module provides tools for splitting a single OpenAPI specification into multiple files,
4//! allowing for better organization and reusability of schemas across different API specifications.
5//!
6//! # Overview
7//!
8//! When working with large APIs, it's common to want to:
9//! - Extract common schemas (like error types) into a shared file
10//! - Organize schemas by domain or tag
11//! - Share schemas across multiple API specifications
12//!
13//! This module provides the [`OpenApiSplitter`] trait and several implementations for common
14//! splitting strategies.
15//!
16//! # Example
17//!
18//! ## With the `yaml` feature (recommended)
19//!
20#![cfg_attr(feature = "yaml", doc = "```rust,ignore")]
21#![cfg_attr(not(feature = "yaml"), doc = "```rust,ignore")]
22//! use clawspec_core::split::{OpenApiSplitter, SplitSchemasByTag};
23//! use std::path::PathBuf;
24//!
25//! let spec: OpenApi = /* your collected OpenAPI spec */;
26//!
27//! // Split schemas by their tag usage
28//! let splitter = SplitSchemasByTag::new(PathBuf::from("common-types.yaml"));
29//! let result = splitter.split(spec);
30//!
31//! // Write fragments using the convenient to_yaml() method
32//! for fragment in &result.fragments {
33//!     let content = fragment.to_yaml()?;
34//!     std::fs::write(&fragment.path, content)?;
35//! }
36//!
37//! // Write main spec
38//! let main_content = result.main_to_yaml()?;
39//! std::fs::write("openapi.yaml", main_content)?;
40//! ```
41//!
42//! ## Using ToYaml trait directly
43//!
44#![cfg_attr(feature = "yaml", doc = "```rust,ignore")]
45#![cfg_attr(not(feature = "yaml"), doc = "```rust,ignore")]
46//! use clawspec_core::{ToYaml, split::{OpenApiSplitter, SplitSchemasByTag}};
47//!
48//! let result = splitter.split(spec);
49//!
50//! // The ToYaml trait is implemented for all Serialize types
51//! let main_yaml = result.main.to_yaml()?;
52//! ```
53
54mod fragment;
55mod splitter;
56mod strategies;
57
58pub use fragment::{Fragment, SplitResult};
59pub use splitter::{OpenApiSplitExt, OpenApiSplitter};
60pub use strategies::{ExtractSchemasByPredicate, SplitSchemasByTag};