Skip to content

Commit fb799c4

Browse files
twoplustwoonearcautodeiteris
authored
Fix multiple type rendering issues (#18)
* Add font-weight variable to the attribute label (#15) * refactor: add variable to adjust attribute label font-weight * docs: adjust readme formatting * chore(demo): add APIC-631 raml * fix: append "Array of" to anyOf type names for scalars * test: add test for scalar array in union toggles * fix: if name is undefined, return undefined instead of string * test: add test for undefined type name * fix: when array is of scalar type, add "Array of" title * test: add test for "Array of" title * fix: array of number not replacing ns string section * test: add test for array of number data type * 4.2.5 * 4.2.6 * 4.2.8 * chore(deps): regenerate package-lock.json Co-authored-by: Ci agent <arc@mulesoft.com> Co-authored-by: Yuri <RIP95_95@mail.ru>
1 parent 0ead8b1 commit fb799c4

File tree

10 files changed

+2198
-2102
lines changed

10 files changed

+2198
-2102
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ Custom property | Description | Default
5858
## Usage
5959

6060
### Installation
61-
```
61+
62+
```sh
6263
npm install --save @api-components/api-type-document
6364
```
6465

@@ -108,6 +109,7 @@ npm start
108109
```
109110

110111
### Running the tests
112+
111113
```sh
112114
npm test
113115
```

demo/APIC-631/APIC-631.raml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#%RAML 1.0
2+
title: APIC-631
3+
4+
5+
types:
6+
test1:
7+
properties:
8+
names1: string[] | nil
9+
test2:
10+
type: string[] | nil
11+
test3:
12+
type: string[]
13+
test4:
14+
properties:
15+
names1: string[]
16+
test5:
17+
type: string[]
18+
test8:
19+
properties:
20+
names8: number[]

demo/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"APIC-289/APIC-289.yaml": "OAS 2.0",
1010
"APIC-282/APIC-282.raml": "RAML 1.0",
1111
"APIC-483/APIC-483.raml": "RAML 1.0",
12+
"APIC-631/APIC-631.raml": "RAML 1.0",
1213
"APIC-429/APIC-429.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1314
"new-oas3-types/new-oas3-types.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1415
"oas-api/read-only-properties.yaml": { "type": "OAS 3.0", "mime": "application/yaml" }

package-lock.json

Lines changed: 2120 additions & 2097 deletions
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.7",
4+
"version": "4.2.8",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiTypeDocument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
652652
.mediaType="${this.mediaType}"
653653
?graph="${this.graph}"
654654
></property-shape-document>`
655-
: ''}
655+
: html`<span>Array of:</span>`}
656656
657657
<div class="array-children">
658658
${items.map(

src/PropertyDocumentMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ const mxFunction = (base) => {
419419
}
420420
list = this._resolve(list);
421421
if (this._hasType(list, this.ns.aml.vocabularies.shapes.ScalarShape)) {
422-
return this._computeRangeDataType(list);
422+
return `Array of ${this._computeRangeDataType(list)}`;
423423
}
424424
return this._computeDisplayName(list, list);
425425
}

src/PropertyShapeDocument.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
181181
[type] = type;
182182
let typed = String(type['@id']);
183183
typed = typed.replace(this.ns.w3.xmlSchema.key, '');
184+
typed = typed.replace(this.ns.aml.vocabularies.shapes.toString(), '');
184185
const stLetter = typed[0].toUpperCase();
185186
return `${stLetter}${typed.substr(1)}`;
186187
} catch (_) {
@@ -295,6 +296,9 @@ export class PropertyShapeDocument extends PropertyDocumentMixin(LitElement) {
295296
shape,
296297
this.ns.w3.shacl.name
297298
));
299+
if (name === undefined) {
300+
return undefined
301+
}
298302
if (name && name.indexOf('amf_inline_type') === 0) {
299303
return undefined;
300304
}

src/RangeStyles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default css`
2626
}
2727
2828
.attribute-label {
29-
font-weight: 500;
29+
font-weight: var(--api-type-document-property-range-attribute-label-font-weight, 500);
3030
margin-right: 12px;
3131
}
3232

test/api-type-document.test.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ describe('<api-type-document>', () => {
753753
['Compact model - Union types', true],
754754
].forEach((item) => {
755755
describe(String(item[0]), () => {
756+
const compact = item[1]
756757
describe('_typeChanged()', () => {
757758
let element = /** @type ApiTypeDocument */ (null);
758759
beforeEach(async () => {
@@ -813,6 +814,51 @@ describe('<api-type-document>', () => {
813814
assert.equal(u2.label, 'PropertyExamples', 'Union2 has name');
814815
});
815816
});
817+
818+
describe('APIC-631', () => {
819+
let element = /** @type ApiTypeDocument */ (null);
820+
821+
beforeEach(async () => {
822+
element = await basicFixture();
823+
});
824+
825+
it('should render union toggle as "Array of String"', async () => {
826+
const data = await AmfLoader.loadType('test2', compact, 'APIC-631');
827+
element.amf = data[0];
828+
element._typeChanged(element._resolve(data[1]));
829+
await nextFrame();
830+
const firstToggle = element.shadowRoot.querySelectorAll('.union-toggle')[0]
831+
assert.equal(firstToggle.textContent.toLowerCase(), 'array of string');
832+
});
833+
834+
it('should not render type name as "undefined" for inline type', async () => {
835+
const data = await AmfLoader.loadType('test3', compact, 'APIC-631');
836+
element.amf = data[0];
837+
element.type = data[1]
838+
await aTimeout(100);
839+
const propertyName = element.shadowRoot.querySelector('property-shape-document').shadowRoot.querySelector('span.property-name');
840+
assert.notExists(propertyName);
841+
});
842+
843+
it('should render "Array of:" in title for scalar array', async () => {
844+
const data = await AmfLoader.loadType('test3', compact, 'APIC-631');
845+
element.amf = data[0];
846+
element.type = data[1]
847+
await aTimeout(100);
848+
const firstSpan = element.shadowRoot.querySelector('span');
849+
assert.exists(firstSpan);
850+
assert.equal(firstSpan.textContent, 'Array of:');
851+
});
852+
853+
it('should render "Array of number" data type', async () => {
854+
const data = await AmfLoader.loadType('test8', compact, 'APIC-631');
855+
element.amf = data[0];
856+
element.type = data[1]
857+
await aTimeout(100);
858+
const dataType = element.shadowRoot.querySelector('property-shape-document').shadowRoot.querySelector('span.data-type');
859+
assert.equal(dataType.textContent, 'Array of Number');
860+
});
861+
});
816862
});
817863
});
818864

0 commit comments

Comments
 (0)