Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions demo/W-19097505/W-19097505.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"swagger": "2.0",
"info": {
"title": "Connected API",
"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",
"version": "v1"
},
"paths": {
"/1.0": {},
"/1.0/vehicle": {},
"/1.0/vehicle/manual": {
"get": {
"description": "Returns a list of digital manuals",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "",
"x-amf-mediaType": "application/json",
"schema": {
"example": [
{
"locale": "en-NZ",
"make": "TOYOTA",
"model": "AXAL64R_7",
"modelYear": "2026",
"vehicleRegion": "NZ",
"createdAt": "2025-06-25T03:31:08.000Z",
"documents": {
"om": [
{
"documentType": "om",
"documentUrl": "https://toyotanz.bynder.com/m/1a9818c1db004a8/original/AXAHA_NM1_OM_GeneralOceania_OM00C00E_1_2507-pdf.pdf",
"pubNumber": "OM00C00E",
"summary": "AXAHA_NM1_OM_GeneralOceania_OM00C00E_1_2507.pdf",
"title": "AXAHA_NM1_OM_GeneralOceania_OM00C00E_1_2507-pdf.pdf"
}
],
"omms": [],
"omnav": [
{
"documentType": "omnav",
"documentUrl": "https://toyotanz.bynder.com/m/81e86f1e4959e02/original/AXAHA_NM1_MM_GeneralOceania_OM00C00E_1_2507.pdf",
"pubNumber": "OM00C00E",
"summary": "AXAHA_NM1_MM_GeneralOceania_OM00C00E_1_2507",
"title": "AXAHA_NM1_MM_GeneralOceania_OM00C00E_1_2507.pdf"
}
]
}
}
]
}
}
}
}
}
}
}
3 changes: 2 additions & 1 deletion demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ class ComponentDemo extends ApiDemoPage {
['W-17309546', 'W-17309546'],
['W-17413312', 'W-17413312'],
['v4_0_0_api_specs', 'v4_0_0_api_specs'],
['W-18830464', 'W-18830464']
['W-18830464', 'W-18830464'],
['W-19097505', 'W-19097505']
].map(
([file, label]) => html`
<anypoint-item data-src="${file}-compact.json"
Expand Down
1 change: 1 addition & 0 deletions demo/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ files.set('v4_0_0_api_spec/v4_0_0_api_specs.yaml', { type: 'OAS 3.0', mime: 'app
files.set('W-11843862/W-11843862.yaml', { type: 'OAS 3.0', mime: 'application/yaml' });
files.set('W-12428170/W-12428170.yaml', { type: 'OAS 2.0', mime: 'application/yaml' });
files.set('W-18830464/W-18830464.json', { type: 'OAS 3.0', mime: 'application/json' });
files.set('W-19097505/W-19097505.json', { type: 'OAS 2.0', mime: 'application/json' });

generator.generate(files);
124 changes: 73 additions & 51 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@api-components/api-example-generator",
"description": "Examples generator from AMF model",
"version": "4.4.33",
"version": "4.4.34",
"license": "Apache-2.0",
"main": "index.js",
"module": "index.js",
Expand Down Expand Up @@ -41,6 +41,7 @@
"eslint": "^7.31.0",
"eslint-config-prettier": "^8.1.0",
"husky": "^7.0.1",
"js-yaml": "^4.1.0",
"lint-staged": "^11.1.1",
"sinon": "^11.1.1",
"typescript": "^4.2.2",
Expand Down
17 changes: 16 additions & 1 deletion src/ExampleGenerator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable class-methods-use-this */
import { AmfHelperMixin } from '@api-components/amf-helper-mixin/amf-helper-mixin.js';
import yaml from 'js-yaml';

/* eslint-disable prefer-destructuring */
/* eslint-disable no-plusplus */
Expand Down Expand Up @@ -893,7 +894,7 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
}


computeRaw(raw) {
computeRawOld2(raw) {
if (typeof raw !== 'string') {
return JSON.stringify(raw);
}
Expand Down Expand Up @@ -936,6 +937,20 @@ export class ExampleGenerator extends AmfHelperMixin(Object) {
// Convert to clean JSON string
return JSON.stringify(sanitized, null, 2);
}

computeRaw(raw) {
if (typeof raw !== 'string') {
return JSON.stringify(raw, null, 2);
}
try {
const parsed = yaml.load(raw);
return JSON.stringify(parsed, null, 2);
} catch (e) {
// this is a fallback for when the RAML is not valid.
return raw;
}
}

/**
* Computes list of examples for an array shape.
* @param {Object} schema The AMF's array shape
Expand Down
4 changes: 2 additions & 2 deletions test/ExampleGenerator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3180,8 +3180,8 @@ describe('ExampleGenerator', () => {
});

it('should correctly transform raw string to JSON', () => {
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";
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]';
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";
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]';
assert.equal(element.computeRaw(raw), expectedJson);
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/W-17309546.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,21 @@ describe('W-17309546', () => {
"id": 1,
"name": "Alice Dupont",
"email": "[email protected]",
"companyDateEntry": "2003-05-14",
"companyDateEntry": "2003-05-14T00:00:00.000Z",
"postal_code": "075001"
},
{
"id": 2,
"name": "Bob Martin",
"email": "[email protected]",
"companyDateEntry": "2004-05-04",
"companyDateEntry": "2004-05-04T00:00:00.000Z",
"postal_code": "169002"
},
{
"id": 3,
"name": "Charlie Durand",
"email": "[email protected]",
"companyDateEntry": "2003-08-11",
"companyDateEntry": "2003-08-11T00:00:00.000Z",
"postal_code": "013003"
}
]`);
Expand Down
18 changes: 10 additions & 8 deletions test/W-18830464.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,21 @@ describe('W-18830464', () => {
"programID": "ENERGYALERT",
"channelID": "EMAIL",
"userID": "CCB_IDL_Provider",
"customProperties": 0
},
{
"link": 0
"customProperties": [
{
"link": 0
}
]
},
{
"programID": "ENERGYALERT",
"channelID": "EMAIL",
"userID": "CCB_IDL_Provider",
"customProperties": 0
},
{
"link": 0
"customProperties": [
{
"link": 0
}
]
}
]`);
});
Expand Down
Loading
Loading