oxidecomputer / oxidecomputer/typify

Translate `if`/`then`/`else` to `oneOf`

Open
#480 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

if/then
Dominant language
Rust
Stars
898
Forks
114
Avg merge
4h 18m
Merged PRs (30d)
14

Description

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),
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests. Start by tracing existing oneOf handling in the JSON Schema-to-Rust compiler, then check whether the proposed if/then/else transformation preserves the conditional schema semantics. Done means supporting the structure and generating the corresponding untagged Rust enum representation.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.