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 + inline param schemas)
- 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 param_type(&self, param: &OperationParam) -> TokenStream
pub fn param_type(&self, param: &OperationParam) -> TokenStream
Get the type for a path or 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 generate_query_struct(
&self,
op: &Operation,
overrides: &TypeOverrides,
unknown_field: Option<&Ident>,
) -> Option<(Ident, TokenStream)>
pub fn generate_query_struct( &self, op: &Operation, overrides: &TypeOverrides, unknown_field: Option<&Ident>, ) -> Option<(Ident, TokenStream)>
Generate a query params struct for an operation.
If unknown_field is provided, an additional #[serde(flatten)] field with that name
will be added to capture unknown query parameters as HashMap<String, String>.
Sourcepub fn generate_path_struct(
&self,
op: &Operation,
overrides: &TypeOverrides,
) -> Option<(Ident, TokenStream)>
pub fn generate_path_struct( &self, op: &Operation, overrides: &TypeOverrides, ) -> Option<(Ident, TokenStream)>
Generate a path params struct for an operation.
Returns Some((struct_name, struct_definition)) if the operation has path params,
or None if there are no path params or the struct is replaced by an override.
Path parameters are sorted by their position in the URL path to ensure correct serde deserialization order.