Skip to content

Commit 31d36c1

Browse files
authored
Avoid falling back to MOD label when rendering oneOf/anyOf and title not defined (#455)
* Add preprocessing step to inject title attribute to component schema if none exists * Add CloudAccounts for testing * Remove CloudAccounts from demo * Remove title attribute from components schemas * Revert back to petstore
1 parent d9429c7 commit 31d36c1

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

demo/examples/petstore.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ components:
933933
message:
934934
type: string
935935
Cat:
936-
title: cat
937936
description: A representation of a cat
938937
allOf:
939938
- $ref: "#/components/schemas/Pet"
@@ -972,7 +971,6 @@ components:
972971
xml:
973972
name: Category
974973
Dog:
975-
title: dog
976974
description: A representation of a dog
977975
allOf:
978976
- $ref: "#/components/schemas/Pet"
@@ -987,7 +985,6 @@ components:
987985
required:
988986
- packSize
989987
HoneyBee:
990-
title: bee
991988
description: A representation of a honey bee
992989
allOf:
993990
- $ref: "#/components/schemas/Pet"
@@ -1043,7 +1040,6 @@ components:
10431040
xml:
10441041
name: Order
10451042
Pet:
1046-
title: pet
10471043
type: object
10481044
required:
10491045
- name
@@ -1110,7 +1106,6 @@ components:
11101106
xml:
11111107
name: Pet
11121108
Tag:
1113-
title: tag
11141109
type: object
11151110
properties:
11161111
id:

packages/docusaurus-plugin-openapi-docs/src/openapi/utils/loadAndResolveSpec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ export async function loadAndResolveSpec(specUrlOrObject: object | string) {
128128
const {
129129
bundle: { parsed },
130130
} = await bundle(bundleOpts);
131+
132+
//Pre-processing before resolving JSON refs
133+
if (parsed.components) {
134+
for (let [component, type] of Object.entries(parsed.components) as any) {
135+
if (component === "schemas") {
136+
for (let [schemaKey, schemaValue] of Object.entries(type) as any) {
137+
const title: string | undefined = schemaValue["title"];
138+
if (!title) {
139+
schemaValue.title = schemaKey;
140+
}
141+
}
142+
}
143+
}
144+
}
145+
131146
const resolved = await resolveJsonRefs(parsed);
132147

133148
// Force serialization and replace circular $ref pointers

0 commit comments

Comments
 (0)