Skip to content

Commit c6637b0

Browse files
authored
Use default value if string/number/boolean in generateSchemaExample (#3234)
1 parent 778624a commit c6637b0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

.changeset/ten-apples-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@gitbook/react-openapi': patch
3+
---
4+
5+
Use default value if string number or boolean in generateSchemaExample

packages/react-openapi/src/generateSchemaExample.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ const getExampleFromSchema = (
204204
return cache(schema, schema.example);
205205
}
206206

207+
// Use a default value, if there’s one and it’s a string or number
208+
if (
209+
schema.default !== undefined &&
210+
['string', 'number', 'boolean'].includes(typeof schema.default)
211+
) {
212+
return cache(schema, schema.default);
213+
}
214+
207215
// enum: [ 'available', 'pending', 'sold' ]
208216
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
209217
return cache(schema, schema.enum[0]);

0 commit comments

Comments
 (0)