Skip to content

Commit 676465d

Browse files
committed
fix: prevent duplicate variant examples in oneOf dropdown for nested oneOf schemas
- Ensure top-level oneOf only expands variants at root without combinatorial duplication for nested properties - Simplify mergePropertyExamples to update property values directly - Fix property merging across allOf schemas in schemaToSampleObj - Add visual test page and unit tests for oneOf example deduplication fixes #1143
1 parent f98de22 commit 676465d

7 files changed

Lines changed: 10006 additions & 621 deletions

File tree

‎docs/generated-docs/rapidoc/rapidoc-min.js‎

Lines changed: 4874 additions & 226 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
openapi: 3.1.0
2+
info:
3+
title: oneOf Nested Example Validation
4+
version: 1.0.0
5+
description: Validates that top-level oneOf request body schemas with discriminator mappings list each variant exactly once in the EXAMPLE dropdown, even when sub-properties contain nested oneOf schemas.
6+
paths:
7+
/things:
8+
post:
9+
summary: Create a Thing
10+
description: Polymorphic Request body containing top-level oneOf variants (PlainVariant and NestedOneOfVariant), where NestedOneOfVariant contains a nested oneOf in EntryRef.
11+
requestBody:
12+
required: true
13+
content:
14+
application/json:
15+
schema:
16+
$ref: '#/components/schemas/Request'
17+
responses:
18+
'200':
19+
description: Successful response
20+
content:
21+
application/json:
22+
schema:
23+
$ref: '#/components/schemas/Request'
24+
components:
25+
schemas:
26+
Request:
27+
oneOf:
28+
- $ref: '#/components/schemas/PlainVariant'
29+
- $ref: '#/components/schemas/NestedOneOfVariant'
30+
discriminator:
31+
propertyName: kind
32+
mapping:
33+
plain: '#/components/schemas/PlainVariant'
34+
nested: '#/components/schemas/NestedOneOfVariant'
35+
PlainVariant:
36+
title: PlainVariant
37+
type: object
38+
properties:
39+
kind:
40+
type: string
41+
enum:
42+
- plain
43+
value:
44+
type: string
45+
NestedOneOfVariant:
46+
title: NestedOneOfVariant
47+
type: object
48+
properties:
49+
kind:
50+
type: string
51+
enum:
52+
- nested
53+
entry:
54+
$ref: '#/components/schemas/EntryRef'
55+
EntryRef:
56+
oneOf:
57+
- type: string
58+
- $ref: '#/components/schemas/EntryObject'
59+
EntryObject:
60+
title: EntryObject
61+
type: object
62+
properties:
63+
id:
64+
type: string

‎docs/src/page-data/tests.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ advanced:
158158
title: Composite Schemas with Custom Tab Titles
159159
validates:
160160
- Rendering designated sub-schema titles on polymorphic tab selectors
161+
- oneof-duplicate-examples:
162+
title: Polymorphic oneOf with Nested oneOf Example Deduplication
163+
validates:
164+
- Request body EXAMPLE dropdown displays each top-level variant exactly once
165+
- Nested oneOf in sub-properties do not create duplicate parent variant dropdown entries
166+
- Clean polymorphic schema example generation with discriminator mapping
161167
- request-header-as-object:
162168
title: Serialized JSON Object in HTTP Request Headers
163169
validates:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
import ExampleLayout from '../../layouts/ExampleLayout.astro';
3+
import { getSpecUrl } from '../../utils/getSpecUrl';
4+
5+
const specUrl = getSpecUrl(Astro.url);
6+
---
7+
8+
<ExampleLayout>
9+
<rapi-doc
10+
id="thedoc"
11+
spec-url="/specs-test/oneof-duplicate-examples.yaml"
12+
default-schema-tab="example"
13+
render-style="read"
14+
show-header="false"
15+
allow-authentication="false"
16+
allow-server-selection="false"
17+
>
18+
<div slot="nav-logo" style="display:flex; flex-direction:row; align-items:center; justify-content: center;">
19+
<button class='btn' onclick="toggleSchemaStyle()">Toggle Schema Style</button>
20+
</div>
21+
</rapi-doc>
22+
</ExampleLayout>

‎packages/rapidoc/dist/rapidoc-min.js‎

Lines changed: 4877 additions & 233 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)