Skip to content

Commit 12658ac

Browse files
Fix type display for partial model enum array (#14)
* chore(models): add aap-1698 issue model * chore(models): add to apis.json * fix(property-range): fix getting model `in` key * chore(lint): turn off prefer-destructuring * chore(lint): remove no-plusplus and consistent-return * test: add test case for partial model enum array * build: bump version * test: testing adding a timeout to test
1 parent 65823ca commit 12658ac

File tree

6 files changed

+98
-17
lines changed

6 files changed

+98
-17
lines changed

demo/aap-1698/aap-1698.raml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#%RAML 1.0
2+
title: AAP-1698
3+
4+
/working:
5+
post:
6+
body:
7+
application/json:
8+
type: object
9+
properties:
10+
userType:
11+
type:
12+
enum: [Admin, User, System]
13+
required: false
14+
15+
/not-working:
16+
post:
17+
body:
18+
application/json:
19+
type: object
20+
properties:
21+
mappers:
22+
description: optional set of mapper types to use for handling the request.
23+
type: array
24+
items:
25+
enum: [ "lookup","ml","fasttext"]
26+
required: false

demo/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"demo-api/demo-api.raml": "RAML 1.0",
3+
"aap-1698/aap-1698.raml": "RAML 1.0",
34
"apic-83/apic-83.raml": "RAML 1.0",
45
"oas-api/Petstore.yaml": "OAS 2.0",
56
"examples-api/examples-api.raml": "RAML 1.0",

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: 7 additions & 2 deletions
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.2",
4+
"version": "4.2.3",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",
@@ -91,7 +91,12 @@
9191
"import/no-extraneous-dependencies": "off"
9292
}
9393
}
94-
]
94+
],
95+
"rules": {
96+
"prefer-destructuring": "off",
97+
"no-plusplus": "off",
98+
"consistent-return": "off"
99+
}
95100
},
96101
"prettier": {
97102
"singleQuote": true,

src/PropertyRangeDocument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export class PropertyRangeDocument extends PropertyDocumentMixin(LitElement) {
172172
[model] = model;
173173
}
174174
if (isArray) {
175-
[model] = model[ikey];
175+
model = model[ikey];
176176
}
177177
const results = [];
178178
Object.keys(model).forEach((key) => {

test/api-type-document.test.js

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { fixture, assert, nextFrame, aTimeout } from '@open-wc/testing';
2-
import { AmfLoader } from './amf-loader.js';
32
import { tap } from '@polymer/iron-test-helpers/mock-interactions.js';
3+
import { AmfLoader } from './amf-loader.js';
44
import '../api-type-document.js';
55

66
describe('<api-type-document>', function () {
77
const newOas3Types = 'new-oas3-types';
88
async function basicFixture() {
9-
return await fixture(`<api-type-document></api-type-document>`);
9+
return fixture(`<api-type-document></api-type-document>`);
1010
}
1111

1212
function getPayloadType(element, model, path, methodName) {
@@ -707,7 +707,7 @@ describe('<api-type-document>', function () {
707707
});
708708

709709
describe('readOnly properties', () => {
710-
let element
710+
let element;
711711

712712
beforeEach(async () => {
713713
const data = await AmfLoader.loadType(
@@ -724,15 +724,21 @@ describe('<api-type-document>', function () {
724724
it('does not render the readOnly properties', async () => {
725725
element.renderReadOnly = false;
726726
await nextFrame();
727-
assert.lengthOf(element.shadowRoot.querySelectorAll('property-shape-document'), 1);
727+
assert.lengthOf(
728+
element.shadowRoot.querySelectorAll('property-shape-document'),
729+
1
730+
);
728731
});
729732

730733
it('renders the readOnly properties', async () => {
731734
element.renderReadOnly = true;
732735
await nextFrame();
733-
assert.lengthOf(element.shadowRoot.querySelectorAll('property-shape-document'), 2);
736+
assert.lengthOf(
737+
element.shadowRoot.querySelectorAll('property-shape-document'),
738+
2
739+
);
734740
});
735-
})
741+
});
736742
});
737743
});
738744

@@ -806,7 +812,7 @@ describe('<api-type-document>', function () {
806812

807813
[
808814
['Regular model - OAS 3 types additions', false],
809-
['Compact model - OAS 3 types additions', true]
815+
['Compact model - OAS 3 types additions', true],
810816
].forEach(([name, compact]) => {
811817
describe(name, () => {
812818
let element;
@@ -816,7 +822,11 @@ describe('<api-type-document>', function () {
816822
});
817823

818824
it('should represent type as oneOf', async () => {
819-
const [amf, type] = await AmfLoader.loadType('Pet', compact, newOas3Types)
825+
const [amf, type] = await AmfLoader.loadType(
826+
'Pet',
827+
compact,
828+
newOas3Types
829+
);
820830
element.amf = amf;
821831
element.type = type;
822832
await aTimeout(0);
@@ -825,17 +835,25 @@ describe('<api-type-document>', function () {
825835
});
826836

827837
it('changes selectedOneOf when button clicked', async () => {
828-
const [amf, type] = await AmfLoader.loadType('Pet', compact, newOas3Types)
838+
const [amf, type] = await AmfLoader.loadType(
839+
'Pet',
840+
compact,
841+
newOas3Types
842+
);
829843
element.amf = amf;
830844
element.type = type;
831845
await aTimeout(0);
832846
assert.equal(element.selectedOneOf, 0);
833-
element.shadowRoot.querySelectorAll('.one-of-toggle')[1].click()
847+
element.shadowRoot.querySelectorAll('.one-of-toggle')[1].click();
834848
assert.equal(element.selectedOneOf, 1);
835849
});
836850

837851
it('should represent type as anyOf', async () => {
838-
const [amf, type] = await AmfLoader.loadType('Monster', compact, newOas3Types)
852+
const [amf, type] = await AmfLoader.loadType(
853+
'Monster',
854+
compact,
855+
newOas3Types
856+
);
839857
element.amf = amf;
840858
element.type = type;
841859
await aTimeout(0);
@@ -844,17 +862,48 @@ describe('<api-type-document>', function () {
844862
});
845863

846864
it('changes selectedAnyOf when button clicked', async () => {
847-
const [amf, type] = await AmfLoader.loadType('Monster', compact, newOas3Types)
865+
const [amf, type] = await AmfLoader.loadType(
866+
'Monster',
867+
compact,
868+
newOas3Types
869+
);
848870
element.amf = amf;
849871
element.type = type;
850872
await aTimeout(0);
851873
assert.equal(element.selectedAnyOf, 0);
852-
element.shadowRoot.querySelectorAll('.any-of-toggle')[1].click()
874+
element.shadowRoot.querySelectorAll('.any-of-toggle')[1].click();
853875
assert.equal(element.selectedAnyOf, 1);
854876
});
855877
});
856878
});
857879

880+
[
881+
['Regular model - AAP-1698', false],
882+
['Compact model - AAP-1698', true],
883+
].forEach(([name, compact]) => {
884+
describe(name, () => {
885+
let element;
886+
let amf;
887+
let type;
888+
889+
beforeEach(async () => {
890+
element = await basicFixture();
891+
amf = await AmfLoader.load(compact, 'aap-1698');
892+
element.amf = amf;
893+
[type] = getPayloadType(element, amf, '/not-working', 'post');
894+
element.type = type;
895+
await nextFrame();
896+
await aTimeout(0);
897+
});
898+
899+
it('renders array of enum strings property with partial model', () => {
900+
assert.exists(
901+
element.shadowRoot.querySelector('property-shape-document')
902+
);
903+
});
904+
});
905+
});
906+
858907
describe('_mediaTypesChanged()', () => {
859908
let element;
860909
beforeEach(async () => {

0 commit comments

Comments
 (0)