mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-22 02:23:30 +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);
|
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' ]
|
// enum: [ 'available', 'pending', 'sold' ]
|
||||||
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
if (Array.isArray(schema.enum) && schema.enum.length > 0) {
|
||||||
return cache(schema, schema.enum[0]);
|
return cache(schema, schema.enum[0]);
|
||||||
|
|||||||
Reference in New Issue
Block a user