Skip to content

Commit faa8368

Browse files
authored
[W-11858334] Missing array properties (#59)
* feat(PropertyRangeDocument): missing minCount and maxCount for arrays * build: bump version
1 parent b6a0446 commit faa8368

File tree

7 files changed

+100
-4
lines changed

7 files changed

+100
-4
lines changed

demo/W-11858334/W-11858334.raml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#%RAML 1.0
2+
3+
title: W-11858334
4+
5+
types:
6+
testType:
7+
properties:
8+
country:
9+
type: string
10+
required: true
11+
displayName: "Country"
12+
skuList:
13+
type: string[]
14+
minItems: 3
15+
maxItems: 10
16+
required: true
17+
18+
/test:
19+
get:
20+
body:
21+
application/json:
22+
type: testType

demo/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"enum-test/enum-test.raml": "RAML 1.0",
1515
"APIC-667/APIC-667.raml": "RAML 1.0",
1616
"array-type/array-type.raml": "RAML 1.0",
17+
"W-11858334/W-11858334.raml": "RAML 1.0",
1718
"APIC-429/APIC-429.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1819
"SE-17897/SE-17897.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1920
"new-oas3-types/new-oas3-types.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },

demo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ class ApiDemo extends ApiDemoPage {
113113
['new-oas3-types', 'New OAS 3 types API'],
114114
['APIC-483', 'APIC 483'],
115115
['array-type', 'array-type'],
116+
['W-11858334', 'W-11858334'],
116117
].map(
117118
([file, label]) => html` <anypoint-item data-src="${file}-compact.json"
118119
>${label} - compact model</anypoint-item

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-type-document",
33
"description": "A documentation table for type (resource) properties. Works with AMF data model",
4-
"version": "4.2.18",
4+
"version": "4.2.19",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/PropertyRangeDocument.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,25 @@ export class PropertyRangeDocument extends PropertyDocumentMixin(LitElement) {
303303
</div>`;
304304
}
305305

306+
_arrayPropertiesTemplate() {
307+
const { range } = this;
308+
309+
return html` ${this._hasProperty(range, this.ns.w3.shacl.minCount)
310+
? this._listItemTemplate(
311+
'Minimum array length',
312+
'Minimum amount of items in array',
313+
this.ns.w3.shacl.minCount
314+
)
315+
: ''}
316+
${this._hasProperty(range, this.ns.w3.shacl.maxCount)
317+
? this._listItemTemplate(
318+
'Maximum array length',
319+
'Maximum amount of items in array',
320+
this.ns.w3.shacl.maxCount
321+
)
322+
: ''}`;
323+
}
324+
306325
/**
307326
* @return {TemplateResult|string} Template for the element.
308327
*/
@@ -355,6 +374,7 @@ export class PropertyRangeDocument extends PropertyDocumentMixin(LitElement) {
355374
? this._filePropertiesTemplate()
356375
: this._nonFilePropertiesTemplate()}
357376
${this.isEnum ? this._enumTemplate() : ''}
377+
${this.isArray ? this._arrayPropertiesTemplate() : ''}
358378
359379
<section class="examples" ?hidden="${!this._hasExamples}">
360380
<api-resource-example-document

test/property-range-document.test.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ describe('PropertyRangeDocument', () => {
1616
return /** @type PropertyRangeDocument */ (elm);
1717
}
1818

19-
function findTypePropertyRange(element, type, index = 0) {
19+
function findTypePropertyRange(element, type, index = 0, propIndex = 0) {
2020
type = element._resolve(type);
2121
const props = element._computeObjectProperties(type);
2222
const key = element._getAmfKey(element.ns.aml.vocabularies.shapes.range);
23-
return element._ensureArray(props[0][key])[index];
23+
return element._ensureArray(props[propIndex][key])[index];
2424
}
2525

2626
async function getTypePropertyRange(
@@ -252,6 +252,58 @@ describe('PropertyRangeDocument', () => {
252252
});
253253
});
254254

255+
describe('Array data rendering', () => {
256+
[
257+
['Regular model', false],
258+
['Compact model', true],
259+
].forEach((item) => {
260+
describe(String(item[0]), () => {
261+
let element;
262+
let amf;
263+
let type;
264+
265+
before(async () => {
266+
const data = await AmfLoader.loadType('testType', item[1], 'W-11858334');
267+
amf = data[0];
268+
type = data[1];
269+
});
270+
271+
beforeEach(async () => {
272+
element = await basicFixture();
273+
element.amf = amf;
274+
element.range = findTypePropertyRange(element, type, 0, 1);
275+
await aTimeout(0);
276+
});
277+
278+
it('Renders array minimum count', async () => {
279+
const properties = element.shadowRoot.querySelectorAll('.property-attribute');
280+
assert.lengthOf(properties, 2);
281+
282+
const minProperty = properties[0]
283+
const label = minProperty.querySelector('.attribute-label');
284+
assert.equal(label.innerText, 'Minimum array length:');
285+
286+
const value = minProperty.querySelector('.attribute-value');
287+
assert.equal(value.title, 'Minimum amount of items in array');
288+
assert.equal(value.innerText.trim().toLowerCase(), '3');
289+
});
290+
291+
it('Renders array maximum count', async () => {
292+
const properties = element.shadowRoot.querySelectorAll('.property-attribute');
293+
assert.lengthOf(properties, 2);
294+
295+
const maxProperty = properties[1]
296+
const label = maxProperty.querySelector('.attribute-label');
297+
assert.equal(label.innerText, 'Maximum array length:');
298+
299+
const value = maxProperty.querySelector('.attribute-value');
300+
assert.equal(value.title, 'Maximum amount of items in array');
301+
assert.equal(value.innerText.trim().toLowerCase(), '10');
302+
});
303+
});
304+
});
305+
});
306+
255307
describe('a11y', () => {
256308
let element;
257309

0 commit comments

Comments
 (0)