Skip to content

Commit f15b874

Browse files
authored
Merge pull request #55 from advanced-rest-client/fix/W-11209734/missing-array-length
[W-11209734] Missing array length
2 parents db0b1eb + 3e97e8e commit f15b874

File tree

8 files changed

+95
-8
lines changed

8 files changed

+95
-8
lines changed

demo/apis.json

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

demo/array-type/array-type.raml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#%RAML 1.0
2+
title: 00193743
3+
4+
types:
5+
Email:
6+
type: object
7+
properties:
8+
name:
9+
type: string
10+
Emails:
11+
type: array
12+
items: Email
13+
minItems: 1
14+
maxItems: 3
15+
uniqueItems: true
16+
Other:
17+
type: string
18+
minLength: 2

demo/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class ApiDemo extends ApiDemoPage {
112112
['APIC-282', 'APIC-282'],
113113
['new-oas3-types', 'New OAS 3 types API'],
114114
['APIC-483', 'APIC 483'],
115+
['array-type', 'array-type'],
115116
].map(
116117
([file, label]) => html` <anypoint-item data-src="${file}-compact.json"
117118
>${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.17",
4+
"version": "4.2.18",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiTypeDocument.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,25 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
652652
);
653653
}
654654

655+
_arrayPropertyTemplate(label, value, title) {
656+
return html`
657+
<div class="property-attribute" part="property-attribute">
658+
<span class="attribute-label" part="attribute-label">${label}</span>
659+
<span class="attribute-value" part="attribute-value" title=${title}>${value}</span>
660+
</div>
661+
`
662+
}
663+
664+
_arrayPropertiesTemplate() {
665+
const minCount = this._getValue(this._resolvedType, this.ns.w3.shacl.minCount)
666+
const maxCount = this._getValue(this._resolvedType, this.ns.w3.shacl.maxCount)
667+
668+
return html`
669+
${minCount !== undefined ? this._arrayPropertyTemplate('Minimum array length:', minCount, 'Minimum amount of items in array') : ''}
670+
${maxCount !== undefined ? this._arrayPropertyTemplate('Maximum array length:', maxCount, 'Maximum amount of items in array') : ''}
671+
`
672+
}
673+
655674
/**
656675
* @return {TemplateResult} Templates for object properties
657676
*/
@@ -688,15 +707,19 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
688707
: ''}
689708
`
690709
);
691-
if (!this.hasParentType) {
692-
return html`
710+
711+
return html`
712+
${!this.hasParentType ?
713+
html`
693714
<span>Array of:</span>
694715
<div class="array-children">
695716
${documents}
696-
</div>
697-
`;
698-
}
699-
return html`${documents}`;
717+
</div>`
718+
: html`${documents}`
719+
}
720+
721+
${this._arrayPropertiesTemplate()}
722+
`;
700723
}
701724

702725
/**

src/TypeStyles.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,15 @@ export default css`
8585
.union-type-selector {
8686
margin: 12px 0;
8787
}
88+
89+
.property-attribute {
90+
margin: 4px 0;
91+
padding: 0;
92+
color: var(--api-type-document-type-attribute-color, #616161);
93+
}
94+
95+
.attribute-label {
96+
font-weight: var(--api-type-document-property-range-attribute-label-font-weight, 500);
97+
margin-right: 12px;
98+
}
8899
`;

test/api-type-document.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,39 @@ describe('<api-type-document>', () => {
521521
});
522522
});
523523

524+
describe('Array type with restrictions', () => {
525+
let element = /** @type ApiTypeDocument */ (null);
526+
beforeEach(async () => {
527+
const data = await AmfLoader.loadType('Emails', item[1], 'array-type');
528+
element = await basicFixture();
529+
element.amf = data[0];
530+
element.type = data[1];
531+
await aTimeout(0);
532+
});
533+
534+
it('isArray is true', () => {
535+
assert.isTrue(element.isArray);
536+
});
537+
538+
it('Renders array document', () => {
539+
const doc = element.shadowRoot.querySelector(
540+
'property-shape-document.array-document'
541+
);
542+
assert.ok(doc);
543+
});
544+
545+
it('Renders minItems and maxItems info', () => {
546+
const properties = element.shadowRoot.querySelectorAll(
547+
'.property-attribute'
548+
);
549+
assert.lengthOf(properties, 2);
550+
assert.equal(properties[0].querySelector('.attribute-label').innerText, 'Minimum array length:');
551+
assert.equal(properties[0].querySelector('.attribute-value').innerText, '1');
552+
assert.equal(properties[1].querySelector('.attribute-label').innerText, 'Maximum array length:');
553+
assert.equal(properties[1].querySelector('.attribute-value').innerText, '3');
554+
});
555+
});
556+
524557
describe('Scalar type', () => {
525558
let element = /** @type ApiTypeDocument */ (null);
526559

0 commit comments

Comments
 (0)