pub struct TypeGenerator { /* private fields */ }Expand description
Type generator that wraps typify’s TypeSpace.
Uses a two-pass approach:
- Pass 1: Generate all types (component schemas + auto-generated types)
- Pass 2: Generate code that references types using the registry built in Pass 1
Implementations§
Source§impl TypeGenerator
impl TypeGenerator
Sourcepub fn new(spec: &ParsedSpec) -> Result<Self>
pub fn new(spec: &ParsedSpec) -> Result<Self>
Create a new type generator from a parsed spec with default settings.
Sourcepub fn with_settings(
spec: &ParsedSpec,
settings: TypeSpaceSettings,
renames: HashMap<String, String>,
) -> Result<Self>
pub fn with_settings( spec: &ParsedSpec, settings: TypeSpaceSettings, renames: HashMap<String, String>, ) -> Result<Self>
Create a new type generator from a parsed spec with custom settings and renames.
The renames map should contain original schema name -> new name mappings. These must match the patches configured in TypeSpaceSettings.
Sourcepub fn generate_all_types(&self) -> TokenStream
pub fn generate_all_types(&self) -> TokenStream
Generate all types as a TokenStream.
Sourcepub fn get_type_name(&self, reference: &str) -> Option<String>
pub fn get_type_name(&self, reference: &str) -> Option<String>
Get the type name for a schema reference. Returns the actual name from TypeSpace (after any renames applied by typify).
Sourcepub fn is_inline_schema(schema: &ReferenceOr<Schema>) -> bool
pub fn is_inline_schema(schema: &ReferenceOr<Schema>) -> bool
Check if a schema is inline (not a reference).
Sourcepub fn type_for_schema(
&self,
schema: &ReferenceOr<Schema>,
name_hint: &str,
) -> TokenStream
pub fn type_for_schema( &self, schema: &ReferenceOr<Schema>, name_hint: &str, ) -> TokenStream
Generate a type for an inline schema (returns only the type reference, discarding definitions).
For inline object types that need struct definitions, use type_for_schema_with_definitions.
Sourcepub fn type_for_boxed_schema(
&self,
schema: &ReferenceOr<Box<Schema>>,
name_hint: &str,
) -> TokenStream
pub fn type_for_boxed_schema( &self, schema: &ReferenceOr<Box<Schema>>, name_hint: &str, ) -> TokenStream
Generate a type for a boxed schema reference.
Sourcepub fn type_for_schema_with_definitions(
&self,
schema: &ReferenceOr<Schema>,
name_hint: &str,
) -> GeneratedType
pub fn type_for_schema_with_definitions( &self, schema: &ReferenceOr<Schema>, name_hint: &str, ) -> GeneratedType
Generate a type for a schema, returning both the type reference and any generated definitions. Use this when you need to collect inline struct definitions.
Sourcepub fn path_param_type(&self, param: &OperationParam) -> TokenStream
pub fn path_param_type(&self, param: &OperationParam) -> TokenStream
Get the type for a path parameter.
Sourcepub fn query_param_type(&self, param: &OperationParam) -> TokenStream
pub fn query_param_type(&self, param: &OperationParam) -> TokenStream
Get the type for a query parameter.
Sourcepub fn request_body_type(
&self,
body: &RequestBody,
op_name: &str,
) -> TokenStream
pub fn request_body_type( &self, body: &RequestBody, op_name: &str, ) -> TokenStream
Get the type for a request body.
Sourcepub fn response_type(
&self,
schema: &Option<ReferenceOr<Schema>>,
op_name: &str,
status: u16,
) -> TokenStream
pub fn response_type( &self, schema: &Option<ReferenceOr<Schema>>, op_name: &str, status: u16, ) -> TokenStream
Get the type for a response body.
Sourcepub fn generate_query_struct(
&self,
op: &Operation,
overrides: &TypeOverrides,
) -> Option<(Ident, TokenStream)>
pub fn generate_query_struct( &self, op: &Operation, overrides: &TypeOverrides, ) -> Option<(Ident, TokenStream)>
Generate a query params struct for an operation.
Sourcepub fn generate_path_type(&self, op: &Operation) -> TokenStream
pub fn generate_path_type(&self, op: &Operation) -> TokenStream
Generate a path params type for an operation (usually a tuple).