Skip to content

re-order untagged enum#991

Open
Farossco wants to merge 1 commit intooxidecomputer:mainfrom
Farossco:fares/reordered_untagged_enum
Open

re-order untagged enum#991
Farossco wants to merge 1 commit intooxidecomputer:mainfrom
Farossco:fares/reordered_untagged_enum

Conversation

@Farossco
Copy link

@Farossco Farossco commented Mar 5, 2026

When parsing the following type of schema definition:

{
    "definitions": {
        "Value": {
            "type": [
                "array",
                "boolean",
                "integer",
                "number",
                "object",
                "string"
            ]
        }
    }
}

The following rust type is generated:

pub enum Value {
    Boolean(bool),
    Object(::serde_json::Map<::std::string::String, ::serde_json::Value>),
    Array(::std::vec::Vec<::serde_json::Value>),
    Number(f64),
    String(::std::string::String),
    Integer(i64),
}

This is mostly what we want but the issue here is the ordering. The use of a BTreeMap not only deduplicates but also re-orders the types to follow the ordering of the InstanceType enum from schemars which puts the Number type before the Integer type.

This makes the Integer variant of our Value enum here unreachable as all possible values can already be matched by the Number variant.

I believe that forcing the re-ordering of the variant instead of following the ordering declared in the schema is a good thing but it should be slightly tweaked.

This PR introduces an intermediate re-definition of this InstanceType enum with re-ordered fields and uses it for this BTreeMap deduplication.

This in terms, gives us the following rust enum definition:

pub enum Value {
    Boolean(bool),
    Integer(i64),
    Number(f64),
    String(::std::string::String),
    Array(::std::vec::Vec<::serde_json::Value>),
    Object(::serde_json::Map<::std::string::String, ::serde_json::Value>),
}

@Farossco Farossco force-pushed the fares/reordered_untagged_enum branch 3 times, most recently from e446496 to 5da50fb Compare March 5, 2026 14:01
Signed-off-by: Farès Chati <fchati@smartandconnective.com>
@Farossco Farossco force-pushed the fares/reordered_untagged_enum branch from 5da50fb to a79bf15 Compare March 5, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant