Skip to content

Fix fix_boolean_patterns recursion under nested combinators in if (#187)#188

Merged
aditigopalan merged 1 commit into
mainfrom
fix/boolean-pattern-recursion-in-if
May 18, 2026
Merged

Fix fix_boolean_patterns recursion under nested combinators in if (#187)#188
aditigopalan merged 1 commit into
mainfrom
fix/boolean-pattern-recursion-in-if

Conversation

@adamjtaylor
Copy link
Copy Markdown
Collaborator

Summary

  • scripts/linkml_to_flat_synapse_jsonschema.py::fix_boolean_patterns() only rewrote pattern: "^true$"const: true when the if clause had properties directly. It did not descend into if.anyOf[], if.oneOf[], if.allOf[], or if.not — so LinkML rules emitted as if: { anyOf: [...] } shipped with pattern: "^true$" against boolean fields. pattern is a string-only keyword, so those branches silently never matched and the conditional required never fired (e.g. PANEL_NAME was not enforced when PROTEIN_MEASURED: true).
  • Extends the walk so every subschema reachable inside an if clause is visited (anyOf, oneOf, allOf, not, and nested if/then/else), applying the same boolean-pattern → const rewrite wherever a properties map is found.
  • Adds six unit tests covering direct if.properties, if.anyOf, if.oneOf, if.not, true/false variants, and a regression test confirming string-typed patterns are left alone.

Fixes #187.

Test plan

  • PYTHONPATH=. python -m pytest tests/test_linkml_schema_conversion.py -v → 22 passed (16 existing + 6 new)
  • Black-formatted with the project's existing style
  • Downstream regen: after merge, regenerating JSON_Schemas/v1.5.0/HTAN.SpatialLevel3-v1.5.0-schema.json should now show "const": true inside the if.anyOf[] branches for PROTEIN_MEASURED instead of "pattern": "^true$". Per CLAUDE.md, that regen lands in a separate downstream PR.

🤖 Generated with Claude Code

The pattern -> const rewrite only descended into `if.properties`
directly, so LinkML rules emitted as `if: { anyOf: [...] }` left
`pattern: "^true$"` against boolean fields unchanged. Pattern is
string-only, so those branches silently never matched and the
conditional `required` never fired.

Walk every subschema reachable inside the `if` clause (anyOf, oneOf,
allOf, not, and nested if/then/else) and rewrite the boolean pattern
wherever it appears. Adds tests covering direct, anyOf, oneOf, and not
nesting, plus a regression test ensuring string patterns are untouched.

Fixes #187

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

HTAN Schema Review — ✅ Approved

Automated review by htan-claude · commit 977312c6a6a890f249975230f3a6d6eaeec071aa

This is a clean, well-scoped PR — the fix is targeted, the tests cover all the new recursive paths, and all three reviewers agree there's nothing to flag.

Tip

All checklist items pass — no issues found.

Files Changed

  • scripts/linkml_to_flat_synapse_jsonschema.py
  • tests/test_linkml_schema_conversion.py

Checklist Results

Check Result Notes
Inheritance correctness N/A No LinkML YAML schema files changed
Inlining of nested objects N/A No LinkML YAML schema files changed
Slot completeness (range, title, description) N/A No LinkML YAML schema files changed
Enum integrity (alphabetical, descriptions) N/A No LinkML YAML schema files changed
Generated artifacts PASS Downstream JSON schema regen is correctly deferred to a follow-on PR per CLAUDE.md; 22 unit tests pass including 6 new cases covering all recursive combinator paths

Verdict

APPROVE


Rules defined in CLAUDE.md · To update review rules, edit CLAUDE.md and open a PR to main

Copy link
Copy Markdown
Collaborator

@aditigopalan aditigopalan left a comment

Choose a reason for hiding this comment

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

LGTM!

@aditigopalan aditigopalan merged commit bf56c75 into main May 18, 2026
5 checks passed
@aditigopalan aditigopalan deleted the fix/boolean-pattern-recursion-in-if branch May 18, 2026 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix_boolean_patterns() doesn't recurse into anyOf/oneOf inside if clauses

2 participants