IR Reference
The Intermediate Representation (IrSpec) is the version-agnostic data structure that generators consume. The lowering pass resolves all $ref references, classifies schemas, and normalizes operations into a flat list.
IrSpec
#![allow(unused)]
fn main() {
pub struct IrSpec {
pub info: IrInfo,
pub servers: Vec<IrServer>,
pub schemas: IndexMap<String, IrSchema>,
pub operations: Vec<IrOperation>,
pub security_schemes: IndexMap<String, IrSecurityScheme>,
pub security: Vec<IrSecurityRequirement>,
}
}
All maps use IndexMap for deterministic iteration order.
Schemas
Each IrSchema has a name, optional description, and a classified kind:
#![allow(unused)]
fn main() {
pub enum IrSchemaKind {
Object(IrObject),
Enum(IrEnum),
TaggedUnion(IrTaggedUnion),
Union(IrUnion),
Intersection(IrIntersection),
Alias(IrTypeExpr),
}
}
Object
An object with named properties and optional additional properties:
#![allow(unused)]
fn main() {
pub struct IrObject {
pub properties: IndexMap<String, IrProperty>,
pub additional_properties: Option<IrTypeExpr>,
}
}
Each IrProperty carries type_expr, required, nullable, optional description, default_value, format, and validation.
Enum
A typed enumeration with string, integer, number, or mixed values:
#![allow(unused)]
fn main() {
pub struct IrEnum {
pub value_type: IrEnumValueType,
pub values: Vec<IrEnumValue>,
}
}
TaggedUnion
A discriminated union (oneOf with a discriminator property):
#![allow(unused)]
fn main() {
pub struct IrTaggedUnion {
pub discriminator_property: String,
pub style: TaggedUnionStyle,
pub variants: Vec<IrTaggedVariant>,
}
}
Styles: InternallyTagged, ExternallyTagged, AdjacentlyTagged, Untagged.
Union
An untagged union (oneOf/anyOf without a discriminator):
#![allow(unused)]
fn main() {
pub struct IrUnion {
pub members: Vec<IrTypeExpr>,
}
}
Intersection
An allOf intersection:
#![allow(unused)]
fn main() {
pub struct IrIntersection {
pub members: Vec<IrTypeExpr>,
}
}
Alias
A type alias wrapping a single type expression (e.g., from a $ref):
#![allow(unused)]
fn main() {
Alias(IrTypeExpr)
}
Type Expressions
IrTypeExpr represents type references throughout the IR:
#![allow(unused)]
fn main() {
pub enum IrTypeExpr {
Named(String),
Primitive(IrPrimitive),
Array(Box<IrTypeExpr>),
Map(Box<IrTypeExpr>),
Nullable(Box<IrTypeExpr>),
Union(Vec<IrTypeExpr>),
Literal(serde_json::Value),
Unknown,
}
}
Operations
Each IrOperation represents one HTTP method + path:
#![allow(unused)]
fn main() {
pub struct IrOperation {
pub operation_id: String,
pub tags: Vec<String>,
pub method: String,
pub path: String,
pub summary: Option<String>,
pub description: Option<String>,
pub deprecated: bool,
pub parameters: Vec<IrParameter>,
pub request_body: Option<IrRequestBody>,
pub responses: Vec<IrResponse>,
pub security: Vec<IrSecurityRequirement>,
}
}
Parameters carry a ParameterLocation (Query, Header, Path, Cookie).
Request bodies map media types to IrTypeExpr:
#![allow(unused)]
fn main() {
pub struct IrRequestBody {
pub required: bool,
pub content: IndexMap<String, IrTypeExpr>,
}
}
Responses carry status code, description, content map, and headers.
Security Schemes
#![allow(unused)]
fn main() {
pub enum IrSecurityScheme {
ApiKey { name, location, description },
Http { scheme, bearer_format, description },
OAuth2 { flows, description },
OpenIdConnect { open_id_connect_url, description },
MutualTls { description },
}
}