OpenApiSpec

Struct OpenApiSpec 

Source
pub struct OpenApiSpec {
    pub openapi: String,
    pub info: Info,
    pub components: Components,
}
Expand description

Complete OpenAPI 3.0 specification.

Fields§

§openapi: String§info: Info§components: Components

Implementations§

Source§

impl OpenApiSpec

Source

pub fn builder( title: impl Into<String>, version: impl Into<String>, ) -> OpenApiBuilder

Create a new builder.

Source

pub fn to_json(&self) -> Result<String, Error>

Convert to JSON string.

Examples found in repository?
examples/user_api.rs (line 142)
132fn main() {
133    // Build OpenAPI specification
134    let spec = OpenApiBuilder::new("User Management API", "1.0.0")
135        .description("API for managing users, addresses, and teams with validation")
136        .register::<User>()
137        .register::<Address>()
138        .register::<Team>()
139        .build();
140
141    // Output as JSON
142    let json = spec.to_json().expect("Failed to serialize to JSON");
143    println!("{}", json);
144
145    println!("\n=== Schema Generation Complete ===");
146    println!("Registered schemas:");
147    println!("  - User (with email, age, name, status)");
148    println!("  - Address (with street, zip code, city)");
149    println!("  - Team (with name and members array)");
150    println!("\nValidation constraints mapped to OpenAPI:");
151    println!("  [ok] email → format: email");
152    println!("  [ok] range(min, max) → minimum, maximum");
153    println!("  [ok] length(min, max) → minLength, maxLength");
154    println!("  [ok] one_of → enum");
155    println!("  [ok] min_items, max_items → minItems, maxItems");
156    println!("  [ok] numeric_string → pattern: ^[0-9]+$");
157}
More examples
Hide additional examples
examples/v08_features.rs (line 256)
244fn main() {
245    let spec = OpenApiBuilder::new("v0.8 Features Demo", "1.0.0")
246        .description("Demonstrates OpenAPI v0.8 features: composition, metadata, and extensions")
247        .register::<PaymentMethod>()
248        .register::<AdminUser>()
249        .register::<User>()
250        .register::<UserSettings>()
251        .register::<UserAccount>()
252        .register::<DateRange>()
253        .register::<OrderForm>()
254        .build();
255
256    println!("{}", spec.to_json().expect("Failed to serialize"));
257
258    println!("\n=== v0.8 Features Demonstrated ===");
259    println!("[ok] anyOf: PaymentMethod (union of card | cash)");
260    println!("[ok] allOf: AdminUser (extends User)");
261    println!("[ok] default: UserSettings.theme = 'auto'");
262    println!("[ok] example: UserSettings.theme example = 'dark'");
263    println!("[ok] examples: UserSettings.language examples = ['en', 'es', 'fr']");
264    println!("[ok] readOnly: UserAccount.id, createdAt (response only)");
265    println!("[ok] writeOnly: UserAccount.password (request only)");
266    println!("[ok] deprecated: UserAccount.oldUsername");
267    println!("[ok] vendor extensions: DateRange, OrderForm (x-domainstack-validations)");
268    println!("\nAll v0.8 features working correctly!");
269}

Trait Implementations§

Source§

impl Clone for OpenApiSpec

Source§

fn clone(&self) -> OpenApiSpec

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OpenApiSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for OpenApiSpec

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for OpenApiSpec

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,