Skip to main content

TypeGenerator

Struct TypeGenerator 

Source
pub struct TypeGenerator { /* private fields */ }
Expand description

Type generator that wraps typify’s TypeSpace.

Uses a two-pass approach:

  1. Pass 1: Generate all types (component schemas + inline param schemas)
  2. Pass 2: Generate code that references types using the registry built in Pass 1

Implementations§

Source§

impl TypeGenerator

Source

pub fn new(spec: &ParsedSpec) -> Result<Self>

Create a new type generator from a parsed spec with default settings.

Source

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.

Source

pub fn generate_all_types(&self) -> TokenStream

Generate all types as a TokenStream.

Source

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).

Source

pub fn is_inline_schema(schema: &ReferenceOr<Schema>) -> bool

Check if a schema is inline (not a reference).

Source

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.

Source

pub fn type_for_boxed_schema( &self, schema: &ReferenceOr<Box<Schema>>, name_hint: &str, ) -> TokenStream

Generate a type for a boxed schema reference.

Source

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.

Source

pub fn param_type(&self, param: &OperationParam) -> TokenStream

Get the type for a path or query parameter.

Source

pub fn request_body_type( &self, body: &RequestBody, op_name: &str, ) -> TokenStream

Get the type for a request body.

Source

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>.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.