pub struct SplitResult<T: Serialize> {
pub main: OpenApi,
pub fragments: Vec<Fragment<T>>,
}Expand description
The result of splitting an OpenAPI specification.
Contains the main specification (with $ref references to external files)
and a collection of fragments to be written to separate files.
§Type Parameters
T- The type of content in the fragments. Must implementSerialize.
§Example
ⓘ
use clawspec_core::split::{OpenApiSplitter, SplitSchemasByTag, SplitResult};
let splitter = SplitSchemasByTag::new("common.yaml");
let result: SplitResult<_> = splitter.split(spec);
// Write fragments to files
for fragment in &result.fragments {
let yaml = serde_yaml::to_string(&fragment.content)?;
std::fs::write(&fragment.path, yaml)?;
}
// Write main spec
let main_yaml = serde_yaml::to_string(&result.main)?;
std::fs::write("openapi.yaml", main_yaml)?;Fields§
§main: OpenApiThe main OpenAPI specification with $ref references to extracted fragments.
fragments: Vec<Fragment<T>>Extracted fragments to be written to separate files.
Implementations§
Source§impl<T: Serialize> SplitResult<T>
impl<T: Serialize> SplitResult<T>
Sourcepub fn add_fragment(&mut self, fragment: Fragment<T>)
pub fn add_fragment(&mut self, fragment: Fragment<T>)
Adds a fragment to the result.
Sourcepub fn is_unsplit(&self) -> bool
pub fn is_unsplit(&self) -> bool
Returns true if there are no fragments (no splitting occurred).
Sourcepub fn fragment_count(&self) -> usize
pub fn fragment_count(&self) -> usize
Returns the number of fragments.
Sourcepub fn main_to_yaml(&self) -> Result<String, YamlError>
Available on crate feature yaml only.
pub fn main_to_yaml(&self) -> Result<String, YamlError>
yaml only.Serializes the main OpenAPI specification to a YAML string.
Requires the yaml feature.
§Example
ⓘ
use clawspec_core::split::{OpenApiSplitter, SplitSchemasByTag};
let result = splitter.split(spec);
let main_yaml = result.main_to_yaml()?;
std::fs::write("openapi.yaml", main_yaml)?;§Errors
Returns a YamlError if serialization fails.
Trait Implementations§
Source§impl<T: Clone + Serialize> Clone for SplitResult<T>
impl<T: Clone + Serialize> Clone for SplitResult<T>
Source§fn clone(&self) -> SplitResult<T>
fn clone(&self) -> SplitResult<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl<T> Freeze for SplitResult<T>
impl<T> RefUnwindSafe for SplitResult<T>where
T: RefUnwindSafe,
impl<T> Send for SplitResult<T>where
T: Send,
impl<T> Sync for SplitResult<T>where
T: Sync,
impl<T> Unpin for SplitResult<T>where
T: Unpin,
impl<T> UnwindSafe for SplitResult<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more