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

Prefer the array description to display when available over the items schema description. Fix #250. #251

Merged
merged 1 commit into from
May 15, 2024
Merged
Show file tree
Hide file tree
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
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
Loading