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 + auto-generated types)
  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 path_param_type(&self, param: &OperationParam) -> TokenStream

Get the type for a path parameter.

Source

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

Get the type for a 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 response_type( &self, schema: &Option<ReferenceOr<Schema>>, op_name: &str, status: u16, ) -> TokenStream

Get the type for a response body.

Source

pub fn generate_query_struct( &self, op: &Operation, overrides: &TypeOverrides, ) -> Option<(Ident, TokenStream)>

Generate a query params struct for an operation.

Source

pub fn generate_path_type(&self, op: &Operation) -> TokenStream

Generate a path params type for an operation (usually a tuple).

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.