Skip to content

Translate if/then/else to oneOf #480

Open

Description

@ahl

Right now we don't support the if/then/else structure. I think it would be valid to transform it to a oneOf:

{
  "if": { "$ref": "#/$defs/A" },
  "then": { "$ref": "#/$defs/B" },
  "else": { "$ref": "#/$defs/C" },
}

transforms to

{
  "oneOf": [
    {
      "title": "then",
      "allOf": [
        { "$ref": "#/$defs/A" },
        { "$ref": "#/$defs/B" }
      ]
    },
    {
      "title": "else",
      "allOf": [
        { "not": { "$ref": "#/$defs/A" } },
        { "$ref": "#/$defs/C" }
      ]
    }
  ]
}

This should become something like:

#[serde(untagged)]
pub enum IfThenElseType {
    Then(BA),
    Else(CNotA),
}

Activity

  1. added
    if/thenNeeds support for if/then or if/then/else schemas
    on Jun 26, 2025
  2. ndreno commented on Mar 19, 2026

    @ndreno

    We've implemented a fix for this in our fork at barbacane-dev/typify. Happy to extract a clean PR if there's interest.

  3. nipil commented on May 25, 2026

    @nipil

    Hello, i have a similar not implemented: if/then/else schemas are not supported in cargo-typify 0.6.2

    It happens with ansible-lint meta.json schema :

    https://raw.githubusercontent.com/ansible/ansible-lint/refs/tags/v26.4.0/src/ansiblelint/schemas/meta.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    if/thenNeeds support for if/then or if/then/else schemas

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions