pub trait OpenApiGenerator {
Show 15 methods
// Required methods
fn spec(&self) -> &OpenAPI;
fn registry(&self) -> &SchemaRegistry;
fn generate_header(&self) -> String;
fn generate_models(&self) -> Result<String>;
fn generate_routes(&self) -> Result<String>;
// Provided methods
fn generate_footer(&self) -> String { ... }
fn generate(&self) -> Result<String> { ... }
fn iter_paths<F>(&self, f: F) -> Result<()>
where F: FnMut(&str, &str, &Operation) -> Result<()> { ... }
fn iter_schemas<F>(&self, f: F) -> Result<()>
where F: FnMut(&str, &Schema) -> Result<()> { ... }
fn extract_request_body_type(&self, operation: &Operation) -> Option<String> { ... }
fn extract_response_type(&self, operation: &Operation) -> String { ... }
fn extract_type_from_schema_ref(
&self,
schema_ref: &ReferenceOr<Schema>,
) -> String { ... }
fn format_type_name(&self, name: &str) -> String { ... }
fn default_response_type(&self) -> String { ... }
fn generate_operation_id(
&self,
path: &str,
method: &str,
operation: &Operation,
) -> String { ... }
}Expand description
Base trait for OpenAPI code generators to eliminate duplication across languages.
Implementors should override language-specific methods while leveraging shared default implementations for common patterns.
Required Methods§
Sourcefn registry(&self) -> &SchemaRegistry
fn registry(&self) -> &SchemaRegistry
Get the schema registry for reference resolution
Sourcefn generate_header(&self) -> String
fn generate_header(&self) -> String
Generate the file header (imports, module declaration, etc.)
Sourcefn generate_models(&self) -> Result<String>
fn generate_models(&self) -> Result<String>
Generate data models/DTOs from OpenAPI components
Sourcefn generate_routes(&self) -> Result<String>
fn generate_routes(&self) -> Result<String>
Generate route handlers from OpenAPI paths
Provided Methods§
Generate file footer (bootstrap, exports, etc.)
Sourcefn iter_paths<F>(&self, f: F) -> Result<()>
fn iter_paths<F>(&self, f: F) -> Result<()>
Iterate over all paths in the spec and apply a function to each operation
Sourcefn iter_schemas<F>(&self, f: F) -> Result<()>
fn iter_schemas<F>(&self, f: F) -> Result<()>
Iterate over all component schemas and apply a function to each
Sourcefn extract_request_body_type(&self, operation: &Operation) -> Option<String>
fn extract_request_body_type(&self, operation: &Operation) -> Option<String>
Extract request body type from operation (looks for application/json)
Sourcefn extract_response_type(&self, operation: &Operation) -> String
fn extract_response_type(&self, operation: &Operation) -> String
Extract response type from operation (looks for 200/201 responses)
Sourcefn extract_type_from_schema_ref(
&self,
schema_ref: &ReferenceOr<Schema>,
) -> String
fn extract_type_from_schema_ref( &self, schema_ref: &ReferenceOr<Schema>, ) -> String
Extract type name from a schema reference or inline schema
Sourcefn format_type_name(&self, name: &str) -> String
fn format_type_name(&self, name: &str) -> String
Format a type name according to language conventions (PascalCase by default)
Sourcefn default_response_type(&self) -> String
fn default_response_type(&self) -> String
Return the language’s default response type (e.g., “dict[str, Any]”, “Record<string, unknown>”)
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.