Skip to content

fix(schema): keep sibling keys when collapsing nullable anyOf and $ref - #176

Open
rliuup wants to merge 1 commit into
mainfrom
fix/keep-optional-field-description-in-schema
Open

rliuup wants to merge 1 commit into
mainfrom
fix/keep-optional-field-description-in-schema

Conversation

@rliuup

@rliuup rliuup commented Dec 5, 2026 •

Copy link
Copy Markdown

Summary

uipath init writes a schema for each entrypoint input and output. For a field typed Optional[X], pydantic emits an anyOf with a null branch and puts description and title beside it. transform_nullable_types returned only the non-null branch, so the field lost its description and title in entry-points.json. transform_references did the same to keys that sit beside a $ref.

This change merges those sibling keys back into the result. The siblings win over the branch or definition, so a field description beats the description of the referenced class. A default of None is still dropped, because the null branch it described is gone. A non-null default such as 0.5 is kept.

Bounds such as ge and le already survived, because pydantic puts them inside the non-null branch. The description and title were the missing parts.

Not in this change

Keeping null on outputs and on required nullable inputs is a separate step and is not touched here.

Tests

tests/test_schema.py adds six tests.

  • Optional[float] = Field(None, ge=0, le=1, description="d") keeps its description, title and bounds, and has no default.
  • float | None = Field(0.5, ...) keeps default: 0.5.
  • A field description beats the class docstring of a referenced model.
  • A 15-field model keeps one distinct description per property.
  • Keys beside a $ref survive resolution.
  • Keys beside a circular $ref survive.

The existing combined test now expects the title on test_model_property, which is the intended new output.

Verification

Layer Status Command Expected
Unit ✅ done uv run pytest 489 passed on three consecutive runs, including the 18 tests in tests/test_schema.py
Lint and types ✅ done uv run ruff check ., uv run ruff format --check ., uv run mypy --config-file pyproject.toml . all three clean
Real run ✅ done in a scratch project with Optional[float] = Field(None, ge=0, le=1, description="d"), install this branch editable and run uipath init entry-points.json input score has maximum, minimum, type, description and title, and no default. With released uipath-runtime 0.13.8 the description and title are missing.
Pipeline required, not run CI on this PR (lint, test, commit-lint) all green on the PR head

🔥 Critical layer: Real run. It is the only row that goes through uipath init and the written entry-points.json.

Coverage caveat: the unit tests ran on Python 3.11 and the real run on Python 3.12, both on macOS. CI also covers 3.13 and Windows. The golden files in the packages that depend on this function will gain a title on formerly nullable fields, and those packages refresh them after a release.

PR description test plan: ✅ present

transform_nullable_types returned only the non-null branch of a two-entry
anyOf, so keys beside the anyOf were lost. That dropped the description and
title of every Optional field in the generated schema. transform_references
had the same loss for keys beside a $ref.

Merge those sibling keys back into the result, with the siblings winning
over the branch or definition. A default of None is still dropped, because
the null branch it described is gone. A non-null default is kept.
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@rliuup
rliuup marked this pull request as ready for review December 5, 2026 18:33
@rliuup
rliuup requested review from a team and cristipufu as code owners December 5, 2026 18:33
Copilot AI lite review requested due to automatic review settings December 5, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

An active moderate issue remains because sibling schema values can retain unresolved nested references and omit their circular-reference status.

1 open issue
What changed in this PR

Preserves field metadata in runtime schemas used by uipath init when collapsing nullable types and resolving references.

Changes:

  • Retains sibling keys, giving them precedence over branch or definition values.
  • Drops null defaults while preserving non-null defaults.
  • Adds six regression tests and updates the expected nullable-field title.
File Description
tests/​test_schema.py Tests metadata, defaults, precedence, and circular references.
src/​uipath/​runtime/​schema.py Preserves sibling keys during schema transformations.

Review effort: Lite

Comment on lines +179 to 189
siblings = {k: v for k, v in schema.items() if k != "$ref"}

if ref_path in visited:
# Circular dependency detected
return {
"type": "object",
"description": f"Circular reference to {ref_path}",
**siblings,
}, True

visited.add(ref_path)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this. Pydantic emits only description, title, default, examples and deprecated beside $ref (checked on pydantic 2.14.4), so no sibling holds a schema that needs resolving. Recursing into them would also rewrite default and examples payloads, which are data.
On origin/main siblings were dropped entirely, so this PR adds no unresolved ref that was resolved before.

@nikhil-maryala nikhil-maryala left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve. No blocker. Small findings, none needed to merge.

Checked at 2b29a55:

  • Siblings are kept correctly in both collapses. A sibling wins over the $ref target and over the non-null branch (src/uipath/runtime/schema.py:203, :237). This is right: the field-level description and title beat the class docstring.
  • Null semantics are as before: the collapse still drops the null branch (schema.py:231-237). The PR only drops default: null, which is consistent with that (schema.py:235-236).
  • A non-null default is kept. Circular refs also keep siblings (schema.py:179, :186).

Small findings:

  1. schema.py:179/203, Copilot comment: siblings are not passed through transform_references. Real in theory. Pydantic emits only description, title and default beside $ref. A default is data, so recursing into it would be wrong. A properties sibling with a $ref stays unresolved. Low. A comment or a note is enough.
  2. schema.py:237: non_null_type is returned without recursion (the code was like this before the PR). A nested anyOf with null inside an Optional[Model] field is not collapsed. Add a test with an inner nullable field.
  3. schema.py:228: only anyOf with exactly 2 branches collapses. Three or more branches keep null and are not tested.
  4. Tests: no test for $ref siblings that set type or title against the target. Tests for a collapse inside a list (items) are also missing.
  5. tests/test_schema.py:286: output schemas now carry title on plain optional fields. This is a visible change for consumers. It looks intended.

Not verified: I did not run the tests, because pydantic is not installed in this sandbox and I did not install from the network. CI was not checked.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants