Skip to content

Commit bb6916c

Browse files
committed
Handle circular refs anywhere in allOf
1 parent a9ebe39 commit bb6916c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

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

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

785785
if (schema.allOf !== undefined) {
786-
if (
787-
schema.allOf.length &&
788-
typeof schema.allOf[0] === "string" &&
789-
(schema.allOf[0] as string).includes("circular")
790-
) {
786+
const circularIndex = schema.allOf.findIndex((item: any) => {
787+
return typeof item === "string" && item.includes("circular");
788+
});
789+
790+
if (circularIndex !== -1) {
791791
nodes.push(
792792
create("div", {
793793
style: {
794794
marginTop: ".5rem",
795795
marginBottom: ".5rem",
796796
marginLeft: "1rem",
797797
},
798-
children: createDescription(schema.allOf[0]),
798+
children: createDescription(schema.allOf[circularIndex] as string),
799799
})
800800
);
801801

802-
const rest = schema.allOf.slice(1);
802+
const rest = schema.allOf
803+
.slice(0, circularIndex)
804+
.concat(schema.allOf.slice(circularIndex + 1));
805+
803806
if (rest.length) {
804807
const mergedSchemas = mergeAllOf({ allOf: rest } as SchemaObject);
805808
if (

0 commit comments

Comments
 (0)