Skip to content

Commit 5353991

Browse files
committed
feat: display format for oneOf primitive arms
1 parent b0d2b7d commit 5353991

File tree

1 file changed

+31
-25
lines changed
  • packages/docusaurus-theme-openapi-docs/src/theme/Schema

1 file changed

+31
-25
lines changed

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

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -129,55 +129,61 @@ interface SchemaProps {
129129

130130
const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
131131
const key = schema.oneOf ? "oneOf" : "anyOf";
132-
const type = schema.oneOf
132+
const groupLabel = schema.oneOf
133133
? translate({ id: OPENAPI_SCHEMA_ITEM.ONE_OF, message: "oneOf" })
134134
: translate({ id: OPENAPI_SCHEMA_ITEM.ANY_OF, message: "anyOf" });
135+
135136
return (
136137
<>
137138
<span className="badge badge--info" style={{ marginBottom: "1rem" }}>
138-
{type}
139+
{groupLabel}
139140
</span>
140141
<SchemaTabs>
141142
{schema[key]?.map((anyOneSchema: any, index: number) => {
142-
const label = anyOneSchema.title || anyOneSchema.type;
143+
// Prefer explicit title, then inferred name, then raw type, finally fallback MOD{n}
144+
const computedSchemaName = getSchemaName(anyOneSchema);
145+
const label =
146+
anyOneSchema.title ||
147+
computedSchemaName ||
148+
anyOneSchema.type ||
149+
`MOD${index + 1}`;
150+
const isPrimitiveArm =
151+
isPrimitive(anyOneSchema) || anyOneSchema.const;
152+
const emptyObjectPrimitive =
153+
anyOneSchema.type === "object" &&
154+
!anyOneSchema.properties &&
155+
!anyOneSchema.allOf &&
156+
!anyOneSchema.oneOf &&
157+
!anyOneSchema.anyOf;
143158
return (
144159
// @ts-ignore
145160
<TabItem
146161
key={index}
147162
label={label}
148163
value={`${index}-item-properties`}
149164
>
150-
{/* Handle primitive types directly */}
151-
{(isPrimitive(anyOneSchema) || anyOneSchema.const) && (
165+
{isPrimitiveArm && (
152166
<SchemaItem
153167
collapsible={false}
154168
name={undefined}
155-
schemaName={anyOneSchema.type}
169+
schemaName={computedSchemaName}
170+
qualifierMessage={getQualifierMessage(anyOneSchema)}
171+
schema={anyOneSchema}
172+
discriminator={false}
173+
children={null}
174+
/>
175+
)}
176+
{emptyObjectPrimitive && (
177+
<SchemaItem
178+
collapsible={false}
179+
name={undefined}
180+
schemaName={computedSchemaName}
156181
qualifierMessage={getQualifierMessage(anyOneSchema)}
157182
schema={anyOneSchema}
158183
discriminator={false}
159184
children={null}
160185
/>
161186
)}
162-
163-
{/* Handle empty object as a primitive type */}
164-
{anyOneSchema.type === "object" &&
165-
!anyOneSchema.properties &&
166-
!anyOneSchema.allOf &&
167-
!anyOneSchema.oneOf &&
168-
!anyOneSchema.anyOf && (
169-
<SchemaItem
170-
collapsible={false}
171-
name={undefined}
172-
schemaName={anyOneSchema.type}
173-
qualifierMessage={getQualifierMessage(anyOneSchema)}
174-
schema={anyOneSchema}
175-
discriminator={false}
176-
children={null}
177-
/>
178-
)}
179-
180-
{/* Handle actual object types with properties or nested schemas */}
181187
{anyOneSchema.type === "object" && anyOneSchema.properties && (
182188
<Properties schema={anyOneSchema} schemaType={schemaType} />
183189
)}

0 commit comments

Comments
 (0)