pub trait OpenApiExt {
// Required methods
fn openapi(&self) -> OpenApi;
fn openapi_with<F>(&self, configure: F) -> OpenApi
where F: FnOnce(OpenApiBuilder) -> OpenApiBuilder;
}Expand description
Extension trait for generating OpenAPI specifications from applications.
Required Methods§
Sourcefn openapi(&self) -> OpenApi
fn openapi(&self) -> OpenApi
Generate an OpenAPI specification from the application.
This creates an OpenAPI 3.1 document based on the application’s configuration and registered routes.
§Example
ⓘ
use fastapi::prelude::*;
use fastapi::OpenApiExt;
let app = App::builder()
.config(AppConfig::new().name("My API").version("1.0.0"))
.build();
let spec = app.openapi();
println!("{}", serde_json::to_string_pretty(&spec).unwrap());Sourcefn openapi_with<F>(&self, configure: F) -> OpenApi
fn openapi_with<F>(&self, configure: F) -> OpenApi
Generate an OpenAPI specification with custom configuration.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.