Skip to content

Commit 99d4cb6

Browse files
authored
Merge pull request #191 from SalesforceCommerceCloud/wjh/add-parent.W-9113461
Add parent field to metadata.
2 parents 645733c + d7c83f4 commit 99d4cb6

File tree

14 files changed

+16654
-609
lines changed

14 files changed

+16654
-609
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"",
3636
{
3737
"pattern": "^ \\* Copyright \\(c\\) \\d{4}, salesforce.com, inc\\.$",
38-
"template": " * Copyright (c) 2020, salesforce.com, inc."
38+
"template": " * Copyright (c) 2021, salesforce.com, inc."
3939
},
4040
" * All rights reserved.",
4141
" * SPDX-License-Identifier: BSD-3-Clause",

package-lock.json

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

package.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"dependencies": {
5353
"@oclif/command": "1.8.0",
5454
"@oclif/config": "1.17.0",
55-
"amf-client-js": "4.7.1",
55+
"amf-client-js": "4.7.2",
5656
"dotenv": "8.6.0",
5757
"fs-extra": "8.1.0",
5858
"handlebars": "4.7.7",
@@ -68,38 +68,38 @@
6868
"unzipper": "0.10.11"
6969
},
7070
"devDependencies": {
71-
"@fintechstudios/eslint-plugin-chai-as-promised": "^3.0.2",
72-
"@oclif/dev-cli": "^1.22.2",
71+
"@fintechstudios/eslint-plugin-chai-as-promised": "^3.1.0",
72+
"@oclif/dev-cli": "^1.26.0",
7373
"@oclif/parser": "^3.8.5",
74-
"@oclif/test": "^1.2.7",
75-
"@types/chai-as-promised": "^7.1.2",
74+
"@oclif/test": "^1.2.8",
75+
"@types/chai-as-promised": "^7.1.4",
7676
"@types/chai-fs": "^2.0.2",
77-
"@types/fs-extra": "^8.0.1",
78-
"@types/js-yaml": "^3.12.2",
79-
"@types/jszip": "^3.1.7",
80-
"@types/mocha": "^8.0.3",
77+
"@types/fs-extra": "^8.1.2",
78+
"@types/js-yaml": "^3.12.7",
79+
"@types/jszip": "^3.4.1",
80+
"@types/mocha": "^8.2.3",
8181
"@types/node": "^14.14.6",
82-
"@types/sinon": "^9.0.0",
83-
"@types/tmp": "^0.2.0",
84-
"@typescript-eslint/eslint-plugin": "^2.17.0",
85-
"@typescript-eslint/parser": "^2.17.0",
86-
"chai": "^4.2.0",
82+
"@types/sinon": "^9.0.11",
83+
"@types/tmp": "^0.2.1",
84+
"@typescript-eslint/eslint-plugin": "^2.34.0",
85+
"@typescript-eslint/parser": "^2.34.0",
86+
"chai": "^4.3.4",
8787
"chai-as-promised": "^7.1.1",
8888
"chai-fs": "^2.0.0",
8989
"depcheck": "^0.9.2",
90-
"eslint": "^6.6.0",
91-
"eslint-config-prettier": "^6.4.0",
90+
"eslint": "^6.8.0",
91+
"eslint-config-prettier": "^6.15.0",
9292
"eslint-plugin-header": "^3.0.0",
93-
"eslint-plugin-prettier": "^3.1.0",
94-
"jszip": "^3.2.2",
95-
"lint-staged": "^8.1.0",
96-
"mocha": "^8.2.1",
97-
"nock": "^12.0.2",
98-
"nyc": "^15.0.0",
99-
"prettier": "^2.0.5",
100-
"sinon": "^9.0.2",
101-
"sort-package-json": "^1.44.0",
102-
"tslib": "^1.10.0",
93+
"eslint-plugin-prettier": "^3.4.0",
94+
"jszip": "^3.6.0",
95+
"lint-staged": "^8.2.1",
96+
"mocha": "^8.4.0",
97+
"nock": "^12.0.3",
98+
"nyc": "^15.1.0",
99+
"prettier": "^2.3.2",
100+
"sinon": "^9.2.4",
101+
"sort-package-json": "^1.50.0",
102+
"tslib": "^1.14.1",
103103
"typescript": "^3.9.7"
104104
},
105105
"publishConfig": {

resources/lint/profiles/slas.profile.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, salesforce.com, inc.
2+
* Copyright (c) 2021, salesforce.com, inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -13,7 +13,8 @@ import { expect } from "chai";
1313
function loadProfile(profile: string): Record<string, any> {
1414
return yaml.safeLoad(
1515
fs.readFileSync(path.join(__dirname, `${profile}.raml`), "utf8")
16-
);
16+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
17+
) as unknown as Record<string, any>;
1718
}
1819

1920
describe("SLAS profile", () => {

src/diff/amfGraphDifferencer.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,8 @@ describe("Changes to the reference node ID with in a node", () => {
313313
const oldReferenceValue = {
314314
[AmfGraphTypes.KEY_NODE_ID]: "#/declarations/securitySchemes/test",
315315
};
316-
baseGraph[AmfGraphTypes.KEY_GRAPH][1][
317-
"security:scheme"
318-
] = oldReferenceValue;
316+
baseGraph[AmfGraphTypes.KEY_GRAPH][1]["security:scheme"] =
317+
oldReferenceValue;
319318

320319
const newGraph = buildValidGraph();
321320
const newReferenceValue = {

src/diff/diffDirectories.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ export async function diffApiModels(
2929
const leftRaml = path.join(leftApi.path, leftApi.main);
3030
const rightRaml = path.join(rightApi.path, rightApi.main);
3131
const differencer = new ApiDifferencer(leftRaml, rightRaml);
32-
changes.changed[
33-
leftApi.main
34-
] = await differencer.findAndCategorizeChanges();
32+
changes.changed[leftApi.main] =
33+
await differencer.findAndCategorizeChanges();
3534
} catch (error) {
3635
ramlToolLogger.error(
3736
`Diff operation for '${leftApi.name}' failed:`,

src/download/exchangeDownloader.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, salesforce.com, inc.
2+
* Copyright (c) 2021, salesforce.com, inc.
33
* All rights reserved.
44
* SPDX-License-Identifier: BSD-3-Clause
55
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
@@ -41,7 +41,9 @@ const ANYPOINT_API_URI_V2 = `${ANYPOINT_BASE_URI}/api/v2`;
4141
*/
4242
export async function runFetch(
4343
url: string,
44+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4445
options: { [key: string]: any } = {}
46+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4547
): Promise<any> {
4648
options.retry = _.merge({}, retryOptions, options.retry);
4749
options = _.merge(options, {

src/generate/apiMetadata.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
import { expect, default as chai } from "chai";
88
import chaiAsPromised from "chai-as-promised";
9+
import chaiFs from "chai-fs";
910

1011
import { Name } from "../common/structures/name";
1112
import { ApiMetadata } from "./";
@@ -24,6 +25,7 @@ const handlebarTemplate = path.join(
2425

2526
before(() => {
2627
chai.use(chaiAsPromised);
28+
chai.use(chaiFs);
2729
});
2830

2931
describe("ApiMetadata", () => {
@@ -142,6 +144,17 @@ describe("ApiMetadata", () => {
142144
expect(testTree.name).to.be.deep.equal(new Name("apis"));
143145
});
144146

147+
it("is created with no parent", () => {
148+
const testTree = new ApiMetadata("foo");
149+
expect(testTree.parent).to.be.null;
150+
});
151+
152+
it("adds itself as parent to its children", () => {
153+
const child = new ApiMetadata("child");
154+
const parent = new ApiMetadata("parent", null, [child]);
155+
expect(child.parent).to.equal(parent);
156+
});
157+
145158
it("adds a template that doesn't exist", async () => {
146159
const tmpDir = tmp.dirSync();
147160
await fs.ensureDir(path.join(tmpDir.name, "apis"));

src/generate/apiMetadata.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { HandlebarsWithAmfHelpers as Handlebars } from "./";
2020
export class ApiMetadata {
2121
name: Name;
2222
metadata: { [key: string]: unknown } = {};
23+
parent: ApiMetadata = null;
2324

2425
templates: {
2526
handlebarTemplate: TemplateDelegate;
@@ -47,6 +48,9 @@ export class ApiMetadata {
4748
);
4849
}
4950
}
51+
children.forEach((child) => {
52+
child.parent = this;
53+
});
5054
}
5155

5256
/**

src/generate/handlebarsAmfHelpers.test.ts

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@ describe("HandlebarsAmfHelpers", () => {
5656
});
5757

5858
it("returns false on valid optional properties", () => {
59-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
59+
const property: model.domain.PropertyShape =
60+
new model.domain.PropertyShape();
6061
property.withMinCount(0);
6162
expect(isRequiredProperty(property)).to.be.false;
6263
});
6364

6465
it("returns true on valid required class", () => {
65-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
66+
const property: model.domain.PropertyShape =
67+
new model.domain.PropertyShape();
6668
property.withMinCount(1);
6769
expect(isRequiredProperty(property)).to.be.true;
6870
});
@@ -78,13 +80,15 @@ describe("HandlebarsAmfHelpers", () => {
7880
});
7981

8082
it("returns false on valid required property", () => {
81-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
83+
const property: model.domain.PropertyShape =
84+
new model.domain.PropertyShape();
8285
property.withMinCount(1);
8386
expect(isOptionalProperty(property)).to.be.false;
8487
});
8588

8689
it("returns true on valid optional property", () => {
87-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
90+
const property: model.domain.PropertyShape =
91+
new model.domain.PropertyShape();
8892
property.withMinCount(0);
8993
expect(isOptionalProperty(property)).to.be.true;
9094
});
@@ -100,7 +104,8 @@ describe("HandlebarsAmfHelpers", () => {
100104
});
101105

102106
it("returns empty array on model containing only additional property", () => {
103-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
107+
const property: model.domain.PropertyShape =
108+
new model.domain.PropertyShape();
104109
property.withName("//");
105110
const typeDto = new model.domain.NodeShape();
106111
typeDto.withProperties([property]);
@@ -109,7 +114,8 @@ describe("HandlebarsAmfHelpers", () => {
109114
});
110115

111116
it("returns empty array on model containing only one additional property with regex", () => {
112-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
117+
const property: model.domain.PropertyShape =
118+
new model.domain.PropertyShape();
113119
property.withName("/.*/");
114120
const typeDto = new model.domain.NodeShape();
115121
typeDto.withProperties([property]);
@@ -118,7 +124,8 @@ describe("HandlebarsAmfHelpers", () => {
118124
});
119125

120126
it("returns empty array on model containing only one additional property with specific regex", () => {
121-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
127+
const property: model.domain.PropertyShape =
128+
new model.domain.PropertyShape();
122129
property.withName("/^c_.+$/?");
123130
property.withMinCount(1);
124131
const typeDto = new model.domain.NodeShape();
@@ -128,7 +135,8 @@ describe("HandlebarsAmfHelpers", () => {
128135
});
129136

130137
it("returns empty array on model containing only one additional property with prefix regex", () => {
131-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
138+
const property: model.domain.PropertyShape =
139+
new model.domain.PropertyShape();
132140
property.withName("^c_.+$");
133141
property.withMinCount(1);
134142
const typeDto = new model.domain.NodeShape();
@@ -142,10 +150,14 @@ describe("HandlebarsAmfHelpers", () => {
142150
});
143151

144152
it("returns an array of required and optional parameters on model with required, optional and additional parameters", () => {
145-
const property1: model.domain.PropertyShape = new model.domain.PropertyShape();
146-
const property2: model.domain.PropertyShape = new model.domain.PropertyShape();
147-
const property3: model.domain.PropertyShape = new model.domain.PropertyShape();
148-
const property4: model.domain.PropertyShape = new model.domain.PropertyShape();
153+
const property1: model.domain.PropertyShape =
154+
new model.domain.PropertyShape();
155+
const property2: model.domain.PropertyShape =
156+
new model.domain.PropertyShape();
157+
const property3: model.domain.PropertyShape =
158+
new model.domain.PropertyShape();
159+
const property4: model.domain.PropertyShape =
160+
new model.domain.PropertyShape();
149161
property1.withName("required");
150162
property1.withMinCount(1);
151163
property2.withName("optional");
@@ -159,8 +171,10 @@ describe("HandlebarsAmfHelpers", () => {
159171
});
160172

161173
it("returns an array with inherited parameters", () => {
162-
const inheritedProp: model.domain.PropertyShape = new model.domain.PropertyShape();
163-
const property: model.domain.PropertyShape = new model.domain.PropertyShape();
174+
const inheritedProp: model.domain.PropertyShape =
175+
new model.domain.PropertyShape();
176+
const property: model.domain.PropertyShape =
177+
new model.domain.PropertyShape();
164178
inheritedProp.withName("p1");
165179
inheritedProp.withMinCount(1);
166180
property.withName("p2");
@@ -175,8 +189,10 @@ describe("HandlebarsAmfHelpers", () => {
175189
});
176190

177191
it("returns an array with linked parameters", () => {
178-
const property1: model.domain.PropertyShape = new model.domain.PropertyShape();
179-
const property2: model.domain.PropertyShape = new model.domain.PropertyShape();
192+
const property1: model.domain.PropertyShape =
193+
new model.domain.PropertyShape();
194+
const property2: model.domain.PropertyShape =
195+
new model.domain.PropertyShape();
180196
property1.withName("p1");
181197
property1.withMinCount(1);
182198
property2.withName("p2");
@@ -190,10 +206,14 @@ describe("HandlebarsAmfHelpers", () => {
190206
});
191207

192208
it("returns an array excluding duplicate properties", () => {
193-
const property1: model.domain.PropertyShape = new model.domain.PropertyShape();
194-
const property2: model.domain.PropertyShape = new model.domain.PropertyShape();
195-
const property3: model.domain.PropertyShape = new model.domain.PropertyShape();
196-
const property4: model.domain.PropertyShape = new model.domain.PropertyShape();
209+
const property1: model.domain.PropertyShape =
210+
new model.domain.PropertyShape();
211+
const property2: model.domain.PropertyShape =
212+
new model.domain.PropertyShape();
213+
const property3: model.domain.PropertyShape =
214+
new model.domain.PropertyShape();
215+
const property4: model.domain.PropertyShape =
216+
new model.domain.PropertyShape();
197217
property1.withName("p1");
198218
property1.withMinCount(1);
199219
property2.withName("duplicate");

0 commit comments

Comments
 (0)