Skip to content

Commit eee91f6

Browse files
authored
Merge pull request #71 from advanced-rest-client/fix/W-12137562/type-recursion
[W-12137562] Object being incorrectly recursively rendered in type documentation
2 parents c21f341 + 91247bb commit eee91f6

File tree

8 files changed

+92
-3
lines changed

8 files changed

+92
-3
lines changed

demo/W-12137562/W-12137562.raml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#%RAML 1.0
2+
title: api
3+
types:
4+
Pet:
5+
type: !include /pet.json

demo/W-12137562/pet.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"title": "pet",
3+
"description": "pet",
4+
"examples": [
5+
{
6+
"animal": "pet"
7+
}
8+
],
9+
"type": "object",
10+
"properties": {
11+
"pet": {
12+
"type": "string",
13+
"oneOf": [
14+
{
15+
"const": "CT",
16+
"description": "Cat"
17+
},
18+
{
19+
"const": "DG",
20+
"description": "Dog"
21+
},
22+
{
23+
"const": "PT",
24+
"description": "Parrot"
25+
}
26+
]
27+
}
28+
}
29+
}

demo/apis.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"APIC-667/APIC-667.raml": "RAML 1.0",
1616
"array-type/array-type.raml": "RAML 1.0",
1717
"W-11858334/W-11858334.raml": "RAML 1.0",
18+
"W-12137562/W-12137562.raml": "RAML 1.0",
1819
"APIC-429/APIC-429.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
1920
"SE-17897/SE-17897.yaml": { "type": "OAS 3.0", "mime": "application/yaml" },
2021
"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
@@ -114,6 +114,7 @@ class ApiDemo extends ApiDemoPage {
114114
['APIC-483', 'APIC 483'],
115115
['array-type', 'array-type'],
116116
['W-11858334', 'W-11858334'],
117+
['W-12137562', 'W-12137562'],
117118
].map(
118119
([file, label]) => html` <anypoint-item data-src="${file}-compact.json"
119120
>${label} - compact model</anypoint-item

package-lock.json

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

src/ApiTypeDocument.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
383383
this._hasType(type, this.ns.aml.vocabularies.shapes.NilShape)
384384
) {
385385
isScalar = true;
386+
if (this._hasProperty(type, this.ns.w3.shacl.xone)) {
387+
isScalar = false;
388+
isOneOf = true;
389+
key = this._getAmfKey(this.ns.w3.shacl.xone);
390+
this.oneOfTypes = this._computeTypes(type, key);
391+
}
386392
} else if (
387393
this._hasType(type, this.ns.aml.vocabularies.shapes.UnionShape)
388394
) {

test/W-12137562.test.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/* eslint-disable prefer-destructuring */
2+
import {fixture, assert, aTimeout} from '@open-wc/testing'
3+
import { AmfLoader } from './amf-loader.js';
4+
import '../api-type-document.js';
5+
6+
/** @typedef {import('..').ApiTypeDocument} ApiTypeDocument */
7+
/** @typedef {import('..').PropertyShapeDocument} PropertyShapeDocument */
8+
/** @typedef {import('@api-components/amf-helper-mixin').AmfDocument} AmfDocument */
9+
10+
describe('<api-type-document>', () => {
11+
const file = 'W-12137562';
12+
13+
/**
14+
* @returns {Promise<ApiTypeDocument>}
15+
*/
16+
async function basicFixture() {
17+
return fixture(`<api-type-document></api-type-document>`);
18+
}
19+
20+
[
21+
['Regular model', false],
22+
['Compact model', true],
23+
].forEach((item) => {
24+
describe(String(item[0]), () => {
25+
let element = /** @type ApiTypeDocument */ (null);
26+
beforeEach(async () => {
27+
element = await basicFixture();
28+
});
29+
30+
it('renders complex element', async () => {
31+
const data = await AmfLoader.loadType('Pet', item[1], file);
32+
element.amf = data[0];
33+
element.type = data[1];
34+
await aTimeout(0);
35+
36+
const shape = element.shadowRoot.querySelector('property-shape-document')
37+
assert.ok(shape);
38+
39+
/** @type HTMLElement */ (shape.shadowRoot.querySelector('.complex-toggle')).click();
40+
await aTimeout(0);
41+
await aTimeout(0);
42+
43+
assert.ok(shape.shadowRoot.querySelector('api-type-document.children.complex'));
44+
});
45+
});
46+
});
47+
});

0 commit comments

Comments
 (0)