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: ComponentsImplementations§
Source§impl OpenApiSpec
impl OpenApiSpec
Sourcepub fn builder(
title: impl Into<String>,
version: impl Into<String>,
) -> OpenApiBuilder
pub fn builder( title: impl Into<String>, version: impl Into<String>, ) -> OpenApiBuilder
Create a new builder.
Sourcepub fn to_json(&self) -> Result<String, Error>
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
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
impl Clone for OpenApiSpec
Source§fn clone(&self) -> OpenApiSpec
fn clone(&self) -> OpenApiSpec
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 moreSource§impl Debug for OpenApiSpec
impl Debug for OpenApiSpec
Source§impl<'de> Deserialize<'de> for OpenApiSpec
impl<'de> Deserialize<'de> for OpenApiSpec
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for OpenApiSpec
impl RefUnwindSafe for OpenApiSpec
impl Send for OpenApiSpec
impl Sync for OpenApiSpec
impl Unpin for OpenApiSpec
impl UnwindSafe for OpenApiSpec
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