Skip to content

Show oneOf/anyOf variants inside an allOf in API reference - #4313

Closed
akira28 wants to merge 3 commits into
mainfrom
api-explorer-unions/allof-oneof
Closed

akira28 wants to merge 3 commits into
mainfrom
api-explorer-unions/allof-oneof

Conversation

@akira28

@akira28 akira28 commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

An allOf that combines a base schema with a oneOf or anyOf now renders its variants in the API reference. Each object variant shows the shared base properties plus its own.

Affects: API reference

Prompt summary: Improve how the API Explorer renders anyOf, oneOf and allOf, starting with the cases that lose information today. This PR covers the first one: unions nested in an allOf.

Why

GetSchemaProperties merges only the properties of allOf members, so a oneOf or anyOf member contributes nothing. A reader sees the base properties and never learns that the value is one of several shapes.

What

Unions inside allOf

SchemaAnalyzer now recognises an allOf with a union member and classifies the schema as that union. The base members must contribute properties. An allOf that only wraps a union $ref keeps its previous rendering.

Variants carry the base properties

Each object variant expands to the base properties followed by its own, through the existing variant list. Array and primitive variants are left unchanged. Shared properties repeat in every variant, and the required lists of the base and the variant carry over, so required properties keep their badge. When a variant redefines a base property of the same name, the variant's definition wins.

Property rows

A union stops being listed as a plain nested object only when its properties come from an allOf. A union that declares properties itself keeps listing them, and ApiPropertyTreeBuilder hands the rest to the variant list.

Verify

dotnet test tests/Elastic.ApiExplorer.Tests/
# BuildPropertyList_AllOfWithOneOfMember_ExpandsVariantsSharingBaseProperties

Out of scope: $ref targets that are themselves allOf + oneOf, listing shared properties once instead of per variant, and the Markdown export output. Later PRs in this stack can cover them.

Stack: 1 of 1 so far, the bottom of the stack on main. Further fixes will be added on top.

🤖 Generated with Claude Code

@akira28 akira28 changed the title Expand oneOf/anyOf variants inside an allOf in the API Explorer Show oneOf/anyOf variants inside an allOf in API reference Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Docs preview (local build)

Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4313/

@akira28
akira28 added this pull request to stack #4315 October 6, 2026 06:34
@akira28
akira28 force-pushed the api-explorer-unions/allof-oneof branch from f0557e4 to 632b3a4 Compare October 6, 2026 07:02
@akira28
akira28 force-pushed the api-explorer-unions/allof-oneof branch from 632b3a4 to 416c4e5 Compare October 6, 2026 11:31
@akira28
akira28 marked this pull request as ready for review October 6, 2026 11:42
@akira28
akira28 requested a review from a team as a code owner October 6, 2026 11:42
@akira28
akira28 requested a review from reakaleek October 6, 2026 11:42

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes due to a correctness issue in required-field propagation for the new allOf + union variant expansion path (see inline comment).


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

Comment thread tests/Elastic.ApiExplorer.Tests/ApiPropertyTreeBuilderTests.cs
Comment thread src/Elastic.ApiExplorer/Model/SchemaAnalyzer.cs Outdated
@akira28
akira28 force-pushed the api-explorer-unions/allof-oneof branch from 416c4e5 to 9fa12ac Compare October 6, 2026 13:14

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes for two correctness regressions in the new allOf + union rendering path: shared union-level properties can disappear, and duplicate property names can lose variant-specific constraints.


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

Comment thread src/Elastic.ApiExplorer/Components/PropertyTree/ApiPropertyTreeBuilder.cs Outdated
Comment thread src/Elastic.ApiExplorer/Model/SchemaAnalyzer.cs Outdated
akira28 and others added 3 commits October 6, 2026 15:34
An `allOf` that combined a base schema with a `oneOf` or `anyOf` showed only the base properties, so the choice between variants was invisible. Each object variant now renders the shared base properties plus its own.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The variant schema built for an `allOf` with a `oneOf` or `anyOf` had no `required` list, so required properties of the base and the variant rendered as optional. It now collects the lists of every member.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A union that declares its own properties lost them from the property row once unions stopped counting as plain objects, and a variant could not redefine a base property of the same name. Unions with direct properties list them again, and the merged variant schema takes the variant's definition when names clash.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@akira28
akira28 force-pushed the api-explorer-unions/allof-oneof branch from 9fa12ac to 35db829 Compare October 6, 2026 13:35

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Requesting changes for a correctness regression in the new allOf + oneOf/anyOf expansion path: properties/required declared on the union-bearing allOf member are dropped from rendered variants.


What is this? | From workflow: PR Review

Give us feedback! React with 🚀 if perfect, 👍 if helpful, 👎 if not.

if (keyword is null || variants is null)
continue;

var bases = allOf.Where(m => !ReferenceEquals(m, member)).ToArray();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[HIGH] allOf union-member shared properties are dropped from expanded variants

TrySplitAllOfUnion removes the union member from bases, and ClassifyAllOfUnion later builds each variant from MergeBasesInto(split.Bases, o.Schema). That loses properties/required declared directly on the union member itself.

Concrete failure shape:

pet:
  allOf:
    - $ref: '#/components/schemas/Base'
    - type: object
      properties:
        kind: { type: string }
      required: [kind]
      oneOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'

With the new split path, kind is not included in either expanded variant (Cat/Dog), and its required badge is lost. Before this change, GetSchemaProperties(allOf) included that member’s direct properties.

Please include the union member’s own non-union constraints (its direct/allOf-derived properties and required set) when synthesizing each variant.

@akira28

akira28 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #4327, which joins all seven PRs of this stack into one. The commits and the resolved review threads carry over.

@akira28 akira28 closed this Oct 6, 2026
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.

1 participant