oas2moon_core

    Canonical Client IR, validation, naming, and type mapping for oas2moon.

    openapi
    ir
    validation
    codegen
    Download zip
    Version
    0.1.0
    License
    MIT
    Last updated
    5 hours ago
    Downloads
    3

    Dependencies

    #oas2moon core

    Canonical Client IR authority for oas2moon.

    This package validates the supported profile, applies deterministic naming and type mapping, and lowers the Frontend Model into the IR consumed by codegen.

    ApiIr

    pub struct ApiIr {
    module_name : String
    title : String
    version : String
    servers : Array[String]
    auth_schemes : Array[AuthSchemeIr]
    models : Array[ModelIr]
    operations : Array[OperationIr]
    } derive(Eq,
    Debug
    )

    The full Canonical Client IR for one API.

    AuthSchemeIr

    pub struct AuthSchemeIr {
    name : String
    kind : String
    location : String?
    key_name : String?
    } derive(Eq,
    Debug
    )

    Security scheme in the Canonical IR.

    Diagnostic

    pub struct Diagnostic {
    code : String
    severity : Severity
    json_pointer : String
    message : String
    operation_id : String?
    suggestion : String?
    } derive(Eq,
    Debug
    )

    A single diagnostic message.

    EnumModelIr

    pub struct EnumModelIr {
    name : String
    members : Array[(String, String)]
    } derive(Eq,
    Debug
    )

    An enum model.

    FieldIr

    pub struct FieldIr {
    name : String
    wire_name : String
    type_ref : TypeRef
    presence : Presence
    } derive(Eq,
    Debug
    )

    A struct model field.

    HttpMethod

    pub enum HttpMethod {
    Get
    Post
    Put
    Patch
    Delete
    } derive(Eq, Hash,
    Debug
    )

    Http method. Only the methods supported by V1 are listed.

    ModelIr

    pub enum ModelIr {
    EnumModel(EnumModelIr)
    StructModel(StructModelIr)
    } derive(Eq,
    Debug
    )

    A model in the Canonical IR: either an enum or a struct.

    OperationIr

    pub struct OperationIr {
    operation_id : String
    fn_name : String
    http_method : HttpMethod
    path : String
    tags : Array[String]
    parameters : Array[ParameterIr]
    request_body : RequestBodyIr?
    body_name : String?
    success_responses : Array[ResponseIr]
    error_responses : Array[ResponseIr]
    response_strategy : ResponseStrategy
    security : Array[String]
    source : SourceLocation
    } derive(Eq,
    Debug
    )

    A single operation in the Canonical IR.

    ParamLocation

    pub enum ParamLocation {
    Path
    Query
    Header
    } derive(Eq, Hash,
    Debug
    )

    Parameter location: path, query, or header.

    ParameterIr

    pub struct ParameterIr {
    name : String
    wire_name : String
    location : ParamLocation
    required : Bool
    nullable : Bool
    style : SerializationStyle
    explode : Bool
    type_ref : TypeRef
    source : SourceLocation
    } derive(Eq,
    Debug
    )

    A single parameter in the Canonical IR.

    Presence

    pub enum Presence {
    Required
    RequiredNullable
    Optional
    OptionalNullable
    } derive(Eq, Hash,
    Debug
    )

    Presence semantics for a field or parameter.

    RequestBodyIr

    pub struct RequestBodyIr {
    type_ref : TypeRef?
    required : Bool
    media_type : String?
    } derive(Eq,
    Debug
    )

    A request body in the Canonical IR.

    ResponseIr

    pub struct ResponseIr {
    status : Int
    type_ref : TypeRef?
    media_type : String?
    } derive(Eq,
    Debug
    )

    A single response in the Canonical IR.

    ResponseStrategy

    pub enum ResponseStrategy {
    SingleResult(TypeRef)
    UnitResult
    ResponseEnum(Array[ResponseVariant])
    NoContent
    UnsupportedMediaType(String)
    } derive(Eq,
    Debug
    )

    Computed response strategy for an operation.

    Determined during lowering from the success_responses array. Codegen emitters read this to decide the operation's return type shape.

    ResponseVariant

    pub struct ResponseVariant {
    status : Int
    type_ref : TypeRef
    } derive(Eq,
    Debug
    )

    One variant in a response enum strategy.

    SerializationStyle

    pub enum SerializationStyle {
    Simple
    Form
    UnsupportedStyle(String)
    } derive(Eq,
    Debug
    )

    Serialization style for a parameter.

    Severity

    pub enum Severity {
    Error
    Warning
    } derive(Eq,
    Debug
    )

    Severity of a diagnostic.

    SourceLocation

    pub struct SourceLocation {
    pointer : String
    } derive(Eq,
    Debug
    )

    Source location as a JSON Pointer (RFC 6901).

    StructModelIr

    pub struct StructModelIr {
    name : String
    fields : Array[FieldIr]
    additional_properties : Bool
    additional_properties_field : String?
    } derive(Eq,
    Debug
    )

    A struct model.

    TypeRef

    pub enum TypeRef {
    Scalar(String)
    Named(String)
    Array(TypeRef)
    } derive(Eq, Hash,
    Debug
    )

    A MoonBit type reference in the IR.

    api_to_json

    fn api_to_json(api : ApiIr) -> Json

    Serialize the full ApiIr to canonical JSON.

    api_to_json_string

    fn api_to_json_string(api : ApiIr) -> String

    Serialize ApiIr to a canonical JSON string.

    arr

    fn arr(v : Json) -> Array[Json]

    compute_presence

    fn compute_presence(required : Bool, nullable : Bool) -> Presence

    Determine presence from required and nullable flags.

    diagnostic_to_string

    fn diagnostic_to_string(d : Diagnostic) -> String

    Render a diagnostic as a human-readable string.

    error_diagnostic

    fn error_diagnostic(code : String, pointer : String, message : String) -> Diagnostic

    Create an error diagnostic.

    get

    fn get(v : Json, k : String) -> Json

    Standard IR JSON access helpers.

    is_nullable_presence

    fn is_nullable_presence(p : Presence) -> Bool

    Determine if a presence is nullable.

    is_required_presence

    fn is_required_presence(p : Presence) -> Bool

    Determine if a presence is required.

    lower

    fn lower(root : Json, module_name : String) -> ApiIr

    Parse the Frontend Model JSON root and produce an ApiIr.

    map_schema

    fn map_schema(schema : Json) -> TypeRef

    Map a Frontend Model schema JSON node to a TypeRef.

    obj

    fn obj(v : Json) -> Map[String, Json]

    operation_fn_name

    fn operation_fn_name(operation_id : String) -> String

    OperationID to snake_case function name.

    pascal

    fn pascal(name : String) -> String

    Convert to PascalCase.

    presence_to_string

    fn presence_to_string(p : Presence) -> String

    Convert a presence value to its canonical string representation.

    ref_target

    fn ref_target(ref_path : String) -> String

    Get the component name from a local $ref like #/components/schemas/Pet.

    snake

    fn snake(name : String) -> String

    Convert to snake_case.

    text

    fn text(v : Json) -> String

    truth

    fn truth(v : Json) -> Bool

    type_ref_to_json

    fn type_ref_to_json(t : TypeRef) -> Json

    Convert TypeRef to its canonical JSON representation.

    unique

    fn unique(base : String, taken : Map[String, Bool]) -> String

    Return base, or the first free base_N.

    warning_diagnostic

    fn warning_diagnostic(code : String, pointer : String, message : String) -> Diagnostic

    Create a warning diagnostic.

    words

    fn words(name : String) -> Array[String]

    Split a camelCase/PascalCase/kebab-case name into lowercase words.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io