Struct Generator

Source
pub struct Generator { /* private fields */ }

Implementations§

Source§

impl Generator

Source

pub fn new(openapi: OpenAPI, default_options: GeneratorOptions) -> Self

Creates a new instance of Generator.

§Arguments
  • openapi - An instance of the OpenAPI structure representing the OpenAPI specification.
  • default_options - An instance of GeneratorOptions to configure the generator’s behavior.
§Returns

A new Generator instance initialized with the provided OpenAPI specification and generator options.

§Examples
use openapiv3::OpenAPI;
use openapiv3_to_typescript::{Generator, GeneratorOptions};

let openapi = OpenAPI::default();
let options = GeneratorOptions::default();
let generator = Generator::new(openapi, options);
Source

pub fn generate_schema<'a>( &'a self, schema: &'a Schema, options: Option<GeneratorOptions>, ) -> PartialGeneration<'a>

Generates a TypeScript type definition from an OpenAPI schema.

§Arguments
  • schema - A reference to the Schema object from the OpenAPI specification that you want to generate the TypeScript type for.
  • options - An optional instance of GeneratorOptions to override the default options for this generation.
§Returns

A PartialGeneration instance containing the generated TypeScript type definition as a string and a vector of references that were included in the generation process.

§Examples
use openapiv3::{OpenAPI, Schema};
use openapiv3_to_typescript::{Generator, GeneratorOptions, PartialGeneration};

let openapi = OpenAPI::default();
let options = GeneratorOptions { skip_read_only: true };
let generator = Generator::new(openapi, options);
let schema = Schema::new_number();
let partial_generation: PartialGeneration = generator.generate_schema(&schema, None);

println!("{:?}", partial_generation);
Source

pub fn generate_path( &self, operation_id: String, ) -> Option<PartialGeneration<'_>>

Source

pub fn openapi(&self) -> &OpenAPI

Trait Implementations§

Source§

impl Debug for Generator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.