Skip to content

Commit 58cfd94

Browse files
committed
feat: Add new endpoints for allOf with nested array items and properties in OpenAPI schema
1 parent 16cc743 commit 58cfd94

3 files changed

Lines changed: 130 additions & 13 deletions

File tree

demo/examples/tests/allOf.yaml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,98 @@ paths:
367367
otherOuterProp:
368368
type: string
369369

370+
/allof-nested-array-items:
371+
get:
372+
tags:
373+
- allOf
374+
summary: allOf with Nested Array Items
375+
description: |
376+
A list of books demonstrating allOf with nested items as children.
377+
378+
Schema:
379+
```yaml
380+
type: array
381+
items:
382+
type: object
383+
properties:
384+
books:
385+
type: array
386+
items:
387+
$ref: '#/components/schemas/Book'
388+
pagination:
389+
type: object
390+
properties:
391+
page_number:
392+
type: integer
393+
page_size:
394+
type: integer
395+
```
396+
responses:
397+
"200":
398+
description: A list of books with pagination
399+
content:
400+
application/json:
401+
schema:
402+
type: object
403+
properties:
404+
books:
405+
type: array
406+
items:
407+
$ref: "#/components/schemas/Book"
408+
pagination:
409+
type: object
410+
properties:
411+
page_number:
412+
type: integer
413+
page_size:
414+
type: integer
415+
416+
/allof-nested-array-with-properties:
417+
get:
418+
tags:
419+
- allOf
420+
summary: allOf in Nested Array with Properties
421+
description: |
422+
A list of books demonstrating allOf with nested array with properties.
423+
424+
Schema:
425+
```yaml
426+
type: array
427+
items:
428+
type: object
429+
properties:
430+
books:
431+
type: array
432+
items:
433+
$ref: '#/components/schemas/CategorizedBook'
434+
pagination:
435+
type: object
436+
properties:
437+
page_number:
438+
type: integer
439+
page_size:
440+
type: integer
441+
```
442+
responses:
443+
"200":
444+
description: A list of books
445+
content:
446+
application/json:
447+
schema:
448+
type: object
449+
properties:
450+
books:
451+
type: array
452+
items:
453+
$ref: "#/components/schemas/CategorizedBook"
454+
pagination:
455+
type: object
456+
properties:
457+
page_number:
458+
type: integer
459+
page_size:
460+
type: integer
461+
370462
components:
371463
schemas:
372464
# Your existing schemas are integrated here.

packages/docusaurus-theme-openapi-docs/lib/theme/Schema/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,16 @@ const SchemaEdge = ({ name, schema, required, discriminator, schemaType }) => {
625625
schemaType: schemaType,
626626
});
627627
}
628+
if (schema.items?.allOf) {
629+
return react_1.default.createElement(SchemaNodeDetails, {
630+
name: name,
631+
schemaName: schemaName,
632+
required: required,
633+
nullable: schema.nullable,
634+
schema: schema,
635+
schemaType: schemaType,
636+
});
637+
}
628638
if (schema.allOf) {
629639
// handle circular properties
630640
if (
@@ -677,7 +687,7 @@ const SchemaEdge = ({ name, schema, required, discriminator, schemaType }) => {
677687
});
678688
}
679689
if (mergedSchemas.items?.properties) {
680-
react_1.default.createElement(SchemaNodeDetails, {
690+
return react_1.default.createElement(SchemaNodeDetails, {
681691
name: name,
682692
schemaName: mergedSchemaName,
683693
required: Array.isArray(mergedSchemas.required)

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

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,19 @@ const SchemaEdge: React.FC<SchemaEdgeProps> = ({
685685
);
686686
}
687687

688+
if (schema.items?.allOf) {
689+
return (
690+
<SchemaNodeDetails
691+
name={name}
692+
schemaName={schemaName}
693+
required={required}
694+
nullable={schema.nullable}
695+
schema={schema}
696+
schemaType={schemaType}
697+
/>
698+
);
699+
}
700+
688701
if (schema.allOf) {
689702
// handle circular properties
690703
if (
@@ -754,18 +767,20 @@ const SchemaEdge: React.FC<SchemaEdgeProps> = ({
754767
}
755768

756769
if (mergedSchemas.items?.properties) {
757-
<SchemaNodeDetails
758-
name={name}
759-
schemaName={mergedSchemaName}
760-
required={
761-
Array.isArray(mergedSchemas.required)
762-
? mergedSchemas.required.includes(name)
763-
: mergedSchemas.required
764-
}
765-
nullable={mergedSchemas.nullable}
766-
schema={mergedSchemas}
767-
schemaType={schemaType}
768-
/>;
770+
return (
771+
<SchemaNodeDetails
772+
name={name}
773+
schemaName={mergedSchemaName}
774+
required={
775+
Array.isArray(mergedSchemas.required)
776+
? mergedSchemas.required.includes(name)
777+
: mergedSchemas.required
778+
}
779+
nullable={mergedSchemas.nullable}
780+
schema={mergedSchemas}
781+
schemaType={schemaType}
782+
/>
783+
);
769784
}
770785

771786
return (

0 commit comments

Comments
 (0)