Skip to content

Commit af8942b

Browse files
committed
Missing top-level required OpenAPI alternatives
1 parent 5a69692 commit af8942b

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

.changeset/shy-plums-deny.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Missing top-level required OpenAPI alternatives

packages/react-openapi/src/OpenAPISchema.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ export function getSchemaAlternatives(
482482
const [type, schemas] = alternatives;
483483
return mergeAlternatives(
484484
type,
485-
flattenAlternatives(type, schemas, new Set(ancestors).add(schema))
485+
flattenAlternatives(type, schemas, new Set(ancestors).add(schema)),
486+
schema.required ?? []
486487
);
487488
}
488489

@@ -492,7 +493,8 @@ export function getSchemaAlternatives(
492493
*/
493494
function mergeAlternatives(
494495
alternativeType: AlternativeType,
495-
schemasOrRefs: OpenAPIV3.SchemaObject[]
496+
schemasOrRefs: OpenAPIV3.SchemaObject[],
497+
parentRequired?: string[]
496498
): OpenAPIV3.SchemaObject[] | null {
497499
switch (alternativeType) {
498500
case 'oneOf': {
@@ -547,6 +549,7 @@ function mergeAlternatives(
547549
};
548550
latest.required = Array.from(
549551
new Set([
552+
...(Array.isArray(parentRequired) ? parentRequired : []),
550553
...(Array.isArray(latest.required) ? latest.required : []),
551554
...(Array.isArray(schemaOrRef.required)
552555
? schemaOrRef.required

0 commit comments

Comments
 (0)