Skip to content

bugfix: nested oneOf/anyOf inside allOf#1250

Merged
sserrata merged 2 commits intomainfrom
bug/nested-oneof-anyof-allof
Nov 20, 2025
Merged

bugfix: nested oneOf/anyOf inside allOf#1250
sserrata merged 2 commits intomainfrom
bug/nested-oneof-anyof-allof

Conversation

@sserrata
Copy link
Member

Description

Issue

When rendering OpenAPI schemas with allOf containing multiple oneOf or anyOf items, the nested schemas were not rendering properly. The schema merge operation was losing or combining the separate constraint arrays instead of preserving them as independent options.

Example Schema Pattern

This issue affected schemas like:

allOf:

Constraint 1: Must be one of these policy types

  • oneOf:
    • security-rule-type
    • internet-rule-type
      discriminator: ...

Constraint 2: Must exist in one of these scopes

  • oneOf:
    • folder
    • snippet
    • deviceIn this pattern, the object must satisfy one option from each oneOf group (multiple independent constraints), but only one oneOf was rendering or they were incorrectly merged together.

Affected Operations

  • Create a security rule (POST /security-rules) in examples/httpbin.yaml
  • Any schema using allOf with multiple oneOf/anyOf constraints

Root Cause

The SchemaNode component was using mergeAllOf() for all allOf schemas, which flattens multiple oneOf arrays into a single merged result. This loses the independence of each constraint.

Solution

Modified packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx:

  1. Detect multiple choice constraints: Check if allOf contains more than one oneOf or anyOf item
  2. Preserve independence: Render each oneOf/anyOf constraint separately as its own tabbed interface
  3. Merge for shared properties: Still merge the schema to extract shared properties, which are rendered after the constraints
  4. Maintain backward compatibility: Standard allOf merge behavior is preserved for schemas without multiple choice constraints

Rendering Order

  • First: All oneOf/anyOf constraints (each as tabbed options)
  • Then: Shared properties that apply to all combinations

Changes

  • Modified packages/docusaurus-theme-openapi-docs/src/theme/Schema/index.tsx
  • Added test case POST /allof-multiple-oneof in demo/examples/tests/allOf.yaml

Testing

The fix has been tested with:

  • The original security-rules schema from httpbin.yaml
  • A new comprehensive test case in allOf.yaml demonstrating:
    • Two independent oneOf constraints (type selection + scope selection)
    • Shared properties across all combinations
    • Proper tab rendering for each constraint
    • Property visibility based on selected options

Screenshots

Before

Only one oneOf was visible, or constraints were incorrectly merged

After

Both oneOf constraints render as separate tabbed interfaces, followed by shared properties

- Detect when allOf contains multiple oneOf/anyOf items
- Render each constraint separately instead of merging (which loses information)
- Display oneOf/anyOf constraints before shared properties
- Fixes issue where nested oneOf schemas were not properly rendered in security-rules schema
- Demonstrates allOf containing two independent oneOf groups
- Shows realistic pattern where object must satisfy multiple constraints
- Includes shared properties that apply to all combinations
- Tests the fix for rendering multiple oneOf items within allOf
@sserrata sserrata self-assigned this Nov 20, 2025
@sserrata sserrata added the bug Something isn't working label Nov 20, 2025
@github-actions
Copy link

Size Change: +1.46 kB (+0.07%)

Total Size: 2.14 MB

Filename Size Change
demo/.docusaurus/globalData.json 56.1 kB +203 B (+0.36%)
demo/.docusaurus/registry.js 81.3 kB +290 B (+0.36%)
demo/.docusaurus/routes.js 77 kB +269 B (+0.35%)
demo/.docusaurus/routesChunkNames.json 31.8 kB +115 B (+0.36%)
demo/build/assets/js/main.********.js 714 kB +535 B (+0.07%)
demo/build/assets/js/runtime~main.********.js 20 kB +48 B (+0.24%)
ℹ️ View Unchanged
Filename Size
demo/.docusaurus/codeTranslations.json 2 B
demo/.docusaurus/docusaurus.config.mjs 14.6 kB
demo/.docusaurus/i18n.json 267 B
demo/.docusaurus/site-metadata.json 1.51 kB
demo/build/assets/css/styles.********.css 145 kB
demo/build/index.html 84.4 kB
demo/build/petstore/add-pet/index.html 27.8 kB
demo/build/petstore/create-user/index.html 22.5 kB
demo/build/petstore/create-users-with-array-input/index.html 22.6 kB
demo/build/petstore/create-users-with-list-input/index.html 22.6 kB
demo/build/petstore/delete-order/index.html 22.5 kB
demo/build/petstore/delete-pet/index.html 22.6 kB
demo/build/petstore/delete-user/index.html 22.8 kB
demo/build/petstore/find-pets-by-status/index.html 23.2 kB
demo/build/petstore/find-pets-by-tags/index.html 23.9 kB
demo/build/petstore/get-inventory/index.html 21.8 kB
demo/build/petstore/get-order-by-id/index.html 22.8 kB
demo/build/petstore/get-pet-by-id/index.html 23.3 kB
demo/build/petstore/get-user-by-name/index.html 22.9 kB
demo/build/petstore/login-user/index.html 23.4 kB
demo/build/petstore/logout-user/index.html 22.2 kB
demo/build/petstore/new-pet/index.html 22.7 kB
demo/build/petstore/pet/index.html 21 kB
demo/build/petstore/place-order/index.html 22 kB
demo/build/petstore/schemas/apiresponse/index.html 23.3 kB
demo/build/petstore/schemas/cat/index.html 37.2 kB
demo/build/petstore/schemas/category/index.html 24.3 kB
demo/build/petstore/schemas/dog/index.html 37.6 kB
demo/build/petstore/schemas/honeybee/index.html 37.7 kB
demo/build/petstore/schemas/id/index.html 21.4 kB
demo/build/petstore/schemas/order/index.html 25.5 kB
demo/build/petstore/schemas/pet/index.html 37.1 kB
demo/build/petstore/schemas/tag/index.html 22.7 kB
demo/build/petstore/schemas/user/index.html 44.8 kB
demo/build/petstore/store/index.html 20.2 kB
demo/build/petstore/subscribe-to-the-store-events/index.html 28.8 kB
demo/build/petstore/swagger-petstore-yaml/index.html 29 kB
demo/build/petstore/update-pet-with-form/index.html 22.7 kB
demo/build/petstore/update-pet/index.html 23.1 kB
demo/build/petstore/update-user/index.html 22.8 kB
demo/build/petstore/upload-file/index.html 22.6 kB
demo/build/petstore/user/index.html 20.7 kB

compressed-size-action

@github-actions
Copy link

Visit the preview URL for this PR (updated for commit 23ba905):

https://docusaurus-openapi-36b86--pr1250-rwhd9r00.web.app

(expires Sat, 20 Dec 2025 15:44:15 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: bf293780ee827f578864d92193b8c2866acd459f

@sserrata sserrata merged commit 2e26316 into main Nov 20, 2025
10 checks passed
@sserrata sserrata deleted the bug/nested-oneof-anyof-allof branch November 20, 2025 15:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant