Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docker/base/Dockerfile.nmp-studio-ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ COPY web/packages/sdk/generateAll.ts packages/sdk/generateAll.ts
COPY web/packages/sdk/orval.config.ts packages/sdk/orval.config.ts
COPY web/packages/sdk/orval packages/sdk/orval
COPY openapi /app/openapi
COPY plugins/nemo-anonymizer/openapi /app/plugins/nemo-anonymizer/openapi
COPY plugins/nemo-data-designer/openapi /app/plugins/nemo-data-designer/openapi
COPY plugins/nemo-agents/openapi /app/plugins/nemo-agents/openapi
COPY plugins/nemo-safe-synthesizer/openapi /app/plugins/nemo-safe-synthesizer/openapi
Expand Down
7 changes: 4 additions & 3 deletions packages/nmp_common/src/nmp/common/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,12 @@ def _anyof_null_visitor(key: str, value: Any, parent: Dict):
if len(value) == 1:
non_null = value[0]
del parent["anyOf"]
if "type" not in non_null and "$ref" not in non_null:
if not non_null.keys() & {"type", "$ref", "oneOf", "anyOf"}:
raise ValueError(f"Unsupported anyOf member format: {non_null}")
# Hoist every key from the non-null branch (type, format, writeOnly,
# readOnly, items, pattern, enum, examples, $ref, ...) onto the parent
# without overwriting parent-provided metadata like title/description.
# readOnly, items, pattern, enum, examples, $ref, oneOf, anyOf, ...) onto
# the parent without overwriting parent-provided metadata like
# title/description. An Optional[Union[...]] collapses to a bare oneOf.
for k, v in non_null.items():
parent.setdefault(k, v)

Expand Down
41 changes: 41 additions & 0 deletions packages/nmp_common/tests/api/test_utils_openapi_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,44 @@ def test_anyof_null_collapse_preserves_format_and_write_only():
"title": "Value",
"description": "The new secret value",
}


def test_anyof_null_collapse_hoists_optional_union():
"""``Optional[Union[...]]`` renders as ``anyOf: [{oneOf: [...]}, null]``.
Collapsing must drop the null branch and hoist the ``oneOf`` onto the parent."""
spec = {
"components": {
"schemas": {
"Config": {
"type": "object",
"title": "Config",
"properties": {
"replace": {
"anyOf": [
{
"oneOf": [
{"$ref": "#/components/schemas/Annotate"},
{"$ref": "#/components/schemas/Redact"},
]
},
{"type": "null"},
],
"default": None,
"title": "Replace",
}
},
}
}
},
"paths": {},
}

result = tweak_spec(spec)
prop = result["components"]["schemas"]["Config"]["properties"]["replace"]
assert prop == {
"oneOf": [
{"$ref": "#/components/schemas/Annotate"},
{"$ref": "#/components/schemas/Redact"},
],
"title": "Replace",
}
Loading