Skip to content

Commit c90cb3f

Browse files
authored
Merge pull request #267 from Authress-Engineering/fix-inline-array-examples
Fix example usage by inline array properties. fix #266
2 parents 7454a41 + 31f6ef9 commit c90cb3f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/utils/schema-utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ export function getTypeInfo(parameter, options = { includeNulls: false, enableEx
104104
}
105105

106106
export function getSampleValueByType(schemaObj, fallbackPropertyName, skipExampleIds) {
107-
const example = Array.isArray(schemaObj.examples) ? schemaObj.examples[0] : Object.values(schemaObj.examples || {})[0]?.value ?? schemaObj.example;
108107
const propertyName = fallbackPropertyName || 'string';
109-
if (skipExampleIds && typeof example === 'string' && propertyName.match(/id$/i)) { return ''; }
110-
if (typeof example !== 'undefined') { return example; }
111108

112109
if (schemaObj.default) { return schemaObj.default; }
113110

@@ -251,6 +248,13 @@ function getExampleValuesFromSchemaRecursive(rawSchema, config = {}) {
251248
}
252249

253250
function getSimpleValueResult(schema, config, namespace, prefix, xmlAttributes, xmlTagProperties, overridePropertyName) {
251+
const examples = Array.isArray(schema.examples) && schema.examples
252+
|| schema.examples && typeof schema.examples === 'object' && Object.values(schema.examples).map(e => e.value).filter(v => v)
253+
|| schema.example && [schema.example]
254+
|| [];
255+
if (config.skipExampleIds && config.propertyName && config.propertyName.match(/id$/i)) { return ['']; }
256+
if (examples.length) { return examples; }
257+
254258
if (schema.type === 'array' || schema.items) {
255259
if (!config.xml) {
256260
return [getExampleValuesFromSchemaRecursive(schema.items || {}, config)];

0 commit comments

Comments
 (0)