From 31f6ef9c5d21fd9383856b20e0f6f97ac64f4799 Mon Sep 17 00:00:00 2001 From: Warren Parad Date: Fri, 18 Oct 2024 00:55:32 +0200 Subject: [PATCH] Fix example usage by inline array properties. fix #266 --- src/utils/schema-utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils/schema-utils.js b/src/utils/schema-utils.js index 05d5ebcb..4462b130 100644 --- a/src/utils/schema-utils.js +++ b/src/utils/schema-utils.js @@ -104,10 +104,7 @@ export function getTypeInfo(parameter, options = { includeNulls: false, enableEx } export function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleIds) { - const example = Array.isArray(schemaObj.examples) ? schemaObj.examples[0] : Object.values(schemaObj.examples || {})[0]?.value ?? schemaObj.example; const propertyName = fallbackPropertyName || 'string'; - if (skipExampleIds && typeof example === 'string' && propertyName.match(/id$/i)) { return ''; } - if (typeof example !== 'undefined') { return example; } if (schemaObj.default) { return schemaObj.default; } @@ -251,6 +248,13 @@ function getExampleValuesFromSchemaRecursive(rawSchema, config = {}) { } function getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes, xmlTagProperties, overridePropertyName) { + const examples = Array.isArray(schema.examples) && schema.examples + || schema.examples && typeof schema.examples === 'object' && Object.values(schema.examples).map(e => e.value).filter(v => v) + || schema.example && [schema.example] + || []; + if (config.skipExampleIds && config.propertyName && config.propertyName.match(/id$/i)) { return ['']; } + if (examples.length) { return examples; } + if (schema.type === 'array' || schema.items) { if (!config.xml) { return [getExampleValuesFromSchemaRecursive(schema.items || {}, config)];