Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK-9667: small refactoring #47

Merged
merged 5 commits into from
Feb 5, 2025
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
4 changes: 2 additions & 2 deletions forward_engineering/helpers/commonHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function mapExternalDocs({ externalDocsUrl, externalDocsDescription, scopesExten
};
const externalDocsExtensions = getExtensions(scopesExtensions);

return Object.assign({}, externalDocs, externalDocsExtensions);
return { ...externalDocs, ...externalDocsExtensions };
}

function mapExternalTagDocs({ tagExternalDocsUrl, tagExternalDocsDescription } = {}) {
Expand All @@ -44,7 +44,7 @@ function mapTags(tags = []) {
};
const tagExtensions = getExtensions(tag.scopesExtensions);

return Object.assign({}, tagObj, tagExtensions);
return { ...tagObj, ...tagExtensions };
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function mapExample(data) {
};
const extensions = getExtensions(scopesExtensions);

return Object.assign({}, example, extensions);
return { ...example, ...extensions };
}

module.exports = {
Expand Down
14 changes: 7 additions & 7 deletions forward_engineering/helpers/componentsHelpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const renameComponents = components => {
}

return Object.keys(components).reduce((result, componentName) => {
return Object.assign({}, result, {
return {
...result,
[prepareName(componentName)]: components[componentName],
});
};
}, {});
};

Expand All @@ -37,9 +38,8 @@ function getComponents(definitions, containers) {

const extensions = getExtensions(get(componentsData, `['Specification Extensions'].scopesExtensions`));

return Object.assign(
{},
{
return {
...{
schemas,
responses,
parameters,
Expand All @@ -50,8 +50,8 @@ function getComponents(definitions, containers) {
links,
callbacks,
},
extensions,
);
...extensions,
};
}

module.exports = getComponents;
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function mapLink(data) {
};
const extensions = getExtensions(scopesExtensions);

return Object.assign({}, linkData, extensions);
return { ...linkData, ...extensions };
}

function mapParameters(data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function mapParameter(data, required, isParentActivated = false) {
};
const extensions = getExtensions(data.scopesExtensions);

return commentDeactivatedItemInner(Object.assign({}, parameter, extensions), data.isActivated, isParentActivated);
return commentDeactivatedItemInner({ ...parameter, ...extensions }, data.isActivated, isParentActivated);
}

function getIn(parameterType) {
Expand Down Expand Up @@ -164,7 +164,7 @@ function mapMediaTypeObject(data, isParentActivated = false) {
const mediaTypeObj = { schema, examples, encoding, example };
const extensions = getExtensions(data.scopesExtensions);

return Object.assign({}, mediaTypeObj, extensions);
return { ...mediaTypeObj, ...extensions };
}

function mapEncoding(data) {
Expand All @@ -183,7 +183,7 @@ function mapEncoding(data) {
};
const extensions = getExtensions(value.scopesExtensions);

return { key, value: Object.assign({}, encodingObj, extensions) };
return { key, value: { ...encodingObj, ...extensions } };
})
.reduce((acc, { key, value }) => {
acc[key] = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function mapRequestBody(data, required, isParentActivated = false) {
};
const extensions = getExtensions(data.scopesExtensions);

return commentDeactivatedItemInner(Object.assign({}, requestBody, extensions), data.isActivated, isParentActivated);
return commentDeactivatedItemInner({ ...requestBody, ...extensions }, data.isActivated, isParentActivated);
}

module.exports = {
Expand Down
14 changes: 8 additions & 6 deletions forward_engineering/helpers/componentsHelpers/responsesHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ function mapResponse(data, responseCollectionDescription, shouldResponseBeCommen
const content = getContent(get(data, `properties.content`), !shouldResponseBeCommented);
const links = getLinks(get(data, `properties.links`));
const extensions = getExtensions(data.scopesExtensions);
const response = {};
if (shouldResponseBeCommented) {
response[`hackoladeInnerCommentStart`] = true;
}

Object.assign(response, { description, headers, content, links }, extensions);
const response = {
...(shouldResponseBeCommented && { hackoladeInnerCommentStart: true }),
description,
headers,
content,
links,
...extensions,
};

if (shouldResponseBeCommented) {
response[`hackoladeInnerCommentEnd`] = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const cleanUp = obj => {
return acc;
}

return Object.assign({}, acc, { [key]: value });
return { ...acc, [key]: value };
}, {});
}

Expand Down Expand Up @@ -87,7 +87,7 @@ function mapSecurityScheme(data) {
};
const extensions = getExtensions(data.scopesExtensions);

return Object.assign({}, securitySchemeProps, commonFields, extensions);
return { ...securitySchemeProps, ...commonFields, ...extensions };
}

function mapOAuthFlows(data) {
Expand All @@ -110,7 +110,7 @@ function mapOAuthFlows(data) {

const extensions = getExtensions(data.scopesExtensions);

return cleanUp(Object.assign({}, flows, extensions));
return cleanUp({ ...flows, ...extensions });
}

function mapOAuthFlowObject({ authorizationUrl, tokenUrl, refreshUrl, scopes, scopesExtensions }) {
Expand All @@ -122,7 +122,7 @@ function mapOAuthFlowObject({ authorizationUrl, tokenUrl, refreshUrl, scopes, sc
};
const extensions = getExtensions(scopesExtensions);

return Object.assign({}, flow, extensions);
return { ...flow, ...extensions };
}

function mapScopes(data) {
Expand Down
6 changes: 3 additions & 3 deletions forward_engineering/helpers/infoHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getInfo({ description, version, modelVersion, title = '', termsOfServic
};

const extensions = getExtensions(infoExtensions);
return Object.assign({}, info, extensions);
return { ...info, ...extensions };
}

function getContact(contact) {
Expand All @@ -26,7 +26,7 @@ function getContact(contact) {
};
const extensions = getExtensions(contact.contactExtensions);

return Object.assign({}, contactObj, extensions);
return { ...contactObj, ...extensions };
}

function getLicense(license) {
Expand All @@ -40,7 +40,7 @@ function getLicense(license) {
};
const extensions = getExtensions(license.contactExtensions);

return Object.assign({}, licenseObject, extensions);
return { ...licenseObject, ...extensions };
}

module.exports = getInfo;
8 changes: 3 additions & 5 deletions forward_engineering/helpers/pathHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { mapParameter } = require('./componentsHelpers/parametersHelper');
const { mapRequestBody } = require('./componentsHelpers/requestBodiesHelper');
const { mapResponse } = require('./componentsHelpers/responsesHelper');
const { hasRef, getRef } = require('./typeHelper');
const { commentDeactivatedItemInner } = require('./commentsHelper');

function getPaths(containers, containersIdsForCallbacks = []) {
return containers
Expand Down Expand Up @@ -40,7 +39,7 @@ function getRequestsForContainer(container, containers, containersPath = [], isP

const containerExtensions = getExtensions(contactExtensions);

return Object.assign({}, containerData, additionalContainerData, containerExtensions);
return { ...containerData, ...additionalContainerData, ...containerExtensions };
}

function getRequestData(collections, containers, containerId, containersPath = [], isPathActivated = true) {
Expand Down Expand Up @@ -78,7 +77,7 @@ function getRequestData(collections, containers, containerId, containersPath = [
isActivated: data.isActivated,
};

return Object.assign({}, request, extensions);
return { ...request, ...extensions };
})
.reduce((acc, collection, index) => {
const { methodName, isActivated } = collection;
Expand Down Expand Up @@ -159,8 +158,7 @@ function getCallbacks(data, containers, containerId, containersPath = []) {
return { [key]: { [value.callbackExpression]: callbackData, ...extensions } };
})
.reduce((acc, item) => {
acc = Object.assign({}, acc, item);
return acc;
return { ...acc, ...item };
}, {});
}

Expand Down
6 changes: 3 additions & 3 deletions forward_engineering/helpers/serversHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function mapServer(data) {
};
const extensions = getExtensions(data.scopesExtensions);

return Object.assign({}, serverData, extensions);
return { ...serverData, ...extensions };
}

function mapVariables(variables = []) {
Expand All @@ -37,13 +37,13 @@ function mapVariables(variables = []) {
};
const variableExtensions = getExtensions(item.scopesExtensions);

return Object.assign({}, variable, variableExtensions);
return { ...variable, ...variableExtensions };
})
.reduce((acc, item) => {
const { name } = item;
delete item.name;

return Object.assign({}, acc, { [name]: item });
return { ...acc, [name]: item };
}, {});
}

Expand Down
24 changes: 10 additions & 14 deletions forward_engineering/helpers/typeHelper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const get = require('lodash.get');
const getExtensions = require('./extensionsHelper');
const { prepareReferenceName } = require('../utils/utils');
const { commentDeactivatedItemInner } = require('./commentsHelper');

function getType(data, key, isParentActivated = false) {
Expand All @@ -9,7 +8,7 @@ function getType(data, key, isParentActivated = false) {
}

if (Array.isArray(data.type)) {
return getType(Object.assign({}, data, { type: data.type[0] }), '', isParentActivated);
return getType({ ...data, type: data.type[0] }, '', isParentActivated);
}

if (hasRef(data)) {
Expand Down Expand Up @@ -43,7 +42,7 @@ function getTypeProps(data, key, isParentActivated) {
};
const arrayChoices = getChoices(data, key);

return Object.assign({}, arrayProps, arrayChoices, extensions);
return { ...arrayProps, ...arrayChoices, ...extensions };
}
case 'object': {
const objectProps = {
Expand All @@ -63,7 +62,7 @@ function getTypeProps(data, key, isParentActivated) {
};
const objectChoices = getChoices(data, key);

return Object.assign({}, objectProps, objectChoices, extensions);
return { ...objectProps, ...objectChoices, ...extensions };
}
case 'parameter':
if (!properties || properties.length === 0) {
Expand All @@ -85,9 +84,9 @@ function hasRef(data = {}) {

function getArrayItemsType(items, isParentActivated) {
if (Array.isArray(items)) {
return Object.assign({}, items.length > 0 ? getType(items[0], '', isParentActivated) : {});
return { ...(items.length > 0 ? getType(items[0], '', isParentActivated) : {}) };
}
return Object.assign({}, items ? getType(items, '', isParentActivated) : {});
return { ...(items ? getType(items, '', isParentActivated) : {}) };
}

function getObjectProperties(properties, isParentActivated) {
Expand All @@ -110,17 +109,16 @@ function getXml(data) {
return undefined;
}

return Object.assign(
{},
{
return {
...{
name: data.xmlName,
namespace: data.xmlNamespace,
prefix: data.xmlPrefix,
attribute: data.xmlAttribute,
wrapped: data.xmlWrapped,
},
getExtensions(data.scopesExtensions),
);
...getExtensions(data.scopesExtensions),
};
}

function getPrimitiveTypeProps(data) {
Expand Down Expand Up @@ -225,9 +223,7 @@ function addIfTrue(data, propertyName, value) {
return data;
}

return Object.assign({}, data, {
[propertyName]: value,
});
return { ...data, [propertyName]: value };
}

function getArrayItemsExample(items) {
Expand Down
6 changes: 2 additions & 4 deletions forward_engineering/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ function removeEmptyObjectFields(inputObj) {
.reduce((newObj, key) => {
const isObjectAndNotArray = typeof obj[key] === 'object' && !Array.isArray(obj[key]);
if (isObjectAndNotArray) {
return Object.assign(newObj, {
[key]: removeEmptyObjectFields(obj[key]),
});
return { ...newObj, [key]: removeEmptyObjectFields(obj[key]) };
}
return Object.assign(newObj, { [key]: obj[key] });
return { ...newObj, [key]: obj[key] };
}, {});
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ const mapJsonSchema = require('./mapJsonSchema');
const commonHelper = require('../commonHelper');

const convertToString = jsonSchema => {
return Object.assign({}, jsonSchema, {
return {
...jsonSchema,
type: 'string',
nullable: true,
});
};
};

const convertMultipleTypeToType = jsonSchema => {
Expand Down
Loading