Skip to content

Commit 786cbc0

Browse files
committed
fix(W-12428173): Object being incorrectly recursively rendered in type documentation for allOf properties
1 parent eee91f6 commit 786cbc0

File tree

7 files changed

+88
-0
lines changed

7 files changed

+88
-0
lines changed

demo/W-12428173/W-12428173.raml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#%RAML 1.0 Library
2+
usage:
3+
4+
# see https://canda.leanix.net/canda/factsheet/DataObject/ad2b18a7-e768-411d-af15-f0fa5df689cd
5+
6+
types:
7+
valueAddedServiceMapping:
8+
type: !include ref/value-added-service-mapping-schema.json
9+
example: !include ref/value-added-service-mapping-example.json
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"seasVasLocation" : "SEAS"
3+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema",
3+
"description": "Represents data from MPTH70 Value Added Service Mapping For SAP ERP",
4+
"type": "object",
5+
"properties": {
6+
"seasVasLocation": {
7+
"type": "string",
8+
"description": "VAS Location in case of SEAS where this Value added service will be executed. @since 2023.1",
9+
"see" : "https://canda-services.atlassian.net/browse/CARA-75",
10+
"anyOf" : [
11+
{
12+
"type": "string",
13+
"enum": [ "SEAS", "DC" ]
14+
},
15+
{
16+
"type": "string",
17+
"description" : "accept any unknown value to be extendable",
18+
"see" : "https://canda-services.atlassian.net/wiki/spaces/IETKB/pages/1390149835/Web+API+Guideline#Versioning"
19+
}
20+
]
21+
}
22+
}
23+
}

demo/apis.json

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

src/ApiTypeDocument.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ export class ApiTypeDocument extends PropertyDocumentMixin(LitElement) {
388388
isOneOf = true;
389389
key = this._getAmfKey(this.ns.w3.shacl.xone);
390390
this.oneOfTypes = this._computeTypes(type, key);
391+
} else if (this._hasProperty(type, this.ns.w3.shacl.or)) {
392+
isAnyOf = true;
393+
key = this._getAmfKey(this.ns.w3.shacl.or);
394+
this.anyOfTypes = this._computeTypes(type, key);
391395
}
392396
} else if (
393397
this._hasType(type, this.ns.aml.vocabularies.shapes.UnionShape)

test/W-12428173.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-12428173';
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('valueAddedServiceMapping', 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)