Skip to main content

OpenApiParser

Struct OpenApiParser 

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

OpenAPI/Swagger parser

Converts OpenAPI 3.0 specifications into UniStructGen’s Intermediate Representation (IR). Supports both YAML and JSON formats.

§Examples

use unistructgen_openapi_parser::{OpenApiParser, OpenApiParserOptions};
use unistructgen_core::Parser;

let options = OpenApiParserOptions::builder()
    .generate_client(true)
    .generate_validation(true)
    .build();

let mut parser = OpenApiParser::new(options);

let yaml = std::fs::read_to_string("openapi.yaml").unwrap();
let ir_module = parser.parse(&yaml).unwrap();

println!("Generated {} types", ir_module.types.len());

Implementations§

Source§

impl OpenApiParser

Source

pub fn new(options: OpenApiParserOptions) -> Self

Create a new OpenAPI parser with the given options

Source

pub fn with_defaults() -> Self

Create a new parser with default options

Trait Implementations§

Source§

impl Parser for OpenApiParser

Source§

type Error = OpenApiError

The error type this parser produces
Source§

fn parse(&mut self, input: &str) -> Result<IRModule>

Parse input text and return an IR module Read more
Source§

fn name(&self) -> &'static str

Get the parser’s human-readable name Read more
Source§

fn extensions(&self) -> &[&'static str]

Get the file extensions this parser supports Read more
Source§

fn validate(&self, input: &str) -> Result<()>

Validate input without full parsing (optional) Read more
Source§

fn metadata(&self) -> ParserMetadata

Get metadata about the parser (optional) 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<P> ParserExt for P
where P: Parser,

Source§

fn parse_or<E>(&mut self, input: &str) -> Result<IRModule, E>
where E: From<Self::Error>,

Parse input and convert to a specific error type
Source§

fn parse_validated(&mut self, input: &str) -> Result<IRModule, Self::Error>

Parse input with validation first
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.