mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Fix switcher default value being ignored
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
Fix switcher default value being ignored
|
||||
@@ -1235,6 +1235,36 @@
|
||||
"trialEnds": "2023-06-16T17:16:37.161Z"
|
||||
}
|
||||
},
|
||||
"parameters": {
|
||||
"type": "object",
|
||||
"required": ["media_input"],
|
||||
"properties": {
|
||||
"media_input": {
|
||||
"oneOf": [
|
||||
{
|
||||
"title": "Image Media",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": {
|
||||
"type": "string",
|
||||
"const": "image"
|
||||
},
|
||||
"url": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": ["type", "url"],
|
||||
"examples": [
|
||||
{
|
||||
"type": "image",
|
||||
"url": "https://example.com/image.png"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"roles": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
|
||||
@@ -171,12 +171,20 @@ function convertValue(
|
||||
}
|
||||
|
||||
if (schema.type === 'switcher') {
|
||||
const schema = resolve(
|
||||
getDynamicFieldSchema(fieldName, dynamicFields),
|
||||
return convertValue(
|
||||
fieldName,
|
||||
value,
|
||||
resolve(
|
||||
getDynamicFieldSchema(
|
||||
fieldName,
|
||||
dynamicFields,
|
||||
Object.values(schema.items).at(0),
|
||||
),
|
||||
references,
|
||||
),
|
||||
references,
|
||||
dynamicFields,
|
||||
);
|
||||
|
||||
return convertValue(fieldName, value, schema, references, dynamicFields);
|
||||
}
|
||||
|
||||
if (typeof value === 'object' && schema.type === 'object') {
|
||||
@@ -231,10 +239,12 @@ function convertValue(
|
||||
function getDynamicFieldSchema(
|
||||
name: string,
|
||||
dynamicFields: Map<string, DynamicField>,
|
||||
defaultValue?: RequestSchema | ReferenceSchema,
|
||||
): RequestSchema | ReferenceSchema {
|
||||
const field = dynamicFields.get(name);
|
||||
|
||||
return field?.type === 'field'
|
||||
? field.schema
|
||||
: { type: 'null', isRequired: false };
|
||||
if (field?.type === 'field') return field.schema;
|
||||
if (defaultValue) return defaultValue;
|
||||
|
||||
return { type: 'null', isRequired: false };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user