From 5cedb42c6167cf92524057ae1562848dd945bf42 Mon Sep 17 00:00:00 2001 From: Carolina Wright Date: Fri, 24 Jun 2022 16:39:05 -0300 Subject: [PATCH 1/2] fix: missing array length restrictions info --- demo/apis.json | 1 + demo/array-type/array-type.raml | 18 +++++++++++++++++ demo/index.js | 1 + src/ApiTypeDocument.js | 35 +++++++++++++++++++++++++++------ src/TypeStyles.js | 11 +++++++++++ test/api-type-document.test.js | 33 +++++++++++++++++++++++++++++++ 6 files changed, 93 insertions(+), 6 deletions(-) create mode 100644 demo/array-type/array-type.raml diff --git a/demo/apis.json b/demo/apis.json index 10f7a9d..1cb23b3 100644 --- a/demo/apis.json +++ b/demo/apis.json @@ -13,6 +13,7 @@ "SE-19500/SE-19500.raml": "RAML 1.0", "enum-test/enum-test.raml": "RAML 1.0", "APIC-667/APIC-667.raml": "RAML 1.0", + "array-type/array-type.raml": "RAML 1.0", "APIC-429/APIC-429.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }, "SE-17897/SE-17897.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }, "new-oas3-types/new-oas3-types.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }, diff --git a/demo/array-type/array-type.raml b/demo/array-type/array-type.raml new file mode 100644 index 0000000..29a0c3b --- /dev/null +++ b/demo/array-type/array-type.raml @@ -0,0 +1,18 @@ +#%RAML 1.0 +title: 00193743 + +types: + Email: + type: object + properties: + name: + type: string + Emails: + type: array + items: Email + minItems: 1 + maxItems: 3 + uniqueItems: true + Other: + type: string + minLength: 2 diff --git a/demo/index.js b/demo/index.js index d8be25a..52e6854 100644 --- a/demo/index.js +++ b/demo/index.js @@ -112,6 +112,7 @@ class ApiDemo extends ApiDemoPage { ['APIC-282', 'APIC-282'], ['new-oas3-types', 'New OAS 3 types API'], ['APIC-483', 'APIC 483'], + ['array-type', 'array-type'], ].map( ([file, label]) => html` ${label} - compact model + ${label} + ${value} + + ` + } + + _arrayPropertiesTemplate() { + const minCount = this._getValue(this._resolvedType, this.ns.w3.shacl.minCount) + const maxCount = this._getValue(this._resolvedType, this.ns.w3.shacl.maxCount) + + return html` + ${minCount !== undefined ? this._arrayPropertyTemplate('Minimum array length:', minCount, 'Minimum amount of items in array') : ''} + ${maxCount !== undefined ? this._arrayPropertyTemplate('Maximum array length:', maxCount, 'Maximum amount of items in array') : ''} + ` + } + /** * @return {TemplateResult} Templates for object properties */ @@ -688,15 +707,19 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) { : ''} ` ); - if (!this.hasParentType) { - return html` + + return html` + ${!this.hasParentType ? + html` Array of:
${documents} -
- `; - } - return html`${documents}`; + ` + : html`${documents}` + } + + ${this._arrayPropertiesTemplate()} + `; } /** diff --git a/src/TypeStyles.js b/src/TypeStyles.js index 5fd500e..dc54f78 100644 --- a/src/TypeStyles.js +++ b/src/TypeStyles.js @@ -85,4 +85,15 @@ export default css` .union-type-selector { margin: 12px 0; } + + .property-attribute { + margin: 4px 0; + padding: 0; + color: var(--api-type-document-type-attribute-color, #616161); + } + + .attribute-label { + font-weight: var(--api-type-document-property-range-attribute-label-font-weight, 500); + margin-right: 12px; + } `; diff --git a/test/api-type-document.test.js b/test/api-type-document.test.js index c19d331..9379366 100644 --- a/test/api-type-document.test.js +++ b/test/api-type-document.test.js @@ -521,6 +521,39 @@ describe('', () => { }); }); + describe('Array type with restrictions', () => { + let element = /** @type ApiTypeDocument */ (null); + beforeEach(async () => { + const data = await AmfLoader.loadType('Emails', item[1], 'array-type'); + element = await basicFixture(); + element.amf = data[0]; + element.type = data[1]; + await aTimeout(0); + }); + + it('isArray is true', () => { + assert.isTrue(element.isArray); + }); + + it('Renders array document', () => { + const doc = element.shadowRoot.querySelector( + 'property-shape-document.array-document' + ); + assert.ok(doc); + }); + + it('Renders minItems and maxItems info', () => { + const properties = element.shadowRoot.querySelectorAll( + '.property-attribute' + ); + assert.lengthOf(properties, 2); + assert.equal(properties[0].querySelector('.attribute-label').innerText, 'Minimum array length:'); + assert.equal(properties[0].querySelector('.attribute-value').innerText, '1'); + assert.equal(properties[1].querySelector('.attribute-label').innerText, 'Maximum array length:'); + assert.equal(properties[1].querySelector('.attribute-value').innerText, '3'); + }); + }); + describe('Scalar type', () => { let element = /** @type ApiTypeDocument */ (null); From 3e97e8e8e8737d4f547cc218ebf0eda278f7f9e1 Mon Sep 17 00:00:00 2001 From: Carolina Wright Date: Fri, 24 Jun 2022 16:39:42 -0300 Subject: [PATCH 2/2] build: bump version --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2e19de..8c14d1a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@api-components/api-type-document", - "version": "4.2.17", + "version": "4.2.18", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4f68dd8..16e0541 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@api-components/api-type-document", "description": "A documentation table for type (resource) properties. Works with AMF data model", - "version": "4.2.17", + "version": "4.2.18", "license": "Apache-2.0", "main": "index.js", "module": "index.js",