Skip to content

Commit 4ebf730

Browse files
authored
Merge pull request #124 from truenas/mrehan/fix-pydantic-model-discriminator
NAS-138384 / 26.04 / Properly handle oneOf schema case
2 parents eccb9e8 + 490c9bd commit 4ebf730

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

midcli/command/generic_call/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ def _process_method(self, method):
3939
def _create_arguments(self):
4040
for i, item in enumerate(self.method["accepts"] or []):
4141
if i == self.splice_kwargs:
42-
if "anyOf" in item and all(option.get("type") == "object" for option in item["anyOf"]):
42+
# Handle discriminated unions (oneOf with discriminator) and anyOf unions
43+
if ("anyOf" in item or "oneOf" in item) and all(
44+
option.get("type") == "object" for option in item.get("anyOf") or item.get("oneOf")
45+
):
4346
# FIXME: Remove this when we use proper field discriminators in API
4447
item = {"type": "object", "_attrs_order_": []}
4548

midcli/gui/base/steps/input_delegate.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def create_input_delegate(input: "Input", schema: dict) -> "InputDelegate":
2929
type.add("null")
3030
elif isinstance(v, str):
3131
type.add("string")
32-
elif "anyOf" in schema and (type := {s["type"] for s in schema["anyOf"]}):
32+
elif ("anyOf" in schema or "oneOf" in schema) and (
33+
type := {s["type"] for s in schema.get("anyOf", []) or schema.get("oneOf", [])}
34+
):
3335
pass
3436
else:
3537
raise ValueError(f"Unable to create input delegate for schema {schema!r}")

0 commit comments

Comments
 (0)