Skip to content

Commit f61fc5e

Browse files
sserratajwulf
andauthored
feat: display format for oneOf primitive arms (#1268)
* feat: display format for oneOf primitive arms Uses getSchemaName() to properly display format information (e.g., 'string<date-time>') for primitive arms in oneOf/anyOf schemas, instead of just showing the raw type ('string'). Closes #1230 Co-authored-by: Josh Wulf <[email protected]> * test: add oneOf primitive format types example Adds test case for oneOf schemas with primitive types that have format specifiers (e.g., string with date-time, email, integer with int64). This verifies the fix displays 'string<date-time>' instead of just 'string'. --------- Co-authored-by: Josh Wulf <[email protected]>
1 parent 0726d80 commit f61fc5e

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

demo/examples/tests/oneOf.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,46 @@ paths:
3939
- type: boolean
4040
- type: "null"
4141

42+
/oneof-primitive-formats:
43+
get:
44+
tags:
45+
- oneOf
46+
summary: oneOf with Primitive Format Types
47+
description: |
48+
Primitive types with format should display as `type<format>` (e.g., `string<date-time>`).
49+
50+
Schema:
51+
```yaml
52+
type: object
53+
properties:
54+
oneOfProperty:
55+
oneOf:
56+
- type: string
57+
format: date-time
58+
- type: string
59+
format: email
60+
- type: integer
61+
format: int64
62+
- type: string
63+
```
64+
responses:
65+
"200":
66+
description: Successful response
67+
content:
68+
application/json:
69+
schema:
70+
type: object
71+
properties:
72+
oneOfProperty:
73+
oneOf:
74+
- type: string
75+
format: date-time
76+
- type: string
77+
format: email
78+
- type: integer
79+
format: int64
80+
- type: string
81+
4282
/oneof-complex-types:
4383
get:
4484
tags:

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,13 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
145145
</span>
146146
<SchemaTabs groupId={`schema-${uniqueId}`} lazy>
147147
{schema[key]?.map((anyOneSchema: any, index: number) => {
148+
// Use getSchemaName to include format info (e.g., "string<date-time>")
149+
const computedSchemaName = getSchemaName(anyOneSchema);
150+
148151
// Determine label for the tab
149-
// If schema is just oneOf/anyOf without title/type, use a generic label
150-
let label = anyOneSchema.title || anyOneSchema.type;
152+
// Prefer explicit title, then computed schema name, then raw type
153+
let label =
154+
anyOneSchema.title || computedSchemaName || anyOneSchema.type;
151155
if (!label) {
152156
if (anyOneSchema.oneOf) {
153157
label = translate({
@@ -175,7 +179,7 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
175179
<SchemaItem
176180
collapsible={false}
177181
name={undefined}
178-
schemaName={anyOneSchema.type}
182+
schemaName={computedSchemaName}
179183
qualifierMessage={getQualifierMessage(anyOneSchema)}
180184
schema={anyOneSchema}
181185
discriminator={false}
@@ -192,7 +196,7 @@ const AnyOneOf: React.FC<SchemaProps> = ({ schema, schemaType }) => {
192196
<SchemaItem
193197
collapsible={false}
194198
name={undefined}
195-
schemaName={anyOneSchema.type}
199+
schemaName={computedSchemaName}
196200
qualifierMessage={getQualifierMessage(anyOneSchema)}
197201
schema={anyOneSchema}
198202
discriminator={false}

0 commit comments

Comments
 (0)