Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix example usage by inline array properties. fix #266 #267

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading