From 14e0c649c89a3cdfd80de75464eb51f99d44f00d Mon Sep 17 00:00:00 2001 From: "M. Rehan" Date: Tue, 4 Nov 2025 23:33:18 +0500 Subject: [PATCH] Properly handle oneOf schema case (cherry picked from commit 490c9bde58983fd1d84aaeaf0f5afe1529e7ef7a) --- midcli/command/generic_call/__init__.py | 5 ++++- midcli/gui/base/steps/input_delegate.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/midcli/command/generic_call/__init__.py b/midcli/command/generic_call/__init__.py index 0cea71a..52417b4 100644 --- a/midcli/command/generic_call/__init__.py +++ b/midcli/command/generic_call/__init__.py @@ -39,7 +39,10 @@ def _process_method(self, method): def _create_arguments(self): for i, item in enumerate(self.method["accepts"] or []): if i == self.splice_kwargs: - if "anyOf" in item and all(option.get("type") == "object" for option in item["anyOf"]): + # Handle discriminated unions (oneOf with discriminator) and anyOf unions + if ("anyOf" in item or "oneOf" in item) and all( + option.get("type") == "object" for option in item.get("anyOf") or item.get("oneOf") + ): # FIXME: Remove this when we use proper field discriminators in API item = {"type": "object", "_attrs_order_": []} diff --git a/midcli/gui/base/steps/input_delegate.py b/midcli/gui/base/steps/input_delegate.py index eb48ec2..63d5253 100644 --- a/midcli/gui/base/steps/input_delegate.py +++ b/midcli/gui/base/steps/input_delegate.py @@ -29,7 +29,9 @@ def create_input_delegate(input: "Input", schema: dict) -> "InputDelegate": type.add("null") elif isinstance(v, str): type.add("string") - elif "anyOf" in schema and (type := {s["type"] for s in schema["anyOf"]}): + elif ("anyOf" in schema or "oneOf" in schema) and ( + type := {s["type"] for s in schema.get("anyOf", []) or schema.get("oneOf", [])} + ): pass else: raise ValueError(f"Unable to create input delegate for schema {schema!r}")