Expand description
OpenAPI/Swagger parser for UniStructGen
This crate provides a parser that converts OpenAPI 3.0 specifications into UniStructGen’s Intermediate Representation (IR), enabling automatic generation of Rust types, API clients, and validation code.
§Features
- Parse OpenAPI 3.0 specifications (YAML and JSON)
- Convert schemas to Rust structs and enums
- Generate API client traits with typed methods
- Support for request/response validation
- Handle references ($ref) and schema composition (allOf, oneOf, anyOf)
- Fetch specs from URLs or local files
§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 spec = std::fs::read_to_string("openapi.yaml").unwrap();
let ir_module = parser.parse(&spec).unwrap();Re-exports§
pub use error::OpenApiError;pub use error::Result;pub use options::OpenApiParserOptions;pub use options::OpenApiParserOptionsBuilder;pub use parser::OpenApiParser;
Modules§
- client
- API client trait generation from OpenAPI paths
- error
- Error types for OpenAPI parser
- fetch
- Fetch OpenAPI specifications from URLs
- options
- Parser configuration options
- parser
- Main OpenAPI parser implementation
- schema
- Schema conversion from OpenAPI to IR
- types
- Type conversion utilities for OpenAPI schemas
- validation
- Validation constraint extraction from OpenAPI schemas
Structs§
- IRModule
- Intermediate Representation Module Contains all types that will be generated
- IRStruct
- Struct definition
Enums§
- IRType
- Type definition in the IR
- IRType
Ref - Type reference
- Primitive
Kind - Primitive type kinds
Traits§
- Parser
- Core trait for all parsers