Skip to content

Commit

Permalink
Merge pull request #267 from Authress-Engineering/fix-inline-array-ex…
Browse files Browse the repository at this point in the history
…amples

Fix example usage by inline array properties. fix #266
  • Loading branch information
wparad authored Oct 17, 2024
2 parents 7454a41 + 31f6ef9 commit c90cb3f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/utils/schema-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down Expand Up @@ -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)];
Expand Down

0 comments on commit c90cb3f

Please sign in to comment.