Skip to main content

OpenApiGenerator

Trait OpenApiGenerator 

Source
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§

Source

fn spec(&self) -> &OpenAPI

Get the OpenAPI specification

Source

fn registry(&self) -> &SchemaRegistry

Get the schema registry for reference resolution

Source

fn generate_header(&self) -> String

Generate the file header (imports, module declaration, etc.)

Source

fn generate_models(&self) -> Result<String>

Generate data models/DTOs from OpenAPI components

Source

fn generate_routes(&self) -> Result<String>

Generate route handlers from OpenAPI paths

Provided Methods§

Generate file footer (bootstrap, exports, etc.)

Source

fn generate(&self) -> Result<String>

Orchestrate the full code generation pipeline

Source

fn iter_paths<F>(&self, f: F) -> Result<()>
where F: FnMut(&str, &str, &Operation) -> Result<()>,

Iterate over all paths in the spec and apply a function to each operation

Source

fn iter_schemas<F>(&self, f: F) -> Result<()>
where F: FnMut(&str, &Schema) -> Result<()>,

Iterate over all component schemas and apply a function to each

Source

fn extract_request_body_type(&self, operation: &Operation) -> Option<String>

Extract request body type from operation (looks for application/json)

Source

fn extract_response_type(&self, operation: &Operation) -> String

Extract response type from operation (looks for 200/201 responses)

Source

fn extract_type_from_schema_ref( &self, schema_ref: &ReferenceOr<Schema>, ) -> String

Extract type name from a schema reference or inline schema

Source

fn format_type_name(&self, name: &str) -> String

Format a type name according to language conventions (PascalCase by default)

Source

fn default_response_type(&self) -> String

Return the language’s default response type (e.g., “dict[str, Any]”, “Record<string, unknown>”)

Source

fn generate_operation_id( &self, path: &str, method: &str, operation: &Operation, ) -> String

Generate operation ID (function/method name) from operation and path

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§