Skip to content

$ref does not work in oneOf constructs #4580

@edan-bainglass

Description

@edan-bainglass

Prerequisites

What theme are you using?

@rjsf/react-bootstrap

Version

5.24.8

Current Behavior

I'm trying to use $defs and $ref to consolidate my schemas. However, $ref does not work as expected when used in a oneOf construct.

This works (can select another protocol)

{
  "type": "object",
  "$defs": {
    "protocol": {
      "type": "string",
      "enum": [
        "fast",
        "balanced",
        "stringent"
      ],
      "default": "fast"
    }
  },
  "properties": {
    "protocol": {
      "$ref": "#/$defs/protocol"
    }
  }
}

but this does not (can't switch protocols)

{
  "type": "object",
  "$defs": {
    "protocol": {
      "type": "string",
      "enum": [
        "fast",
        "balanced",
        "stringent"
      ],
      "default": "fast"
    }
  },
  "oneOf": [
    {
      "properties": {
        "protocol": {
          "$ref": "#/$defs/protocol"
        }
      }
    }
  ]
}

Also tested allOf, which works fine.

What am I missing?

Expected Behavior

Being able to switch between protocols

Steps To Reproduce

  1. Go to shared playground
  2. Try to select another protocol

Environment

Playground

Anything else?

The following construct again works, but is not ideal for my use case

{
  "type": "object",
  "$defs": {
    "protocol": {
      "type": "object",
      "properties": {
        "value": {
          "type": "string",
          "enum": [
            "fast",
            "balanced",
            "stringent"
          ],
          "default": "fast"
        }
      }
    }
  },
  "oneOf": [
    {
      "properties": {
        "protocol": {
          "$ref": "#/$defs/protocol"
        }
      }
    }
  ]
}

Metadata

Metadata

Labels

any-one-all-ofRelated to fixing anyOf, oneOf or allOfbug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions