Skip to content

NAS-138384 / 25.10.1 / Properly handle oneOf schema case (by Qubad786)#125

Merged
yocalebo merged 1 commit into
stable/goldeyefrom
NAS-138384-25.10.1
Nov 4, 2025
Merged

NAS-138384 / 25.10.1 / Properly handle oneOf schema case (by Qubad786)#125
yocalebo merged 1 commit into
stable/goldeyefrom
NAS-138384-25.10.1

Conversation

@bugclerk

@bugclerk bugclerk commented Nov 4, 2025

Copy link
Copy Markdown

Problem

We had midcli failing with the following pydantic model

class PoolDatasetCreateArgs(BaseModel):
    data: PoolDatasetCreateFilesystem | PoolDatasetCreateVolume = Field(discriminator='type')
    """Configuration data for creating a new ZFS dataset."""

Reason was that the schema generated for this uses oneOf and we ran into key error because of this as this was not handled.
Example schema:

{
  "discriminator": {
    "mapping": {
      "FILESYSTEM": "#/$defs/FilesystemType",
      "VOLUME": "#/$defs/VolumeType"
    },
    "propertyName": "type"
  },
  "oneOf": [
    {
      "properties": {
        "type": {
          "const": "FILESYSTEM",
          "default": "FILESYSTEM",
          "title": "type",
          "type": "string",
          "_name_": "type",
          "_required_": false
        },
        "name": {
          "title": "name",
          "type": "string",
          "_name_": "name",
          "_required_": true
        },
        "recordsize": {
          "default": "128K",
          "title": "recordsize",
          "type": "string",
          "_name_": "recordsize",
          "_required_": false
        }
      },
      "required": [
        "name"
      ],
      "title": "FilesystemType",
      "type": "object",
      "_attrs_order_": [
        "type",
        "name",
        "recordsize"
      ]
    },
    {
      "properties": {
        "type": {
          "const": "VOLUME",
          "default": "VOLUME",
          "title": "type",
          "type": "string",
          "_name_": "type",
          "_required_": false
        },
        "name": {
          "title": "name",
          "type": "string",
          "_name_": "name",
          "_required_": true
        },
        "volsize": {
          "title": "volsize",
          "type": "integer",
          "_name_": "volsize",
          "_required_": true
        }
      },
      "required": [
        "name",
        "volsize"
      ],
      "title": "VolumeType",
      "type": "object",
      "_attrs_order_": [
        "type",
        "name",
        "volsize"
      ]
    }
  ],
  "title": "data",
  "_name_": "data",
  "_required_": true
}

Solution

Properly handle oneOf in midcli so that it gets parsed in the correct way similar to how anyOf works.

Original PR: #124

(cherry picked from commit 490c9bd)
@bugclerk

bugclerk commented Nov 4, 2025

Copy link
Copy Markdown
Author

@yocalebo yocalebo merged commit c5a6d94 into stable/goldeye Nov 4, 2025
1 check passed
@yocalebo yocalebo deleted the NAS-138384-25.10.1 branch November 4, 2025 19:01
@bugclerk

bugclerk commented Nov 4, 2025

Copy link
Copy Markdown
Author

This PR has been merged and conversations have been locked.
If you would like to discuss more about this issue please use our forums or raise a Jira ticket.

@truenas truenas locked as resolved and limited conversation to collaborators Nov 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants