Skip to content

@W-23748899 feat(composition): render if/then/else conditional schemas - #101

Merged
alexpmule merged 2 commits into
W-23748896-composition-labelsfrom
fix/render-if-then-else-conditional-schemas
Aug 26, 2026
Merged

alexpmule merged 2 commits into
W-23748896-composition-labelsfrom
fix/render-if-then-else-conditional-schemas

Conversation

@alexpmule

@alexpmule alexpmule commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

What

Render JSON Schema 2020-12 / OAS 3.1 if/then/else conditional schemas in api-type-document.

AMF 5.11 already parses these keywords into shacl#if / shacl#then / shacl#else triples with the branch shapes fully present, but the component had no rendering support for them. A shape whose only content was a conditional fell through to the AnyShape scalar fallback in _typeChanged and collapsed to a generic "Any" badge — the branch properties (kind / breed / indoor) were silently dropped.

Why

Follow-up to #100 (W-23748896), which added OAS 3.1 composition-label support but explicitly scoped out conditional schemas. Filed as W-23748899 under the OAS 3.1/3.2 API Console umbrella (TD-0333486).

How

  • Detection (_typeChanged): a single additive check after the existing if / else-if chain flags isConditional when the shape carries the if keyword and resolves the three branch shapes. It only ever clears isScalar (gated on isConditional) and never writes any other flag, so oneOf/anyOf/allOf/object detection cannot regress.
  • Raw SHACL IRIs: the frozen amf-helper-mixin namespace exposes no if/then/else members, so the IRIs are built from the existing shacl namespace prefix and passed through _getAmfKey exactly like every other shacl key in the file. No change to amf-helper-mixin.
  • Rendering (_conditionalTemplate): mirrors the existing _anyTemplate/_oneOfTemplate pattern — each present branch renders via a recursive <api-type-document>, reusing the existing property/enum rendering (the if condition's const: dog surfaces through the existing shacl#in path). then and else are independently optional per JSON Schema, so an if+else shape without then renders both branches instead of a blank.

Scope

  • No changes to amf-helper-mixin, TypeStyles.js, or the property-rendering components.
  • Out of scope: oneOf/anyOf/allOf (unchanged), OAS 3.2-specific keywords.

Testing

New describe('Conditional type (if/then/else)') block (runs in both Regular and Compact model variants) against the existing PetKindFields fixture from demo/oas31-webhooks:

  • isConditional true / isScalar false (does not collapse to "Any") — AC1
  • if/then/else resolve to NodeShape branches — AC1
  • branch documents render kind / breed / indoor, and the if condition shows the const value dogAC2
  • if+else-without-then renders If + Else with no silent blank — AC1 edge

Full suite: 586 passed, 0 failed, 13 skippedoneOf/anyOf/allOf blocks unchanged (AC3).

Acceptance criteria

  • AC1 — If/Then/Else branches (and their properties) render instead of collapsing to "Any"
  • AC2 — demo/oas31-webhooks PetKindFields renders kind=dog (If) / breed (Then) / indoor (Else)
  • AC3 — no regression to oneOf/anyOf/allOf rendering

Notes for reviewers

Screenshots

Screenshot 2026-08-26 at 12 38 12 AM Screenshot 2026-08-26 at 12 38 24 AM

JSON Schema 2020-12 / OAS 3.1 if/then/else keywords were parsed by AMF
but not rendered: a shape whose only content was a conditional fell
through to the AnyShape scalar fallback and collapsed to a generic
"Any" badge.

Detect shacl#if/then/else in _typeChanged (raw IRIs built from the
frozen shacl namespace prefix, since amf-helper-mixin exposes no
if/then/else members) and render each present branch via a recursive
api-type-document, mirroring the existing oneOf/anyOf/allOf pattern.
then and else are independently optional per JSON Schema, so an
if-plus-else shape without then renders both branches, not a blank.
@alexpmule
alexpmule merged commit bd2cc0a into W-23748896-composition-labels Aug 26, 2026
1 check passed
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.

1 participant