Skip to content

Commit 5d782d8

Browse files
authored
Merge pull request #73 from advanced-rest-client/W-19097505-Example-array-is-getting-rendered-differently-in-Exchange-UI-and-Design-Center
W-19097505 example array is getting rendered differently in exchange UI and design center
2 parents 2412073 + 9c0d32b commit 5d782d8

File tree

10 files changed

+238
-67
lines changed

10 files changed

+238
-67
lines changed

demo/W-19097505/W-19097505.json

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "Connected API",
5+
"description": "Resources, information and management for digitially connected products\nAll resources of this service requires a valid security token.\nSee Security Token Service API \n",
6+
"version": "v1"
7+
},
8+
"paths": {
9+
"/1.0": {},
10+
"/1.0/vehicle": {},
11+
"/1.0/vehicle/manual": {
12+
"get": {
13+
"description": "Returns a list of digital manuals",
14+
"produces": [
15+
"application/json"
16+
],
17+
"responses": {
18+
"200": {
19+
"description": "",
20+
"x-amf-mediaType": "application/json",
21+
"schema": {
22+
"example": [
23+
{
24+
"locale": "en-NZ",
25+
"make": "TOYOTA",
26+
"model": "AXAL64R_7",
27+
"modelYear": "2026",
28+
"vehicleRegion": "NZ",
29+
"createdAt": "2025-06-25T03:31:08.000Z",
30+
"documents": {
31+
"om": [
32+
{
33+
"documentType": "om",
34+
"documentUrl": "https://toyotanz.bynder.com/m/1a9818c1db004a8/original/AXAHA_NM1_OM_GeneralOceania_OM00C00E_1_2507-pdf.pdf",
35+
"pubNumber": "OM00C00E",
36+
"summary": "AXAHA_NM1_OM_GeneralOceania_OM00C00E_1_2507.pdf",
37+
"title": "AXAHA_NM1_OM_GeneralOceania_OM00C00E_1_2507-pdf.pdf"
38+
}
39+
],
40+
"omms": [],
41+
"omnav": [
42+
{
43+
"documentType": "omnav",
44+
"documentUrl": "https://toyotanz.bynder.com/m/81e86f1e4959e02/original/AXAHA_NM1_MM_GeneralOceania_OM00C00E_1_2507.pdf",
45+
"pubNumber": "OM00C00E",
46+
"summary": "AXAHA_NM1_MM_GeneralOceania_OM00C00E_1_2507",
47+
"title": "AXAHA_NM1_MM_GeneralOceania_OM00C00E_1_2507.pdf"
48+
}
49+
]
50+
}
51+
}
52+
]
53+
}
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}

demo/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ class ComponentDemo extends ApiDemoPage {
127127
['W-17309546', 'W-17309546'],
128128
['W-17413312', 'W-17413312'],
129129
['v4_0_0_api_specs', 'v4_0_0_api_specs'],
130-
['W-18830464', 'W-18830464']
130+
['W-18830464', 'W-18830464'],
131+
['W-19097505', 'W-19097505']
131132
].map(
132133
([file, label]) => html`
133134
<anypoint-item data-src="${file}-compact.json"

demo/model.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ files.set('v4_0_0_api_spec/v4_0_0_api_specs.yaml', { type: 'OAS 3.0', mime: 'app
3232
files.set('W-11843862/W-11843862.yaml', { type: 'OAS 3.0', mime: 'application/yaml' });
3333
files.set('W-12428170/W-12428170.yaml', { type: 'OAS 2.0', mime: 'application/yaml' });
3434
files.set('W-18830464/W-18830464.json', { type: 'OAS 3.0', mime: 'application/json' });
35+
files.set('W-19097505/W-19097505.json', { type: 'OAS 2.0', mime: 'application/json' });
3536

3637
generator.generate(files);

package-lock.json

Lines changed: 73 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-example-generator",
33
"description": "Examples generator from AMF model",
4-
"version": "4.4.33",
4+
"version": "4.4.34",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",
@@ -41,6 +41,7 @@
4141
"eslint": "^7.31.0",
4242
"eslint-config-prettier": "^8.1.0",
4343
"husky": "^7.0.1",
44+
"js-yaml": "^4.1.0",
4445
"lint-staged": "^11.1.1",
4546
"sinon": "^11.1.1",
4647
"typescript": "^4.2.2",

src/ExampleGenerator.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable class-methods-use-this */
22
import { AmfHelperMixin } from '@api-components/amf-helper-mixin/amf-helper-mixin.js';
3+
import yaml from 'js-yaml';
34

45
/* eslint-disable prefer-destructuring */
56
/* eslint-disable no-plusplus */
@@ -893,7 +894,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
893894
}
894895

895896

896-
computeRaw(raw) {
897+
computeRawOld2(raw) {
897898
if (typeof raw !== 'string') {
898899
return JSON.stringify(raw);
899900
}
@@ -936,6 +937,20 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
936937
// Convert to clean JSON string
937938
return JSON.stringify(sanitized, null, 2);
938939
}
940+
941+
computeRaw(raw) {
942+
if (typeof raw !== 'string') {
943+
return JSON.stringify(raw, null, 2);
944+
}
945+
try {
946+
const parsed = yaml.load(raw);
947+
return JSON.stringify(parsed, null, 2);
948+
} catch (e) {
949+
// this is a fallback for when the RAML is not valid.
950+
return raw;
951+
}
952+
}
953+
939954
/**
940955
* Computes list of examples for an array shape.
941956
* @param {Object} schema The AMF's array shape

test/ExampleGenerator.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,8 +3180,8 @@ describe('ExampleGenerator', () => {
31803180
});
31813181

31823182
it('should correctly transform raw string to JSON', () => {
3183-
const raw = "-\n balance: 200\n approval-status: P\n account-id: de7228b9-f6bb-4261-9d17-a3ddd5802e03\n account-name: Plaid Saving\n account-number: '1111222233331111'\n account-routing-number: '123123123'\n institution-name: Sample Bank\n institution-id: b3dedb19-157c-4239-880f-a125ef4384e2\n created-by: WREX\n modified-by: WREX\n created-at: February 19, 2023, 3:16:01 AM\n modified-at: February 19, 2023, 3:16:01 AM\n-\n balance: 100\n approval-status: P\n account-id: e7bb8f6d-fdc0-4873-9609-d2f2713900ed\n account-name: Plaid Checking\n account-number: '1111222233330000 '\n account-routing-number: '123123123'\n institution-name: Sample Bank\n institution-id: b3dedb19-157c-4239-880f-a125ef4384e2\n created-by: WREX\n modified-by: WREX\n created-at: February 19, 2023, 3:16:01 AM\n modified-at: February 19, 2023, 3:16:01 AM";
3184-
const expectedJson = '[\n {\n "balance": 200,\n "approval-status": "P",\n "account-id": "de7228b9-f6bb-4261-9d17-a3ddd5802e03",\n "account-name": "Plaid Saving",\n "account-number": "\'1111222233331111\'",\n "account-routing-number": "\'123123123\'",\n "institution-name": "Sample Bank",\n "institution-id": "b3dedb19-157c-4239-880f-a125ef4384e2",\n "created-by": "WREX",\n "modified-by": "WREX",\n "created-at": "February 19, 2023, 3:16:01 AM",\n "modified-at": "February 19, 2023, 3:16:01 AM"\n },\n {\n "balance": 100,\n "approval-status": "P",\n "account-id": "e7bb8f6d-fdc0-4873-9609-d2f2713900ed",\n "account-name": "Plaid Checking",\n "account-number": "\'1111222233330000 \'",\n "account-routing-number": "\'123123123\'",\n "institution-name": "Sample Bank",\n "institution-id": "b3dedb19-157c-4239-880f-a125ef4384e2",\n "created-by": "WREX",\n "modified-by": "WREX",\n "created-at": "February 19, 2023, 3:16:01 AM",\n "modified-at": "February 19, 2023, 3:16:01 AM"\n }\n]';
3183+
const raw = "-\n balance: 200\n approval-status: P\n account-id: de7228b9-f6bb-4261-9d17-a3ddd5802e03\n account-name: Plaid Saving\n account-number: '1111222233331111'\n account-routing-number: '123123123'\n institution-name: Sample Bank\n institution-id: b3dedb19-157c-4239-880f-a125ef4384e2\n created-by: WREX\n modified-by: WREX\n created-at: February 19, 2023, 3:16:01 AM\n modified-at: February 19, 2023, 3:16:01 AM\n-\n balance: 100\n approval-status: P\n account-id: e7bb8f6d-fdc0-4873-9609-d2f2713900ed\n account-name: Plaid Checking\n account-number: '1111222233330000'\n account-routing-number: '123123123'\n institution-name: Sample Bank\n institution-id: b3dedb19-157c-4239-880f-a125ef4384e2\n created-by: WREX\n modified-by: WREX\n created-at: February 19, 2023, 3:16:01 AM\n modified-at: February 19, 2023, 3:16:01 AM";
3184+
const expectedJson = '[\n {\n "balance": 200,\n "approval-status": "P",\n "account-id": "de7228b9-f6bb-4261-9d17-a3ddd5802e03",\n "account-name": "Plaid Saving",\n "account-number": "1111222233331111",\n "account-routing-number": "123123123",\n "institution-name": "Sample Bank",\n "institution-id": "b3dedb19-157c-4239-880f-a125ef4384e2",\n "created-by": "WREX",\n "modified-by": "WREX",\n "created-at": "February 19, 2023, 3:16:01 AM",\n "modified-at": "February 19, 2023, 3:16:01 AM"\n },\n {\n "balance": 100,\n "approval-status": "P",\n "account-id": "e7bb8f6d-fdc0-4873-9609-d2f2713900ed",\n "account-name": "Plaid Checking",\n "account-number": "1111222233330000",\n "account-routing-number": "123123123",\n "institution-name": "Sample Bank",\n "institution-id": "b3dedb19-157c-4239-880f-a125ef4384e2",\n "created-by": "WREX",\n "modified-by": "WREX",\n "created-at": "February 19, 2023, 3:16:01 AM",\n "modified-at": "February 19, 2023, 3:16:01 AM"\n }\n]';
31853185
assert.equal(element.computeRaw(raw), expectedJson);
31863186
});
31873187
});

test/W-17309546.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ describe('W-17309546', () => {
3636
"id": 1,
3737
"name": "Alice Dupont",
3838
"email": "[email protected]",
39-
"companyDateEntry": "2003-05-14",
39+
"companyDateEntry": "2003-05-14T00:00:00.000Z",
4040
"postal_code": "075001"
4141
},
4242
{
4343
"id": 2,
4444
"name": "Bob Martin",
4545
"email": "[email protected]",
46-
"companyDateEntry": "2004-05-04",
46+
"companyDateEntry": "2004-05-04T00:00:00.000Z",
4747
"postal_code": "169002"
4848
},
4949
{
5050
"id": 3,
5151
"name": "Charlie Durand",
5252
"email": "[email protected]",
53-
"companyDateEntry": "2003-08-11",
53+
"companyDateEntry": "2003-08-11T00:00:00.000Z",
5454
"postal_code": "013003"
5555
}
5656
]`);

test/W-18830464.test.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,21 @@ describe('W-18830464', () => {
4242
"programID": "ENERGYALERT",
4343
"channelID": "EMAIL",
4444
"userID": "CCB_IDL_Provider",
45-
"customProperties": 0
46-
},
47-
{
48-
"link": 0
45+
"customProperties": [
46+
{
47+
"link": 0
48+
}
49+
]
4950
},
5051
{
5152
"programID": "ENERGYALERT",
5253
"channelID": "EMAIL",
5354
"userID": "CCB_IDL_Provider",
54-
"customProperties": 0
55-
},
56-
{
57-
"link": 0
55+
"customProperties": [
56+
{
57+
"link": 0
58+
}
59+
]
5860
}
5961
]`);
6062
});

0 commit comments

Comments
 (0)