Use default value if string/number/boolean in generateSchemaExample (#3234)

This commit is contained in:
Nolann B.
2025-05-13 22:07:41 +02:00
committed by GitHub
parent 778624af00
commit c6637b09e2
2 changed files with 13 additions and 0 deletions
+5
View File
@@ -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 theres one and its 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]);