Skip to content

Commit c82cfef

Browse files
author
Gustavo Bazan
authored
task: fix typos (#542)
1 parent deb17cd commit c82cfef

File tree

8 files changed

+30
-46
lines changed

8 files changed

+30
-46
lines changed

tools/transformer/src/atlasTransformations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {
44
applyModelNameTransformations,
55
applyDiscriminatorTransformations,
66
applyRemoveEnumsTransformations,
7-
applyRemoveObjectAdditonalProperties,
7+
applyRemoveObjectAdditionalProperties,
88
applyAnyOfTransformations,
99
applyRemoveNullableTransformations,
1010
removeRefsFromParameters,
@@ -27,7 +27,7 @@ module.exports = function runTransformations(openapi) {
2727
openapi = applyAllOfTransformations(openapi);
2828
openapi = applyRemoveEnumsTransformations(openapi);
2929
openapi = applyRemoveNullableTransformations(openapi);
30-
openapi = applyRemoveObjectAdditonalProperties(openapi);
30+
openapi = applyRemoveObjectAdditionalProperties(openapi);
3131
openapi = reorderResponseBodies(openapi);
3232

3333
openapi = applyModelNameTransformations(

tools/transformer/src/engine/readers.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function getAllObjects(object, filter = (_obj) => true) {
5252
}
5353
}
5454
}
55-
// Add all properties of the object to the recurssion stack
55+
// Add all properties of the object to the recursion stack
5656
else {
5757
for (let key of Object.keys(currentObj)) {
5858
if (typeof currentObj[key] === "object" && currentObj[key]) {
@@ -69,14 +69,12 @@ function getAllObjects(object, filter = (_obj) => true) {
6969
}
7070

7171
function filterObjectProperties(object, filter = (_k, _v) => true) {
72-
const filteredObj = Object.keys(object)
72+
return Object.keys(object)
7373
.filter((key) => filter(key, object[key]))
7474
.reduce((aggregationObj, key) => {
7575
aggregationObj[key] = object[key];
7676
return aggregationObj;
7777
}, {});
78-
79-
return filteredObj;
8078
}
8179

8280
function getObjectProperties(obj) {
@@ -149,11 +147,11 @@ function isSchema(path) {
149147
const pathStack = path.split(".").reverse();
150148
pathStack.pop();
151149

152-
if (pathStack.length != 3) {
150+
if (pathStack.length !== 3) {
153151
return false;
154152
}
155153

156-
return pathStack.pop() == "components" && pathStack.pop() == "schemas";
154+
return pathStack.pop() === "components" && pathStack.pop() === "schemas";
157155
}
158156

159157
module.exports = {

tools/transformer/src/engine/transformers.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ const {
44
} = require("../engine/readers");
55

66
function filterObjectProperties(object, filter = (_k, _v) => true) {
7-
const filteredObj = Object.keys(object)
7+
return Object.keys(object)
88
.filter((key) => filter(key, object[key]))
99
.reduce((aggregationObj, key) => {
1010
aggregationObj[key] = object[key];
1111
return aggregationObj;
1212
}, {});
13-
14-
return filteredObj;
1513
}
1614

1715
// Detects duplicates in array of object properties
@@ -120,11 +118,7 @@ function removeParentFromAllOf(child, parentName) {
120118
return objName !== parentName;
121119
});
122120

123-
if (initialLength === child.allOf.length) {
124-
return false;
125-
}
126-
127-
return true;
121+
return initialLength !== child.allOf.length;
128122
}
129123

130124
// For string reference fetch object from openapi
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Remove all AdditonalProperties object section
2+
* Remove all AdditionalProperties object section
33
* That generates an map[string]map[string]string objects for SDK
44
* but for our API much safer is to rely on the map[string]any
55
* This is due to the fact that dynamic field can be array which would
@@ -8,20 +8,20 @@
88
* @param modelNames
99
* @returns OpenAPI JSON File
1010
*/
11-
function applyRemoveObjectAdditonalProperties(api) {
11+
function applyRemoveObjectAdditionalProperties(api) {
1212
const hasSchemas = api && api.components && api.components.schemas;
1313
if (!hasSchemas) {
1414
throw new Error("Missing schemas in openapi");
1515
}
1616
// Recursive function to traverse the OpenAPI object
17-
function removeObjectAdditonalProperties(obj) {
17+
function removeObjectAdditionalProperties(obj) {
1818
if (typeof obj !== "object" || obj === null) {
1919
return;
2020
}
2121

2222
if (Array.isArray(obj)) {
2323
for (let i = 0; i < obj.length; i++) {
24-
removeObjectAdditonalProperties(obj[i]);
24+
removeObjectAdditionalProperties(obj[i]);
2525
}
2626
} else {
2727
// Remove enum field if present
@@ -34,17 +34,17 @@ function applyRemoveObjectAdditonalProperties(api) {
3434
// Traverse nested properties
3535
for (const prop in obj) {
3636
if (obj.hasOwnProperty(prop)) {
37-
removeObjectAdditonalProperties(obj[prop]);
37+
removeObjectAdditionalProperties(obj[prop]);
3838
}
3939
}
4040
}
4141
}
4242

4343
// Start removing enum fields from the OpenAPI object
44-
removeObjectAdditonalProperties(api);
44+
removeObjectAdditionalProperties(api);
4545
return api;
4646
}
4747

4848
module.exports = {
49-
applyRemoveObjectAdditonalProperties,
49+
applyRemoveObjectAdditionalProperties: applyRemoveObjectAdditionalProperties,
5050
};

tools/transformer/src/transformations/anyOf.js

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ const { detectDuplicates } = require("../engine/transformers");
1010
* Transforms provided API JSON file using anyOf transformation
1111
*
1212
* @param {*} api OpenAPI JSON File
13-
* @param {*} anyOfTransformations array of transformations to apply
1413
* @returns OpenAPI JSON File
1514
*/
1615
function applyAnyOfTransformations(api) {
1716
const anyOfTransformations = getAllObjects(api, (obj) => {
1817
return canApplyAnyOfTransformation(obj, api);
1918
});
2019

21-
transformationPaths = anyOfTransformations.map((e) => e.path);
20+
const transformationPaths = anyOfTransformations.map((e) => e.path);
2221

2322
console.info(
2423
"# AnyOf transformations: " +
@@ -81,7 +80,7 @@ function transformAnyOfEnum(parentObject, api) {
8180
delete parentObject.anyOf;
8281
}
8382

84-
// Moves all the propertis of the children into the parent
83+
// Moves all the properties of the children into the parent
8584
function transformAnyOfProperties(parentObject, api) {
8685
const childObjects = parentObject.anyOf.map((childRef) =>
8786
getObjectFromReference(childRef, api),
@@ -129,11 +128,8 @@ function transformAnyOfProperties(parentObject, api) {
129128
delete parentObject.anyOf;
130129
}
131130

132-
function canApplyAnyOfTransformation(obj, api) {
133-
if (obj.anyOf) {
134-
return true;
135-
}
136-
return false;
131+
function canApplyAnyOfTransformation(obj, _) {
132+
return !!obj.anyOf;
137133
}
138134

139135
module.exports = {

tools/transformer/src/transformations/discriminator.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ function transformDiscriminatorOneOf(objectPath, api) {
4747
`Setting oneOf based on discriminator for allOf transformation in ${parentName}`,
4848
);
4949
// Ignore objects that point to themselves
50-
oneOfReferences = Object.values(parentObject.discriminator.mapping);
51-
// Remove duplicates in referneces
50+
let oneOfReferences = Object.values(parentObject.discriminator.mapping);
51+
// Remove duplicates in references
5252
oneOfReferences = [...new Set(oneOfReferences)];
5353

5454
for (referenceObj of oneOfReferences) {
55-
if (getObjectNameFromReferenceString(referenceObj) == parentName) {
55+
if (getObjectNameFromReferenceString(referenceObj) === parentName) {
5656
if (isModelIgnored(parentName, ignoreModels)) {
5757
console.warn("Ignored discriminator reference for: " + parentName);
5858
return;

tools/transformer/src/transformations/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const { applyDiscriminatorTransformations } = require("./discriminator");
99
const { applyArrayTransformations } = require("./swapArray");
1010
const { applyRemoveEnumsTransformations } = require("./removeEnums");
1111
const {
12-
applyRemoveObjectAdditonalProperties,
12+
applyRemoveObjectAdditionalProperties,
1313
} = require("./additionalPropertiesObject");
1414
const { applyAnyOfTransformations } = require("./anyOf");
1515
const { applyRemoveNullableTransformations } = require("./removeNullable");
@@ -26,7 +26,7 @@ module.exports = {
2626
applyDiscriminatorTransformations,
2727
applyArrayTransformations,
2828
applyRemoveEnumsTransformations,
29-
applyRemoveObjectAdditonalProperties,
29+
applyRemoveObjectAdditionalProperties,
3030
applyAnyOfTransformations,
3131
applyRemoveNullableTransformations,
3232
removeRefsFromParameters,

tools/transformer/src/transformations/oneOf.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@ const { detectDuplicates } = require("../engine/transformers");
1313
* Transforms provided API JSON file using oneOf transformation
1414
*
1515
* @param {*} api OpenAPI JSON File
16-
* @param {*} oneOfTransformations array of transformations to apply
1716
* @returns OpenAPI JSON File
1817
*/
1918
function applyOneOfTransformations(api) {
2019
const oneOfTransformations = getAllObjects(api, (obj) => {
2120
return canApplyOneOfTransformation(obj, api);
2221
}).filter((e) => !ignoreModels.includes(e.path));
2322

24-
transformationPaths = oneOfTransformations.map((e) => e.path);
23+
const transformationPaths = oneOfTransformations.map((e) => e.path);
2524
console.info(
2625
"# OneOf transformations: " +
2726
JSON.stringify(transformationPaths, undefined, 2),
@@ -83,7 +82,7 @@ function transformOneOfEnum(parentObject, api) {
8382
delete parentObject.oneOf;
8483
}
8584

86-
// Moves all the propertis of the children into the parent
85+
// Moves all the properties of the children into the parent
8786
function transformOneOfProperties(parentObject, api) {
8887
const childObjects = parentObject.oneOf.map((childRef) =>
8988
getObjectFromReference(childRef, api),
@@ -153,7 +152,7 @@ function handleDuplicates(parentObject, childObject) {
153152
}
154153
}
155154

156-
// Uses ignore list for known missmatches and removes them
155+
// Uses ignore list for known mismatches and removes them
157156
function filterReferenceOrTypeMissmatch(mismatches) {
158157
return mismatches.filter((mismatch) => {
159158
for (const ignoredProperty of ignoredProperties) {
@@ -183,8 +182,8 @@ function mergeDuplicates(
183182
)}\n`,
184183
);
185184
for (duplicate of duplicates) {
186-
childProperty = childObject.properties[duplicate.key];
187-
parentProperty = parentObject.properties[duplicate.key];
185+
const childProperty = childObject.properties[duplicate.key];
186+
const parentProperty = parentObject.properties[duplicate.key];
188187

189188
if (
190189
parentProperty.description &&
@@ -195,10 +194,7 @@ function mergeDuplicates(
195194
}
196195

197196
function canApplyOneOfTransformation(obj, api) {
198-
if (obj.oneOf) {
199-
return true;
200-
}
201-
return false;
197+
return !!obj.oneOf;
202198
}
203199

204200
module.exports = {

0 commit comments

Comments
 (0)