nori/codegen/ir
Language-agnostic intermediate representation for code generation.
Sits between the OpenAPI Document and language-specific generators.
Decouples parsing from generation: third-party emitters (other languages,
other frameworks) can consume CodegenIR without depending on the parser
or knowing the OpenAPI spec details.
Build one with nori.build_ir(doc), then walk it. The shape is intended
to be stable and human-readable — semantic versioning rules of nori
itself apply to this module.
Types
API key location.
pub type ApiKeyLocationIR {
InHeader
InQuery
InCookie
}
Constructors
-
InHeader -
InQuery -
InCookie
The complete codegen IR — everything a generator needs to produce code.
pub type CodegenIR {
CodegenIR(
title: String,
version: String,
base_url: option.Option(String),
types: List(TypeDef),
endpoints: List(Endpoint),
security_schemes: List(SecuritySchemeIR),
global_security: List(SecurityRequirementIR),
)
}
Constructors
-
CodegenIR( title: String, version: String, base_url: option.Option(String), types: List(TypeDef), endpoints: List(Endpoint), security_schemes: List(SecuritySchemeIR), global_security: List(SecurityRequirementIR), )Arguments
- global_security
-
Global security requirements (applied to all endpoints unless overridden)
An API endpoint.
pub type Endpoint {
Endpoint(
operation_id: String,
method: HttpMethod,
path: String,
summary: option.Option(String),
description: option.Option(String),
tags: List(String),
parameters: List(EndpointParam),
request_body: option.Option(RequestBodyIR),
responses: List(ResponseIR),
deprecated: Bool,
security: option.Option(List(SecurityRequirementIR)),
)
}
Constructors
-
Endpoint( operation_id: String, method: HttpMethod, path: String, summary: option.Option(String), description: option.Option(String), tags: List(String), parameters: List(EndpointParam), request_body: option.Option(RequestBodyIR), responses: List(ResponseIR), deprecated: Bool, security: option.Option(List(SecurityRequirementIR)), )Arguments
- security
-
Per-endpoint security. None = use global, Some([]) = public, Some([…]) = specific
An endpoint parameter.
pub type EndpointParam {
EndpointParam(
name: String,
location: ParamLocation,
type_ref: TypeRef,
required: Bool,
description: option.Option(String),
)
}
Constructors
-
EndpointParam( name: String, location: ParamLocation, type_ref: TypeRef, required: Bool, description: option.Option(String), )
An enum variant.
pub type EnumVariant {
EnumVariant(name: String, value: String)
}
Constructors
-
EnumVariant(name: String, value: String)
A field in a record type.
pub type Field {
Field(
name: String,
type_ref: TypeRef,
required: Bool,
description: option.Option(String),
read_only: Bool,
write_only: Bool,
)
}
Constructors
-
Field( name: String, type_ref: TypeRef, required: Bool, description: option.Option(String), read_only: Bool, write_only: Bool, )
HTTP methods.
pub type HttpMethod {
Get
Post
Put
Delete
Patch
Head
Options
}
Constructors
-
Get -
Post -
Put -
Delete -
Patch -
Head -
Options
Parameter locations.
pub type ParamLocation {
PathParam
QueryParam
HeaderParam
CookieParam
}
Constructors
-
PathParam -
QueryParam -
HeaderParam -
CookieParam
Primitive types.
pub type PrimitiveType {
PString
PInt
PFloat
PBool
PDateTime
PDate
PBinary
PUnit
}
Constructors
-
PString -
PInt -
PFloat -
PBool -
PDateTime -
PDate -
PBinary -
PUnit
Response IR.
pub type ResponseIR {
ResponseIR(
status_code: String,
description: String,
content_type: option.Option(String),
type_ref: option.Option(TypeRef),
)
}
Constructors
-
ResponseIR( status_code: String, description: String, content_type: option.Option(String), type_ref: option.Option(TypeRef), )
A security requirement: which scheme + required scopes.
pub type SecurityRequirementIR {
SecurityRequirementIR(
scheme_name: String,
scopes: List(String),
)
}
Constructors
-
SecurityRequirementIR(scheme_name: String, scopes: List(String))
A security scheme definition from components/securitySchemes.
pub type SecuritySchemeIR {
BearerAuth(name: String, format: option.Option(String))
ApiKeyAuth(
name: String,
param_name: String,
location: ApiKeyLocationIR,
)
BasicAuth(name: String)
OAuth2Auth(name: String)
OpenIdConnectAuth(name: String, url: String)
}
Constructors
-
BearerAuth(name: String, format: option.Option(String))Bearer token (Authorization: Bearer
) -
ApiKeyAuth( name: String, param_name: String, location: ApiKeyLocationIR, )API key in header, query, or cookie
-
BasicAuth(name: String)HTTP Basic auth
-
OAuth2Auth(name: String)OAuth2 — we store just the name, user implements the flow
-
OpenIdConnectAuth(name: String, url: String)OpenID Connect
A named type definition.
pub type TypeDef {
RecordType(
name: String,
fields: List(Field),
description: option.Option(String),
)
EnumType(
name: String,
variants: List(EnumVariant),
description: option.Option(String),
)
UnionType(
name: String,
members: List(TypeRef),
discriminator: option.Option(String),
description: option.Option(String),
)
AliasType(
name: String,
target: TypeRef,
description: option.Option(String),
)
}
Constructors
-
RecordType( name: String, fields: List(Field), description: option.Option(String), )Object type with fields, e.g., User { id, name, email }
-
EnumType( name: String, variants: List(EnumVariant), description: option.Option(String), )Enum type, e.g., Status = “active” | “inactive”
-
UnionType( name: String, members: List(TypeRef), discriminator: option.Option(String), description: option.Option(String), )Union type, e.g., UserOrAdmin = User | Admin
-
AliasType( name: String, target: TypeRef, description: option.Option(String), )Type alias, e.g., type UserId = String
A type reference — describes what type a field or parameter has.
pub type TypeRef {
Named(name: String)
Primitive(PrimitiveType)
Array(item: TypeRef)
Dict(key: TypeRef, value: TypeRef)
Nullable(inner: TypeRef)
Optional(inner: TypeRef)
Literal(value: String)
Unknown
}
Constructors
-
Named(name: String)Reference to another named type
-
Primitive(PrimitiveType)Primitive type
-
Array(item: TypeRef)Array of a type
-
Dictionary/map type
-
Nullable(inner: TypeRef)Nullable type (T | null)
-
Optional(inner: TypeRef)Optional type (may be absent)
-
Literal(value: String)Literal string value
-
UnknownUnknown/any type