Skip to content

Commit 7842f62

Browse files
committed
test(ExampleGenerator): example correctly generated for type with allOf and props
1 parent 9e00de9 commit 7842f62

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

demo/W-12428170/W-12428170.yaml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
swagger: "2.0"
2+
info:
3+
description: "UPM Party Services"
4+
version: 1.0.0
5+
title: UPM Party Services
6+
contact:
7+
email: CustomerMDM@internal.toyota.com
8+
schemes:
9+
- https
10+
11+
paths:
12+
/customers/preferences/search:
13+
post:
14+
summary: "Search customer preferences"
15+
description: "Search customer preferences"
16+
produces:
17+
- application/json
18+
consumes:
19+
- application/json
20+
tags:
21+
- Search Services
22+
responses:
23+
"200":
24+
description: "Get Address search response"
25+
schema:
26+
$ref: "#/definitions/preferencesSearchDTO"
27+
28+
definitions:
29+
preferencesSearchDTO:
30+
type: object
31+
properties:
32+
Account:
33+
type: "array"
34+
items:
35+
$ref: "#/definitions/PreferenceSearchAccount"
36+
PreferenceSearchAccount:
37+
type: object
38+
allOf:
39+
- $ref: "#/definitions/AccountBaseDTO"
40+
properties:
41+
Collateral:
42+
type: "array"
43+
items:
44+
$ref: "#/definitions/CollateralDemographicsSearch"
45+
Contact:
46+
type: "array"
47+
items:
48+
$ref: "#/definitions/SearchPreferenceContactDTO"
49+
CollateralDemographicsSearch:
50+
type: object
51+
properties:
52+
collateralId:
53+
type: string
54+
description: collateral id vin or hin or etc
55+
example: "123"
56+
SearchPreferenceContactDTO:
57+
type: object
58+
properties:
59+
upid:
60+
type: string
61+
example: "053fa2ac-4afd-4dac-9ba4-d1201ed919b1"
62+
description: "Customer UPID"
63+
AccountBaseDTO:
64+
type: object
65+
properties:
66+
applicationId:
67+
type: string
68+
example: ""
69+
description: "Application ID"

demo/model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ files.set('APIC-679/APIC-679.yaml', { type: 'OAS 3.0', mime: 'application/yaml'
2828
files.set('xml-api/xml-api.yaml', { type: 'OAS 3.0', mime: 'application/yaml' });
2929
files.set('v4_0_0_api_spec/v4_0_0_api_specs.yaml', { type: 'OAS 3.0', mime: 'application/yaml' });
3030
files.set('W-11843862/W-11843862.yaml', { type: 'OAS 3.0', mime: 'application/yaml' });
31+
files.set('W-12428170/W-12428170.yaml', { type: 'OAS 2.0', mime: 'application/yaml' });
3132

3233
generator.generate(files);

test/ExampleGenerator.test.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,42 @@ describe('ExampleGenerator', () => {
23272327
});
23282328
});
23292329

2330+
describe('W-12428170', () => {
2331+
[
2332+
['json+ld data model', false],
2333+
['Compact data model', true],
2334+
].forEach((args) => {
2335+
const label = args[0];
2336+
const compact = /** @type boolean */ (args[1]);
2337+
2338+
describe(String(label), () => {
2339+
/** @type ExampleGenerator */
2340+
let element;
2341+
let amf;
2342+
let prefix;
2343+
2344+
before(async () => {
2345+
amf = await AmfLoader.load(compact, 'W-12428170');
2346+
});
2347+
2348+
beforeEach(async () => {
2349+
element = new ExampleGenerator(amf);
2350+
prefix = element._getAmfKey(element.ns.w3.xmlSchema.key);
2351+
if (prefix !== element.ns.w3.xmlSchema.key) {
2352+
prefix += ':';
2353+
}
2354+
});
2355+
2356+
it('returns value for array type with allOf items', () => {
2357+
let properties = AmfLoader.lookupTypeProperties(amf, "PreferenceSearchAccount");
2358+
const result = element._exampleFromProperties(properties, 'application/json', 'preferencesSearchDTO');
2359+
assert.typeOf(result, 'object');
2360+
assert.deepEqual(result.value, "{\n \"Collateral\": [\n {\n \"collateralId\": \"123\"\n }\n ],\n \"Contact\": [\n {\n \"upid\": \"053fa2ac-4afd-4dac-9ba4-d1201ed919b1\"\n }\n ]\n}")
2361+
});
2362+
});
2363+
});
2364+
});
2365+
23302366
describe('APIC-679', () => {
23312367
describe('_computeJsonPropertyValue()', () => {
23322368
[

0 commit comments

Comments
 (0)