pub struct Fragment<T: Serialize> {
pub path: PathBuf,
pub content: T,
}Expand description
A fragment extracted from an OpenAPI specification.
Represents a piece of the original specification that should be written to a separate file.
The content can be any serializable type, typically Components,
OpenApi, or a custom subset of schemas.
§Type Parameters
T- The type of content in this fragment. Must implementSerializefor file output.
§Example
ⓘ
use clawspec_core::split::Fragment;
use std::path::PathBuf;
use utoipa::openapi::Components;
let fragment = Fragment {
path: PathBuf::from("schemas/common.yaml"),
content: Components::new(),
};Fields§
§path: PathBufRelative path where this fragment should be written.
This path is relative to the main OpenAPI specification file.
The main spec will use $ref pointing to this path.
content: TThe content to serialize into the fragment file.
Implementations§
Source§impl<T: Serialize> Fragment<T>
impl<T: Serialize> Fragment<T>
Sourcepub fn new(path: impl Into<PathBuf>, content: T) -> Self
pub fn new(path: impl Into<PathBuf>, content: T) -> Self
Creates a new fragment with the given path and content.
Sourcepub fn to_yaml(&self) -> Result<String, YamlError>
Available on crate feature yaml only.
pub fn to_yaml(&self) -> Result<String, YamlError>
yaml only.Serializes the fragment content to a YAML string.
Requires the yaml feature.
§Example
ⓘ
use clawspec_core::split::Fragment;
let fragment = Fragment::new("common.yaml", components);
let yaml = fragment.to_yaml()?;
std::fs::write(&fragment.path, yaml)?;§Errors
Returns a YamlError if serialization fails.
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Fragment<T>where
T: Freeze,
impl<T> RefUnwindSafe for Fragment<T>where
T: RefUnwindSafe,
impl<T> Send for Fragment<T>where
T: Send,
impl<T> Sync for Fragment<T>where
T: Sync,
impl<T> Unpin for Fragment<T>where
T: Unpin,
impl<T> UnwindSafe for Fragment<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