Skip to content

Commit 42e6a4f

Browse files
committed
Handle multiple circular refs in allOf
1 parent 19fec96 commit 42e6a4f

File tree

2 files changed

+10
-77
lines changed

2 files changed

+10
-77
lines changed

packages/docusaurus-plugin-openapi-docs/src/markdown/__snapshots__/createSchema.test.ts.snap

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -364,24 +364,6 @@ Array [
364364
qualifierMessage={undefined}
365365
schema={{ type: \\"string\\" }}
366366
></SchemaItem>;
367-
",
368-
"<SchemaItem
369-
collapsible={false}
370-
name={\\"parentProp1\\"}
371-
required={false}
372-
schemaName={\\"string\\"}
373-
qualifierMessage={undefined}
374-
schema={{ type: \\"string\\" }}
375-
></SchemaItem>;
376-
",
377-
"<SchemaItem
378-
collapsible={false}
379-
name={\\"parentProp2\\"}
380-
required={false}
381-
schemaName={\\"string\\"}
382-
qualifierMessage={undefined}
383-
schema={{ type: \\"string\\" }}
384-
></SchemaItem>;
385367
",
386368
]
387369
`;
@@ -729,15 +711,6 @@ Array [
729711
qualifierMessage={undefined}
730712
schema={{ type: \\"string\\" }}
731713
></SchemaItem>;
732-
",
733-
"<SchemaItem
734-
collapsible={false}
735-
name={\\"type\\"}
736-
required={false}
737-
schemaName={\\"string\\"}
738-
qualifierMessage={undefined}
739-
schema={{ type: \\"string\\" }}
740-
></SchemaItem>;
741714
",
742715
]
743716
`;
@@ -824,34 +797,6 @@ Array [
824797
qualifierMessage={undefined}
825798
schema={{ type: \\"string\\" }}
826799
></SchemaItem>;
827-
",
828-
"<div className={\\"openapi-discriminator__item openapi-schema__list-item\\"}>
829-
<div>
830-
<span className={\\"openapi-schema__container\\"}>
831-
<strong
832-
className={\\"openapi-discriminator__name openapi-schema__property\\"}
833-
>
834-
type
835-
</strong>
836-
<span className={\\"openapi-schema__name\\"}>string</span>
837-
</span>
838-
<div style={{ paddingLeft: \\"1rem\\" }}>
839-
**Possible values:** [\`typeA\`, \`typeB\`]
840-
</div>
841-
<DiscriminatorTabs className={\\"openapi-tabs__discriminator\\"}>
842-
<TabItem label={\\"typeA\\"} value={\\"0-item-discriminator\\"}>
843-
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
844-
#/definitions/TypeA
845-
</div>
846-
</TabItem>
847-
<TabItem label={\\"typeB\\"} value={\\"1-item-discriminator\\"}>
848-
<div style={{ marginTop: \\".5rem\\", marginBottom: \\".5rem\\" }}>
849-
#/definitions/TypeB
850-
</div>
851-
</TabItem>
852-
</DiscriminatorTabs>
853-
</div>
854-
</div>;
855800
",
856801
]
857802
`;

packages/docusaurus-plugin-openapi-docs/src/markdown/createSchema.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -783,41 +783,29 @@ export function createNodes(
783783
}
784784

785785
if (schema.allOf !== undefined) {
786-
const circularIndex = schema.allOf.findIndex((item: any) => {
786+
const circularItems = schema.allOf.filter((item: any) => {
787787
return typeof item === "string" && item.includes("circular");
788788
});
789789

790-
if (circularIndex !== -1) {
790+
for (const label of circularItems) {
791791
nodes.push(
792792
create("div", {
793793
style: {
794794
marginTop: ".5rem",
795795
marginBottom: ".5rem",
796796
marginLeft: "1rem",
797797
},
798-
children: createDescription(schema.allOf[circularIndex] as string),
798+
children: createDescription(label as string),
799799
})
800800
);
801+
}
801802

802-
const rest = schema.allOf
803-
.slice(0, circularIndex)
804-
.concat(schema.allOf.slice(circularIndex + 1));
805-
806-
if (rest.length) {
807-
const mergedSchemas = mergeAllOf({ allOf: rest } as SchemaObject);
808-
if (
809-
mergedSchemas.oneOf !== undefined ||
810-
mergedSchemas.anyOf !== undefined
811-
) {
812-
nodes.push(createAnyOneOf(mergedSchemas));
813-
}
814-
815-
if (mergedSchemas.properties !== undefined) {
816-
nodes.push(createProperties(mergedSchemas));
817-
}
818-
}
819-
} else {
820-
const mergedSchemas = mergeAllOf(schema) as SchemaObject;
803+
const rest = schema.allOf.filter((item: any) => {
804+
return !(typeof item === "string" && item.includes("circular"));
805+
});
806+
807+
if (rest.length) {
808+
const mergedSchemas = mergeAllOf({ allOf: rest } as SchemaObject);
821809

822810
if (
823811
mergedSchemas.oneOf !== undefined ||

0 commit comments

Comments
 (0)