mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-12 05:48:57 +00:00
Use default value if string/number/boolean in generateSchemaExample (#3234)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@gitbook/react-openapi': patch
|
||||
---
|
||||
|
||||
Use default value if string number or boolean in generateSchemaExample
|
||||
@@ -204,6 +204,14 @@ const getExampleFromSchema = (
|
||||
return cache(schema, schema.example);
|
||||
}
|
||||
|
||||
// Use a default value, if there’s one and it’s a string or number
|
||||
if (
|
||||
schema.default !== undefined &&
|
||||
['string', 'number', 'boolean'].includes(typeof schema.default)
|
||||
) {
|
||||
return cache(schema, schema.default);
|
||||
}
|
||||
|
||||
// enum: [ 'available', 'pending', 'sold' ]
|
||||
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
||||
return cache(schema, schema.enum[0]);
|
||||
|
||||
Reference in New Issue
Block a user