Skip to content

Commit 084cf87

Browse files
committed
fix: primitive
1 parent afaa92a commit 084cf87

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

packages/docusaurus-plugin-openapi-docs/src/openapi/createSchemaExample.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,27 @@ function primitive(schema: SchemaObject = {}) {
234234
return;
235235
}
236236

237-
let fn = schema.default ? () => schema.default : primitives[type].default;
237+
// If type is an array, use the first type
238+
if (Array.isArray(type)) {
239+
type = type[0];
240+
if (type === undefined) {
241+
return;
242+
}
243+
}
238244

239-
if (format !== undefined) {
240-
fn = primitives[type][format] || fn;
245+
// Use schema default if available, otherwise use type default
246+
if (schema.default !== undefined) {
247+
return schema.default;
241248
}
242249

243-
if (fn) {
244-
return fn(schema);
250+
const typeConfig = primitives[type];
251+
if (typeConfig) {
252+
if (format !== undefined && typeConfig[format] !== undefined) {
253+
return typeConfig[format](schema);
254+
}
255+
if (typeConfig.default !== undefined) {
256+
return typeConfig.default(schema);
257+
}
245258
}
246259

247260
return "Unknown Type: " + schema.type;

0 commit comments

Comments
 (0)