Skip to content

Commit

Permalink
Prefer the array description to display when available over the items…
Browse files Browse the repository at this point in the history
… schema description. Fix #250.
  • Loading branch information
wparad committed May 15, 2024
1 parent 8c29fdf commit 5b81fc6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This package follows standard semvar, `<major>.<minor>.<build>`. No breaking cha
* Remove deprecated property `nav-item-spacing` in favor of css variable `--nav-path-padding`.
* Prevent making requests when required path parameters are not specified.
* Automatically retry fetching the spec if it doesn't work for any reason.
* Fix array description display preference to be first--The Array description, and then only second--The array item schema description, so that the "more specific" description wins, even though the "items" description is more deeply nested. This aligns to the expected behavior of preference in the json schema.

## 2.1
* Add `x-locale` vendor extension to specify the locale of the spec.
Expand Down
9 changes: 4 additions & 5 deletions src/utils/schema-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,12 @@ export function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '
} else if (v === 'array') {
multiTypeOptions[`::OPTION~${i + 1}`] = {
'::title': schema.title || '',
'::description': schema.description || '',
'::description': schema.description || arrayItemsSchema?.description || '',
'::flags': { '🆁': schema.readOnly && '🆁', '🆆': schema.writeOnly && '🆆' },
'::link': arrayItemsSchema.title || schema.title || '',
'::type': 'array',
// Array properties are read from the ::props object instead of reading from the keys of this object
// '::props': schemaInObjectNotation(Object.assign({ deprecated: schema.deprecated, readOnly: schema.readOnly, writeOnly: schema.writeOnly }, arrayItemsSchema), options, (level + 1)),
'::props': schemaInObjectNotation(Object.assign({}, schema, arrayItemsSchema), options, (level + 1)),
'::props': schemaInObjectNotation(Object.assign({}, schema, arrayItemsSchema, { description: schema.description || arrayItemsSchema?.description }), options, (level + 1)),
'::deprecated': schema.deprecated || false,
'::metadata': metadata
};
Expand Down Expand Up @@ -492,15 +491,15 @@ export function schemaInObjectNotation(rawSchema, options, level = 0, suffix = '
if (propertyType === 'array' || arrayItemsSchema) { // If Array
const obj = { '::type': '' };
obj['::title'] = schema.title || '';
obj['::description'] = schema.description || (arrayItemsSchema?.description ? `array&lt;${arrayItemsSchema.description}&gt;` : '');
obj['::description'] = schema.description || arrayItemsSchema?.description || '';
obj['::flags'] = { '🆁': schema.readOnly && '🆁', '🆆': schema.writeOnly && '🆆' };
obj['::link'] = arrayItemsSchema?.title || schema.title || '';
obj['::type'] = 'array';
obj['::deprecated'] = schema.deprecated || false;
obj['::metadata'] = metadata;
// Array properties are read from the ::props object instead of reading from the keys of this object
// Use type: undefined to prevent schema recursion by passing array from the parent to the next loop. arrayItemsSchema should have had type defined but it doesn't.
obj['::props'] = schemaInObjectNotation(Object.assign({}, schema, { type: undefined }, arrayItemsSchema), options, (level + 1));
obj['::props'] = schemaInObjectNotation(Object.assign({}, schema, { type: undefined }, arrayItemsSchema, { description: obj['::description'] }), options, (level + 1));
if (arrayItemsSchema?.items) {
obj['::array-type'] = arrayItemsSchema.items.type;
}
Expand Down

0 comments on commit 5b81fc6

Please sign in to comment.