From b99cd5b65e28ee79dcb6de3f5b7e2b91383ad329 Mon Sep 17 00:00:00 2001 From: Sora Morimoto Date: Sun, 11 Aug 2024 09:25:25 +0900 Subject: [PATCH] Fix build warnings Signed-off-by: Sora Morimoto --- cli/execute.js | 6 +- cli/index.js | 8 +- cli/operations/display-help.js | 53 +++--- cli/process-option.js | 14 +- src/code-formatter.js | 36 ++-- src/code-gen-process.js | 60 ++++--- src/configuration.js | 45 +++-- src/schema-components-map.js | 6 +- .../base-schema-parsers/array.js | 6 +- .../base-schema-parsers/complex.js | 16 +- .../base-schema-parsers/discriminator.js | 32 ++-- src/schema-parser/base-schema-parsers/enum.js | 24 ++- .../base-schema-parsers/object.js | 20 +-- .../base-schema-parsers/primitive.js | 12 +- .../complex-schema-parsers/all-of.js | 4 +- .../complex-schema-parsers/any-of.js | 4 +- .../complex-schema-parsers/one-of.js | 4 +- src/schema-parser/schema-formatters.js | 27 +-- src/schema-parser/schema-parser-fabric.js | 4 +- src/schema-parser/schema-parser.js | 10 +- src/schema-parser/schema-utils.js | 52 +++--- src/schema-routes/schema-routes.js | 169 ++++++++++-------- src/schema-walker.js | 6 +- src/swagger-schema-resolver.js | 52 +++--- src/templates-worker.js | 28 +-- src/translators/javascript.js | 23 ++- src/type-name-formatter.js | 10 +- src/util/file-system.js | 10 +- src/util/id.js | 4 +- src/util/internal-case.js | 4 +- src/util/logger.js | 14 +- src/util/name-resolver.js | 13 +- src/util/object-assign.js | 11 +- src/util/pascal-case.js | 4 +- src/util/request.js | 6 +- 35 files changed, 428 insertions(+), 369 deletions(-) diff --git a/cli/execute.js b/cli/execute.js index e0bed487..481845fa 100644 --- a/cli/execute.js +++ b/cli/execute.js @@ -1,5 +1,5 @@ import didYouMean from "didyoumean"; -import _ from "lodash"; +import * as lodash from "lodash"; import { root_command, skip_command } from "./constants.js"; import { parseArgs } from "./parse-args.js"; @@ -98,14 +98,14 @@ const processArgs = (commands, args) => { let allFlagKeys = []; - _.forEach(args, (arg, i) => { + lodash.forEach(args, (arg, i) => { if (error) return; if (i === 0) { command = commands[arg]; if (!command && !arg.startsWith("-")) { - const tip = didYouMean(arg, _.keys(commands)); + const tip = didYouMean(arg, lodash.keys(commands)); error = `unknown command ${arg}${ tip ? `\n(Did you mean ${tip} ?)` : "" }`; diff --git a/cli/index.js b/cli/index.js index a5b818a5..f3954397 100644 --- a/cli/index.js +++ b/cli/index.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { reservedOptions, root_command } from "./constants.js"; import { execute } from "./execute.js"; import { displayHelp } from "./operations/display-help.js"; @@ -12,7 +12,7 @@ const cli = (input) => { commands[command.name] = { name: command.name, description: `${command.description || ""}`, - options: _.compact(_.map(command.options, processOption)), + options: lodash.compact(lodash.map(command.options, processOption)), }; if (addVersion) { @@ -57,7 +57,7 @@ const cli = (input) => { }, ); - _.forEach(input.options, (option) => { + lodash.forEach(input.options, (option) => { const processed = processOption(option); if (!processed) return; @@ -86,7 +86,7 @@ const cli = (input) => { }), ); - _.forEach(input.commands, addCommand); + lodash.forEach(input.commands, addCommand); return instance; }; diff --git a/cli/operations/display-help.js b/cli/operations/display-help.js index f9d8beb2..ebd35ec0 100644 --- a/cli/operations/display-help.js +++ b/cli/operations/display-help.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { root_command } from "../constants.js"; const generateOptionsOutput = (options) => @@ -62,32 +62,31 @@ const displayAllHelp = (commands, instance) => { commands[root_command].options, ); - const { commands: commandLabels, maxLength: maxCommandLength } = _.filter( - commands, - (command) => command.name !== root_command, - ).reduce( - (acc, command) => { - const options = generateOptionsOutput(command.options); - const name = `${command.name}${options.length ? " [options]" : ""}`; - const description = command.description; - - const maxLength = Math.max(name.length, options.maxLength); - if (maxLength > acc.maxLength) { - acc.maxLength = maxLength; - } - - acc.commands.push({ - description, - name, - options, - }); - return acc; - }, - { - commands: [], - maxLength: maxOptionLength, - }, - ); + const { commands: commandLabels, maxLength: maxCommandLength } = lodash + .filter(commands, (command) => command.name !== root_command) + .reduce( + (acc, command) => { + const options = generateOptionsOutput(command.options); + const name = `${command.name}${options.length ? " [options]" : ""}`; + const description = command.description; + + const maxLength = Math.max(name.length, options.maxLength); + if (maxLength > acc.maxLength) { + acc.maxLength = maxLength; + } + + acc.commands.push({ + description, + name, + options, + }); + return acc; + }, + { + commands: [], + maxLength: maxOptionLength, + }, + ); const optionsOutput = generateOptionsTextOutput(options, maxOptionLength, 2); diff --git a/cli/process-option.js b/cli/process-option.js index ab8a1de1..571ecc59 100644 --- a/cli/process-option.js +++ b/cli/process-option.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; const optionFormatters = { number: (str) => +str, @@ -15,8 +15,9 @@ const processFlags = (flags) => { let value = null; const isNoFlag = flags.includes("--no-"); - _.compact(_.split(flags, " ").map((str) => str.replace(/,/g, ""))).forEach( - (str) => { + lodash + .compact(lodash.split(flags, " ").map((str) => str.replace(/,/g, ""))) + .forEach((str) => { if (str.startsWith("-")) { keys.push(str); } else if (value === null) { @@ -31,13 +32,12 @@ const processFlags = (flags) => { }; } } - }, - ); + }); const longestKey = keys.slice().sort((a, b) => b.length - a.length)[0]; - if (!_.isEmpty(longestKey)) { - name = _.camelCase( + if (!lodash.isEmpty(longestKey)) { + name = lodash.camelCase( (isNoFlag ? longestKey.replace("--no-", "") : longestKey).replace( /(--?)/, "", diff --git a/src/code-formatter.js b/src/code-formatter.js index 619f8493..d3d21bb3 100644 --- a/src/code-formatter.js +++ b/src/code-formatter.js @@ -1,6 +1,6 @@ -import _ from "lodash"; -import prettier from "prettier"; -import ts from "typescript"; +import * as lodash from "lodash"; +import * as prettier from "prettier"; +import * as typescript from "typescript"; class CodeFormatter { /** @@ -16,15 +16,15 @@ class CodeFormatter { const tempFileName = "file.ts"; const host = new TsLanguageServiceHost(tempFileName, content); - const languageService = ts.createLanguageService(host); + const languageService = typescript.createLanguageService(host); const fileTextChanges = languageService.organizeImports( { type: "file", fileName: tempFileName }, - { newLineCharacter: ts.sys.newLine }, + { newLineCharacter: typescript.sys.newLine }, )[0]; if (fileTextChanges?.textChanges.length) { - return _.reduceRight( + return lodash.reduceRight( fileTextChanges.textChanges, (content, { span, newText }) => `${content.slice(0, span.start)}${newText}${content.slice( @@ -65,21 +65,25 @@ class CodeFormatter { class TsLanguageServiceHost { constructor(fileName, content) { - const tsconfig = ts.findConfigFile(fileName, ts.sys.fileExists); + const tsconfig = typescript.findConfigFile( + fileName, + typescript.sys.fileExists, + ); Object.assign(this, { fileName, content, compilerOptions: tsconfig - ? ts.convertCompilerOptionsFromJson( - ts.readConfigFile(tsconfig, ts.sys.readFile).config.compilerOptions, + ? typescript.convertCompilerOptionsFromJson( + typescript.readConfigFile(tsconfig, typescript.sys.readFile).config + .compilerOptions, ).options - : ts.getDefaultCompilerOptions(), + : typescript.getDefaultCompilerOptions(), }); } getNewLine() { - return "newLine" in ts.sys ? ts.sys.newLine : "\n"; + return "newLine" in typescript.sys ? typescript.sys.newLine : "\n"; } getScriptFileNames() { return [this.fileName]; @@ -88,26 +92,26 @@ class TsLanguageServiceHost { return this.compilerOptions; } getDefaultLibFileName() { - return ts.getDefaultLibFileName(this.getCompilationSettings()); + return typescript.getDefaultLibFileName(this.getCompilationSettings()); } getCurrentDirectory() { return process.cwd(); } getScriptVersion() { - return ts.version; + return typescript.version; } getScriptSnapshot() { - return ts.ScriptSnapshot.fromString(this.content); + return typescript.ScriptSnapshot.fromString(this.content); } readFile(fileName, encoding) { if (fileName === this.fileName) { return this.content; } - return ts.sys.readFile(fileName, encoding); + return typescript.sys.readFile(fileName, encoding); } fileExists(path) { - return ts.sys.fileExists(path); + return typescript.sys.fileExists(path); } } diff --git a/src/code-gen-process.js b/src/code-gen-process.js index 712fe256..568a9c39 100644 --- a/src/code-gen-process.js +++ b/src/code-gen-process.js @@ -1,5 +1,5 @@ -import _ from "lodash"; -import ts from "typescript"; +import * as lodash from "lodash"; +import * as typescript from "typescript"; import { CodeFormatter } from "./code-formatter.js"; import { CodeGenConfig } from "./configuration.js"; import { SchemaComponentsMap } from "./schema-components-map.js"; @@ -103,8 +103,8 @@ class CodeGenProcess { this.schemaComponentsMap.clear(); - _.each(swagger.usageSchema.components, (component, componentName) => - _.each(component, (rawTypeData, typeName) => { + lodash.each(swagger.usageSchema.components, (component, componentName) => + lodash.each(component, (rawTypeData, typeName) => { this.schemaComponentsMap.createComponent( this.schemaComponentsMap.createRef([ "components", @@ -120,7 +120,7 @@ class CodeGenProcess { * @type {SchemaComponent[]} */ const componentsToParse = this.schemaComponentsMap.filter( - _.compact(["schemas", this.config.extractResponses && "responses"]), + lodash.compact(["schemas", this.config.extractResponses && "responses"]), ); const parsedSchemas = componentsToParse.map((schemaComponent) => { @@ -228,7 +228,7 @@ class CodeGenProcess { return ` * ${line}${eol ? "\n" : ""}`; }, NameResolver: NameResolver, - _, + _: lodash, require: this.templatesWorker.requireFnFromTemplate, }, config: this.config, @@ -239,7 +239,7 @@ class CodeGenProcess { const components = this.schemaComponentsMap.getComponents(); let modelTypes = []; - const modelTypeComponents = _.compact([ + const modelTypeComponents = lodash.compact([ "schemas", this.config.extractResponses && "responses", ]); @@ -322,7 +322,7 @@ class CodeGenProcess { ? await this.createMultipleFileInfos(templatesToRender, configuration) : await this.createSingleFileInfo(templatesToRender, configuration); - if (!_.isEmpty(configuration.extraTemplates)) { + if (!lodash.isEmpty(configuration.extraTemplates)) { for (const extraTemplate of configuration.extraTemplates) { const content = this.templatesWorker.renderTemplate( this.fileSystem.getFileContent(extraTemplate.path), @@ -467,27 +467,29 @@ class CodeGenProcess { return await this.createOutputFileInfo( configuration, configuration.fileName, - _.compact([ - this.templatesWorker.renderTemplate( - templatesToRender.dataContracts, - configuration, - ), - generateRouteTypes && - this.templatesWorker.renderTemplate( - templatesToRender.routeTypes, - configuration, - ), - generateClient && - this.templatesWorker.renderTemplate( - templatesToRender.httpClient, - configuration, - ), - generateClient && + lodash + .compact([ this.templatesWorker.renderTemplate( - templatesToRender.api, + templatesToRender.dataContracts, configuration, ), - ]).join("\n"), + generateRouteTypes && + this.templatesWorker.renderTemplate( + templatesToRender.routeTypes, + configuration, + ), + generateClient && + this.templatesWorker.renderTemplate( + templatesToRender.httpClient, + configuration, + ), + generateClient && + this.templatesWorker.renderTemplate( + templatesToRender.api, + configuration, + ), + ]) + .join("\n"), ); }; @@ -500,7 +502,7 @@ class CodeGenProcess { */ createOutputFileInfo = async (configuration, fileNameFull, content) => { const fileName = this.fileSystem.cropExtension(fileNameFull); - const fileExtension = ts.Extension.Ts; + const fileExtension = typescript.Extension.Ts; if (configuration.translateToJavaScript) { this.logger.debug("using js translator for", fileName); @@ -542,14 +544,14 @@ class CodeGenProcess { servers: servers || [], basePath, host, - externalDocs: _.merge( + externalDocs: lodash.merge( { url: "", description: "", }, externalDocs, ), - tags: _.compact(tags), + tags: lodash.compact(tags), baseUrl: serverUrl, title, version, diff --git a/src/configuration.js b/src/configuration.js index 15a6c53b..3e30c73e 100644 --- a/src/configuration.js +++ b/src/configuration.js @@ -1,6 +1,6 @@ -import { cosmiconfigSync } from "cosmiconfig"; -import _ from "lodash"; -import ts from "typescript"; +import * as cosmiconfig from "cosmiconfig"; +import * as lodash from "lodash"; +import * as typescript from "typescript"; import { ComponentTypeNameResolver } from "./component-type-name-resolver.js"; import * as CONSTANTS from "./constants.js"; import { objectAssign } from "./util/object-assign.js"; @@ -197,10 +197,10 @@ class CodeGenConfig { }; compilerTsConfig = { - module: ts.ModuleKind.ESNext, + module: typescript.ModuleKind.ESNext, noImplicitReturns: true, alwaysStrict: true, - target: ts.ScriptTarget.ESNext, + target: typescript.ScriptTarget.ESNext, declaration: true, noImplicitAny: false, sourceMap: false, @@ -213,8 +213,8 @@ class CodeGenConfig { customTranslator; Ts = { - Keyword: _.cloneDeep(TsKeyword), - CodeGenKeyword: _.cloneDeep(TsCodeGenKeyword), + Keyword: lodash.cloneDeep(TsKeyword), + CodeGenKeyword: lodash.cloneDeep(TsCodeGenKeyword), /** * $A[] or Array<$A> */ @@ -245,7 +245,7 @@ class CodeGenConfig { * $A1 | $A2 */ UnionType: (contents) => - _.join(_.uniq(contents), ` ${this.Ts.Keyword.Union} `), + lodash.join(lodash.uniq(contents), ` ${this.Ts.Keyword.Union} `), /** * ($A1) */ @@ -254,7 +254,7 @@ class CodeGenConfig { * $A1 & $A2 */ IntersectionType: (contents) => - _.join(_.uniq(contents), ` ${this.Ts.Keyword.Intersection} `), + lodash.join(lodash.uniq(contents), ` ${this.Ts.Keyword.Intersection} `), /** * Record<$A1, $A2> */ @@ -264,13 +264,9 @@ class CodeGenConfig { * readonly $key?:$value */ TypeField: ({ readonly, key, optional, value }) => - _.compact([ - readonly && "readonly ", - key, - optional && "?", - ": ", - value, - ]).join(""), + lodash + .compact([readonly && "readonly ", key, optional && "?", ": ", value]) + .join(""), /** * [key: $A1]: $A2 */ @@ -290,10 +286,9 @@ class CodeGenConfig { * $AN.key = $AN.value, */ EnumFieldsWrapper: (contents) => - _.map( - contents, - ({ key, value }) => ` ${this.Ts.EnumField(key, value)}`, - ).join(",\n"), + lodash + .map(contents, ({ key, value }) => ` ${this.Ts.EnumField(key, value)}`) + .join(",\n"), /** * {\n $A \n} */ @@ -397,7 +392,7 @@ class CodeGenConfig { prettierOptions === undefined ? getDefaultPrettierOptions() : prettierOptions, - hooks: _.merge(this.hooks, hooks || {}), + hooks: lodash.merge(this.hooks, hooks || {}), constants: { ...CONSTANTS, ...constants, @@ -428,9 +423,11 @@ class CodeGenConfig { } const getDefaultPrettierOptions = () => { - const prettier = cosmiconfigSync("prettier", { - searchStrategy: "global", - }).search(); + const prettier = cosmiconfig + .cosmiconfigSync("prettier", { + searchStrategy: "global", + }) + .search(); if (prettier) { return { diff --git a/src/schema-components-map.js b/src/schema-components-map.js index f0b6130b..db9bcf65 100644 --- a/src/schema-components-map.js +++ b/src/schema-components-map.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; class SchemaComponentsMap { /** @type {SchemaComponent[]} */ @@ -61,9 +61,9 @@ class SchemaComponentsMap { * @returns {SchemaComponent[]} */ filter(...componentNames) { - return _.filter(this._data, (it) => + return lodash.filter(this._data, (it) => componentNames.some((componentName) => - _.startsWith(it.$ref, `#/components/${componentName}`), + lodash.startsWith(it.$ref, `#/components/${componentName}`), ), ); } diff --git a/src/schema-parser/base-schema-parsers/array.js b/src/schema-parser/base-schema-parsers/array.js index 073386e8..76595e96 100644 --- a/src/schema-parser/base-schema-parsers/array.js +++ b/src/schema-parser/base-schema-parsers/array.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../../constants.js"; import { MonoSchemaParser } from "../mono-schema-parser.js"; @@ -7,7 +7,7 @@ class ArraySchemaParser extends MonoSchemaParser { let contentType; const { type, description, items } = this.schema || {}; - if (_.isArray(items) && type === SCHEMA_TYPES.ARRAY) { + if (lodash.isArray(items) && type === SCHEMA_TYPES.ARRAY) { const tupleContent = []; for (const item of items) { tupleContent.push( @@ -25,7 +25,7 @@ class ArraySchemaParser extends MonoSchemaParser { } return { - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), $schemaPath: this.schemaPath.slice(), $parsedSchema: true, schemaType: SCHEMA_TYPES.PRIMITIVE, diff --git a/src/schema-parser/base-schema-parsers/complex.js b/src/schema-parser/base-schema-parsers/complex.js index 08d15c49..c00baff7 100644 --- a/src/schema-parser/base-schema-parsers/complex.js +++ b/src/schema-parser/base-schema-parsers/complex.js @@ -1,20 +1,20 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../../constants.js"; import { MonoSchemaParser } from "../mono-schema-parser.js"; class ComplexSchemaParser extends MonoSchemaParser { parse() { const complexType = this.schemaUtils.getComplexType(this.schema); - const simpleSchema = _.omit( - _.clone(this.schema), - _.keys(this.schemaParser._complexSchemaParsers), + const simpleSchema = lodash.omit( + lodash.clone(this.schema), + lodash.keys(this.schemaParser._complexSchemaParsers), ); const complexSchemaContent = this.schemaParser._complexSchemaParsers[ complexType ](this.schema); return { - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), $schemaPath: this.schemaPath.slice(), $parsedSchema: true, schemaType: SCHEMA_TYPES.COMPLEX, @@ -23,12 +23,14 @@ class ComplexSchemaParser extends MonoSchemaParser { name: this.typeName, description: this.schemaFormatters.formatDescription( this.schema.description || - _.compact(_.map(this.schema[complexType], "description"))[0] || + lodash.compact( + lodash.map(this.schema[complexType], "description"), + )[0] || "", ), content: this.config.Ts.IntersectionType( - _.compact([ + lodash.compact([ this.config.Ts.ExpressionGroup(complexSchemaContent), this.schemaUtils.getInternalSchemaType(simpleSchema) === SCHEMA_TYPES.OBJECT && diff --git a/src/schema-parser/base-schema-parsers/discriminator.js b/src/schema-parser/base-schema-parsers/discriminator.js index 49f48744..47200fd6 100644 --- a/src/schema-parser/base-schema-parsers/discriminator.js +++ b/src/schema-parser/base-schema-parsers/discriminator.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../../constants.js"; import { MonoSchemaParser } from "../mono-schema-parser.js"; @@ -36,7 +36,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { ); return { - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), $schemaPath: this.schemaPath.slice(), $parsedSchema: true, schemaType: SCHEMA_TYPES.COMPLEX, @@ -59,7 +59,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { this.typeName, ]); const { discriminator } = this.schema; - const mappingEntries = _.entries(discriminator.mapping); + const mappingEntries = lodash.entries(discriminator.mapping); const ableToCreateMappingType = !skipMappingType && !!(abstractSchemaStruct?.typeName && mappingEntries.length); @@ -167,7 +167,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { const ts = this.config.Ts; let mappingPropertySchemaEnumKeysMap = {}; - let mappingPropertySchema = _.get( + let mappingPropertySchema = lodash.get( abstractSchemaStruct?.component?.rawTypeData, ["properties", discPropertyName], ); @@ -180,7 +180,7 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { if ( mappingPropertySchema?.rawTypeData?.$parsed?.type === SCHEMA_TYPES.ENUM ) { - mappingPropertySchemaEnumKeysMap = _.reduce( + mappingPropertySchemaEnumKeysMap = lodash.reduce( mappingPropertySchema.rawTypeData.$parsed.enum, (acc, key, index) => { const enumKey = @@ -205,14 +205,16 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { refPath, mappingPropertySchemaEnumKeysMap, }) => { - const complexSchemaKeys = _.keys(this.schemaParser._complexSchemaParsers); + const complexSchemaKeys = lodash.keys( + this.schemaParser._complexSchemaParsers, + ); // override parent dependencies if (mappingSchema.$ref && abstractSchemaStruct?.component?.$ref) { const mappingRefSchema = this.schemaUtils.getSchemaRefType(mappingSchema)?.rawTypeData; if (mappingRefSchema) { complexSchemaKeys.forEach((schemaKey) => { - if (_.isArray(mappingRefSchema[schemaKey])) { + if (lodash.isArray(mappingRefSchema[schemaKey])) { mappingRefSchema[schemaKey] = mappingRefSchema[schemaKey].map( (schema) => { if (schema.$ref === refPath) { @@ -257,12 +259,18 @@ class DiscriminatorSchemaParser extends MonoSchemaParser { createAbstractSchemaStruct = () => { // eslint-disable-next-line no-unused-vars const { discriminator, ...noDiscriminatorSchema } = this.schema; - const complexSchemaKeys = _.keys(this.schemaParser._complexSchemaParsers); - const schema = _.omit(_.clone(noDiscriminatorSchema), complexSchemaKeys); + const complexSchemaKeys = lodash.keys( + this.schemaParser._complexSchemaParsers, + ); + const schema = lodash.omit( + lodash.clone(noDiscriminatorSchema), + complexSchemaKeys, + ); const schemaIsAny = - this.schemaParserFabric.getInlineParseContent(_.cloneDeep(schema)) === - this.config.Ts.Keyword.Any; - const schemaIsEmpty = !_.keys(schema).length; + this.schemaParserFabric.getInlineParseContent( + lodash.cloneDeep(schema), + ) === this.config.Ts.Keyword.Any; + const schemaIsEmpty = !lodash.keys(schema).length; if (schemaIsEmpty || schemaIsAny) return null; diff --git a/src/schema-parser/base-schema-parsers/enum.js b/src/schema-parser/base-schema-parsers/enum.js index 2be35842..e1109aa9 100644 --- a/src/schema-parser/base-schema-parsers/enum.js +++ b/src/schema-parser/base-schema-parsers/enum.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../../constants.js"; import { MonoSchemaParser } from "../mono-schema-parser.js"; import { EnumKeyResolver } from "../util/enum-key-resolver.js"; @@ -70,12 +70,18 @@ class EnumSchemaParser extends MonoSchemaParser { return this.config.Ts.NullValue(value); } if ( - _.includes(keyType, this.schemaUtils.getSchemaType({ type: "number" })) + lodash.includes( + keyType, + this.schemaUtils.getSchemaType({ type: "number" }), + ) ) { return this.config.Ts.NumberValue(value); } if ( - _.includes(keyType, this.schemaUtils.getSchemaType({ type: "boolean" })) + lodash.includes( + keyType, + this.schemaUtils.getSchemaType({ type: "boolean" }), + ) ) { return this.config.Ts.BooleanValue(value); } @@ -83,15 +89,15 @@ class EnumSchemaParser extends MonoSchemaParser { return this.config.Ts.StringValue(value); }; - if (_.isArray(enumNames) && _.size(enumNames)) { - content = _.map(enumNames, (enumName, index) => { - const enumValue = _.get(this.schema.enum, index); + if (lodash.isArray(enumNames) && lodash.size(enumNames)) { + content = lodash.map(enumNames, (enumName, index) => { + const enumValue = lodash.get(this.schema.enum, index); const formattedKey = this.formatEnumKey({ key: enumName, value: enumValue, }); - if (this.config.enumNamesAsValues || _.isUndefined(enumValue)) { + if (this.config.enumNamesAsValues || lodash.isUndefined(enumValue)) { return { key: formattedKey, type: this.config.Ts.Keyword.String, @@ -106,7 +112,7 @@ class EnumSchemaParser extends MonoSchemaParser { }; }); } else { - content = _.map(this.schema.enum, (value) => { + content = lodash.map(this.schema.enum, (value) => { return { key: this.formatEnumKey({ value }), type: keyType, @@ -116,7 +122,7 @@ class EnumSchemaParser extends MonoSchemaParser { } return { - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), $ref: $ref, typeName: this.typeName || ($ref && refType.typeName) || null, $parsedSchema: true, diff --git a/src/schema-parser/base-schema-parsers/object.js b/src/schema-parser/base-schema-parsers/object.js index dae84bde..7b6ebc1c 100644 --- a/src/schema-parser/base-schema-parsers/object.js +++ b/src/schema-parser/base-schema-parsers/object.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../../constants.js"; import { MonoSchemaParser } from "../mono-schema-parser.js"; @@ -7,7 +7,7 @@ class ObjectSchemaParser extends MonoSchemaParser { const contentProperties = this.getObjectSchemaContent(this.schema); return { - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), $schemaPath: this.schemaPath.slice(), $parsedSchema: true, schemaType: SCHEMA_TYPES.OBJECT, @@ -17,8 +17,8 @@ class ObjectSchemaParser extends MonoSchemaParser { description: this.schemaFormatters.formatDescription( this.schema.description, ), - allFieldsAreOptional: !_.some( - _.values(contentProperties), + allFieldsAreOptional: !lodash.some( + lodash.values(contentProperties), (part) => part.isRequired, ), content: contentProperties, @@ -28,13 +28,13 @@ class ObjectSchemaParser extends MonoSchemaParser { getObjectSchemaContent = (schema) => { const { properties, additionalProperties } = schema || {}; - const propertiesContent = _.map(properties, (property, name) => { + const propertiesContent = lodash.map(properties, (property, name) => { const required = this.schemaUtils.isPropertyRequired( name, property, schema, ); - const rawTypeData = _.get( + const rawTypeData = lodash.get( this.schemaUtils.getSchemaRefType(property), "rawTypeData", {}, @@ -57,15 +57,15 @@ class ObjectSchemaParser extends MonoSchemaParser { title: property.title, description: property.description || - _.compact( - _.map( + lodash.compact( + lodash.map( property[this.schemaUtils.getComplexType(property)], "description", ), )[0] || rawTypeData.description || - _.compact( - _.map( + lodash.compact( + lodash.map( rawTypeData[this.schemaUtils.getComplexType(rawTypeData)], "description", ), diff --git a/src/schema-parser/base-schema-parsers/primitive.js b/src/schema-parser/base-schema-parsers/primitive.js index fe3db0ac..cdfde903 100644 --- a/src/schema-parser/base-schema-parsers/primitive.js +++ b/src/schema-parser/base-schema-parsers/primitive.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../../constants.js"; import { MonoSchemaParser } from "../mono-schema-parser.js"; @@ -9,7 +9,7 @@ class PrimitiveSchemaParser extends MonoSchemaParser { this.schema || {}; if (type === this.config.Ts.Keyword.Object && additionalProperties) { - const fieldType = _.isObject(additionalProperties) + const fieldType = lodash.isObject(additionalProperties) ? this.schemaParserFabric .createSchemaParser({ schema: additionalProperties, @@ -23,14 +23,14 @@ class PrimitiveSchemaParser extends MonoSchemaParser { ); } - if (_.isArray(type) && type.length) { + if (lodash.isArray(type) && type.length) { contentType = this.schemaParser._complexSchemaParsers.oneOf({ - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), oneOf: type.map((type) => ({ type })), }); } - if (_.isArray(items) && type === SCHEMA_TYPES.ARRAY) { + if (lodash.isArray(items) && type === SCHEMA_TYPES.ARRAY) { contentType = this.config.Ts.Tuple( items.map((item) => this.schemaParserFabric @@ -41,7 +41,7 @@ class PrimitiveSchemaParser extends MonoSchemaParser { } return { - ...(_.isObject(this.schema) ? this.schema : {}), + ...(lodash.isObject(this.schema) ? this.schema : {}), $schemaPath: this.schemaPath.slice(), $parsedSchema: true, schemaType: SCHEMA_TYPES.PRIMITIVE, diff --git a/src/schema-parser/complex-schema-parsers/all-of.js b/src/schema-parser/complex-schema-parsers/all-of.js index d0487022..138de848 100644 --- a/src/schema-parser/complex-schema-parsers/all-of.js +++ b/src/schema-parser/complex-schema-parsers/all-of.js @@ -1,11 +1,11 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { MonoSchemaParser } from "../mono-schema-parser.js"; // T1 & T2 class AllOfSchemaParser extends MonoSchemaParser { parse() { const ignoreTypes = [this.config.Ts.Keyword.Any]; - const combined = _.map(this.schema.allOf, (childSchema) => + const combined = lodash.map(this.schema.allOf, (childSchema) => this.schemaParserFabric.getInlineParseContent( this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema), null, diff --git a/src/schema-parser/complex-schema-parsers/any-of.js b/src/schema-parser/complex-schema-parsers/any-of.js index 5f83e6d0..a1ca18e1 100644 --- a/src/schema-parser/complex-schema-parsers/any-of.js +++ b/src/schema-parser/complex-schema-parsers/any-of.js @@ -1,11 +1,11 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { MonoSchemaParser } from "../mono-schema-parser.js"; // T1 | T2 class AnyOfSchemaParser extends MonoSchemaParser { parse() { const ignoreTypes = [this.config.Ts.Keyword.Any]; - const combined = _.map(this.schema.anyOf, (childSchema) => + const combined = lodash.map(this.schema.anyOf, (childSchema) => this.schemaParserFabric.getInlineParseContent( this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema), null, diff --git a/src/schema-parser/complex-schema-parsers/one-of.js b/src/schema-parser/complex-schema-parsers/one-of.js index f5c3247c..98ee62aa 100644 --- a/src/schema-parser/complex-schema-parsers/one-of.js +++ b/src/schema-parser/complex-schema-parsers/one-of.js @@ -1,11 +1,11 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { MonoSchemaParser } from "../mono-schema-parser.js"; // T1 | T2 class OneOfSchemaParser extends MonoSchemaParser { parse() { const ignoreTypes = [this.config.Ts.Keyword.Any]; - const combined = _.map(this.schema.oneOf, (childSchema) => + const combined = lodash.map(this.schema.oneOf, (childSchema) => this.schemaParserFabric.getInlineParseContent( this.schemaUtils.makeAddRequiredToChildSchema(this.schema, childSchema), null, diff --git a/src/schema-parser/schema-formatters.js b/src/schema-parser/schema-formatters.js index 88151d8b..966a7b4d 100644 --- a/src/schema-parser/schema-formatters.js +++ b/src/schema-parser/schema-formatters.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../constants.js"; class SchemaFormatters { @@ -28,7 +28,7 @@ class SchemaFormatters { ...parsedSchema, $content: parsedSchema.content, content: this.config.Ts.UnionType( - _.map(parsedSchema.content, ({ value }) => value), + lodash.map(parsedSchema.content, ({ value }) => value), ), }; } @@ -62,15 +62,15 @@ class SchemaFormatters { content: parsedSchema.$ref ? parsedSchema.typeName : this.config.Ts.UnionType( - _.compact([ - ..._.map(parsedSchema.content, ({ value }) => `${value}`), + lodash.compact([ + ...lodash.map(parsedSchema.content, ({ value }) => `${value}`), parsedSchema.nullable && this.config.Ts.Keyword.Null, ]), ) || this.config.Ts.Keyword.Any, }; }, [SCHEMA_TYPES.OBJECT]: (parsedSchema) => { - if (_.isString(parsedSchema.content)) { + if (lodash.isString(parsedSchema.content)) { return { ...parsedSchema, typeIdentifier: this.config.Ts.Keyword.Type, @@ -102,9 +102,9 @@ class SchemaFormatters { */ formatSchema = (parsedSchema, formatType = "base") => { const schemaType = - _.get(parsedSchema, ["schemaType"]) || - _.get(parsedSchema, ["$parsed", "schemaType"]); - const formatterFn = _.get(this, [formatType, schemaType]); + lodash.get(parsedSchema, ["schemaType"]) || + lodash.get(parsedSchema, ["$parsed", "schemaType"]); + const formatterFn = lodash.get(this, [formatType, schemaType]); return formatterFn?.(parsedSchema) || parsedSchema; }; @@ -113,22 +113,23 @@ class SchemaFormatters { let prettified = description; - prettified = _.replace(prettified, /\*\//g, "*/"); + prettified = lodash.replace(prettified, /\*\//g, "*/"); - const hasMultipleLines = _.includes(prettified, "\n"); + const hasMultipleLines = lodash.includes(prettified, "\n"); if (!hasMultipleLines) return prettified; if (inline) { - return _(prettified) + return lodash + ._(prettified) .split(/\n/g) - .map((part) => _.trim(part)) + .map((part) => lodash.trim(part)) .compact() .join(" ") .valueOf(); } - return _.replace(prettified, /\n$/g, ""); + return lodash.replace(prettified, /\n$/g, ""); }; formatObjectContent = (content) => { diff --git a/src/schema-parser/schema-parser-fabric.js b/src/schema-parser/schema-parser-fabric.js index 2f93d8d3..34323b38 100644 --- a/src/schema-parser/schema-parser-fabric.js +++ b/src/schema-parser/schema-parser-fabric.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SchemaFormatters } from "./schema-formatters.js"; import { SchemaParser } from "./schema-parser.js"; import { SchemaUtils } from "./schema-utils.js"; @@ -73,7 +73,7 @@ class SchemaParserFabric { }; createParsedComponent = ({ typeName, schema, schemaPath }) => { - const schemaCopy = _.cloneDeep(schema); + const schemaCopy = lodash.cloneDeep(schema); const customComponent = this.schemaComponentsMap.createComponent( this.schemaComponentsMap.createRef(["components", "schemas", typeName]), schemaCopy, diff --git a/src/schema-parser/schema-parser.js b/src/schema-parser/schema-parser.js index bd8ec092..9cd6690a 100644 --- a/src/schema-parser/schema-parser.js +++ b/src/schema-parser/schema-parser.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../constants.js"; import { sortByProperty } from "../util/sort-by-property.js"; import { ArraySchemaParser } from "./base-schema-parsers/array.js"; @@ -227,7 +227,7 @@ class SchemaParser { this.schemaPath.push(this.typeName); - _.merge( + lodash.merge( this.schema, this.config.hooks.onPreParseSchema( this.schema, @@ -279,14 +279,14 @@ class SchemaParser { extractSchemaFromResponseStruct = (responseStruct) => { const { content, ...extras } = responseStruct; - const firstResponse = _.first(_.values(content)); - const firstSchema = _.get(firstResponse, "schema"); + const firstResponse = lodash.first(lodash.values(content)); + const firstSchema = lodash.get(firstResponse, "schema"); if (!firstSchema) return; return { ...extras, - ..._.omit(firstResponse, "schema"), + ...lodash.omit(firstResponse, "schema"), ...firstSchema, }; }; diff --git a/src/schema-parser/schema-utils.js b/src/schema-parser/schema-utils.js index 1b155e05..0c9558e9 100644 --- a/src/schema-parser/schema-utils.js +++ b/src/schema-parser/schema-utils.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { SCHEMA_TYPES } from "../constants.js"; import { internalCase } from "../util/internal-case.js"; import { pascalCase } from "../util/pascal-case.js"; @@ -26,8 +26,8 @@ class SchemaUtils { } getRequiredProperties = (schema) => { - return _.uniq( - (schema && _.isArray(schema.required) && schema.required) || [], + return lodash.uniq( + (schema && lodash.isArray(schema.required) && schema.required) || [], ); }; @@ -55,9 +55,9 @@ class SchemaUtils { return true; } - const isRequired = _.isBoolean(propertySchema.required) + const isRequired = lodash.isBoolean(propertySchema.required) ? !!propertySchema.required - : _.isArray(rootSchema.required) + : lodash.isArray(rootSchema.required) ? rootSchema.required.includes(name) : !!rootSchema.required; @@ -73,9 +73,9 @@ class SchemaUtils { const { nullable, type: schemaType } = schema || {}; return ( (nullable || - !!_.get(schema, "x-nullable") || + !!lodash.get(schema, "x-nullable") || schemaType === this.config.Ts.Keyword.Null) && - _.isString(type) && + lodash.isString(type) && !type.includes(` ${this.config.Ts.Keyword.Null}`) && !type.includes(`${this.config.Ts.Keyword.Null} `) ); @@ -100,7 +100,7 @@ class SchemaUtils { return internalCase(enumFieldType); } - if (_.keys(schema.properties).length) { + if (lodash.keys(schema.properties).length) { return SCHEMA_TYPES.OBJECT; } if (schema.items) { @@ -134,7 +134,7 @@ class SchemaUtils { makeAddRequiredToChildSchema = (parentSchema, childSchema) => { if (!childSchema) return childSchema; - const required = _.uniq([ + const required = lodash.uniq([ ...this.getRequiredProperties(parentSchema), ...this.getRequiredProperties(childSchema), ]); @@ -142,7 +142,9 @@ class SchemaUtils { const refData = this.getSchemaRefType(childSchema); if (refData) { - const refObjectProperties = _.keys(refData.rawTypeData?.properties || {}); + const refObjectProperties = lodash.keys( + refData.rawTypeData?.properties || {}, + ); const existedRequiredKeys = refObjectProperties.filter((key) => required.includes(key), ); @@ -154,7 +156,7 @@ class SchemaUtils { $$requiredKeys: existedRequiredKeys, }; } else if (childSchema.properties) { - const childSchemaProperties = _.keys(childSchema.properties); + const childSchemaProperties = lodash.keys(childSchema.properties); const existedRequiredKeys = childSchemaProperties.filter((key) => required.includes(key), ); @@ -162,7 +164,7 @@ class SchemaUtils { if (!existedRequiredKeys.length) return childSchema; return { - required: _.uniq([ + required: lodash.uniq([ ...this.getRequiredProperties(childSchema), ...existedRequiredKeys, ]), @@ -174,7 +176,7 @@ class SchemaUtils { }; filterSchemaContents = (contents, filterFn) => { - return _.uniq(_.filter(contents, (type) => filterFn(type))); + return lodash.uniq(lodash.filter(contents, (type) => filterFn(type))); }; resolveTypeName = ( @@ -211,7 +213,10 @@ class SchemaUtils { }; getInternalSchemaType = (schema) => { - if (!_.isEmpty(schema.enum) || !_.isEmpty(this.getEnumNames(schema))) { + if ( + !lodash.isEmpty(schema.enum) || + !lodash.isEmpty(this.getEnumNames(schema)) + ) { return SCHEMA_TYPES.ENUM; } if (schema.discriminator) { @@ -220,7 +225,7 @@ class SchemaUtils { if (schema.allOf || schema.oneOf || schema.anyOf || schema.not) { return SCHEMA_TYPES.COMPLEX; } - if (!_.isEmpty(schema.properties)) { + if (!lodash.isEmpty(schema.properties)) { return SCHEMA_TYPES.OBJECT; } if (schema.type === SCHEMA_TYPES.ARRAY) { @@ -257,11 +262,14 @@ class SchemaUtils { } const typeAlias = - _.get(this.config.primitiveTypes, [primitiveType, schema.format]) || - _.get(this.config.primitiveTypes, [primitiveType, "$default"]) || + lodash.get(this.config.primitiveTypes, [ + primitiveType, + schema.format, + ]) || + lodash.get(this.config.primitiveTypes, [primitiveType, "$default"]) || this.config.primitiveTypes[primitiveType]; - if (_.isFunction(typeAlias)) { + if (lodash.isFunction(typeAlias)) { resultType = typeAlias(schema, this); } else { resultType = typeAlias || primitiveType; @@ -279,13 +287,15 @@ class SchemaUtils { }; buildTypeNameFromPath = (schemaPath) => { - schemaPath = _.uniq(_.compact(schemaPath)); + schemaPath = lodash.uniq(lodash.compact(schemaPath)); if (!schemaPath || !schemaPath[0]) return null; return pascalCase( - _.camelCase( - _.uniq([schemaPath[0], schemaPath[schemaPath.length - 1]]).join("_"), + lodash.camelCase( + lodash + .uniq([schemaPath[0], schemaPath[schemaPath.length - 1]]) + .join("_"), ), ); }; diff --git a/src/schema-routes/schema-routes.js b/src/schema-routes/schema-routes.js index 9dfe7afd..d94b30e0 100644 --- a/src/schema-routes/schema-routes.js +++ b/src/schema-routes/schema-routes.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; import { DEFAULT_BODY_ARG_NAME, RESERVED_BODY_ARG_NAMES, @@ -71,20 +71,20 @@ class SchemaRoutes { this.logger = logger; this.templatesWorker = templatesWorker; - this.FORM_DATA_TYPES = _.uniq([ + this.FORM_DATA_TYPES = lodash.uniq([ this.schemaUtils.getSchemaType({ type: "string", format: "file" }), this.schemaUtils.getSchemaType({ type: "string", format: "binary" }), ]); } createRequestsMap = (routeInfoByMethodsMap) => { - const parameters = _.get(routeInfoByMethodsMap, "parameters"); + const parameters = lodash.get(routeInfoByMethodsMap, "parameters"); - return _.reduce( + return lodash.reduce( routeInfoByMethodsMap, (acc, requestInfo, method) => { if ( - _.startsWith(method, "x-") || + lodash.startsWith(method, "x-") || ["parameters", "$ref"].includes(method) ) { return acc; @@ -92,7 +92,9 @@ class SchemaRoutes { acc[method] = { ...requestInfo, - parameters: _.compact(_.concat(parameters, requestInfo.parameters)), + parameters: lodash.compact( + lodash.concat(parameters, requestInfo.parameters), + ), }; return acc; @@ -111,20 +113,20 @@ class SchemaRoutes { ); // used in case when path parameters is not declared in requestInfo.parameters ("in": "path") - const pathParams = _.reduce( + const pathParams = lodash.reduce( pathParamMatches, (pathParams, match) => { - const paramName = _.replace(match, /\{|\}|:/g, ""); + const paramName = lodash.replace(match, /\{|\}|:/g, ""); if (!paramName) return pathParams; - if (_.includes(paramName, "-")) { + if (lodash.includes(paramName, "-")) { this.logger.warn("wrong path param name", paramName); } pathParams.push({ $match: match, - name: _.camelCase(paramName), + name: lodash.camelCase(paramName), required: true, type: "string", description: "", @@ -139,7 +141,7 @@ class SchemaRoutes { [], ); - let fixedRoute = _.reduce( + let fixedRoute = lodash.reduce( pathParams, (fixedRoute, pathParam, i, arr) => { const insertion = @@ -149,7 +151,7 @@ class SchemaRoutes { arr, fixedRoute, ) || pathParam.name; - return _.replace(fixedRoute, pathParam.$match, `\${${insertion}}`); + return lodash.replace(fixedRoute, pathParam.$match, `\${${insertion}}`); }, routeName || "", ); @@ -162,28 +164,30 @@ class SchemaRoutes { fixedRoute = fixedRoute.replace(match, ""); }); - _.uniq( - queryParamMatches - .join(",") - .replace(/(\{\?)|(\})|\s/g, "") - .split(","), - ).forEach((paramName) => { - if (_.includes(paramName, "-")) { - this.logger.warn("wrong query param name", paramName); - } + lodash + .uniq( + queryParamMatches + .join(",") + .replace(/(\{\?)|(\})|\s/g, "") + .split(","), + ) + .forEach((paramName) => { + if (lodash.includes(paramName, "-")) { + this.logger.warn("wrong query param name", paramName); + } - queryParams.push({ - $match: paramName, - name: _.camelCase(paramName), - required: true, - type: "string", - description: "", - schema: { + queryParams.push({ + $match: paramName, + name: lodash.camelCase(paramName), + required: true, type: "string", - }, - in: "query", + description: "", + schema: { + type: "string", + }, + in: "query", + }); }); - }); } const result = { @@ -212,7 +216,7 @@ class SchemaRoutes { cookie: [], }; - _.each(parameters, (parameter) => { + lodash.each(parameters, (parameter) => { const refTypeInfo = this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter); let routeParam = null; @@ -242,7 +246,7 @@ class SchemaRoutes { if (routeParam.in === "path") { if (!routeParam.name) return; - routeParam.name = _.camelCase(routeParam.name); + routeParam.name = lodash.camelCase(routeParam.name); } if (routeParam) { @@ -251,8 +255,8 @@ class SchemaRoutes { }); // used in case when path parameters is not declared in requestInfo.parameters ("in": "path") - _.each(pathParamsFromRouteName, (pathParam) => { - const alreadyExist = _.some( + lodash.each(pathParamsFromRouteName, (pathParam) => { + const alreadyExist = lodash.some( routeParams.path, (parameter) => parameter.name === pathParam.name, ); @@ -262,8 +266,8 @@ class SchemaRoutes { } }); // used in case when path parameters is not declared in requestInfo.parameters ("in": "path") - _.each(queryParamsFromRouteName, (queryParam) => { - const alreadyExist = _.some( + lodash.each(queryParamsFromRouteName, (queryParam) => { + const alreadyExist = lodash.some( routeParams.query, (parameter) => parameter.name === queryParam.name, ); @@ -277,14 +281,14 @@ class SchemaRoutes { }; getContentTypes = (requestInfo, extraContentTypes) => - _.uniq( - _.compact([ + lodash.uniq( + lodash.compact([ ...(extraContentTypes || []), - ..._.flatten( - _.map( + ...lodash.flatten( + lodash.map( requestInfo, (requestInfoData) => - requestInfoData && _.keys(requestInfoData.content), + requestInfoData && lodash.keys(requestInfoData.content), ), ), ]), @@ -292,10 +296,12 @@ class SchemaRoutes { getContentKind = (contentTypes) => { if ( - _.some(contentTypes, (contentType) => - _.startsWith(contentType, "application/json"), + lodash.some(contentTypes, (contentType) => + lodash.startsWith(contentType, "application/json"), ) || - _.some(contentTypes, (contentType) => _.endsWith(contentType, "+json")) + lodash.some(contentTypes, (contentType) => + lodash.endsWith(contentType, "+json"), + ) ) { return CONTENT_KIND.JSON; } @@ -309,13 +315,17 @@ class SchemaRoutes { } if ( - _.some(contentTypes, (contentType) => _.includes(contentType, "image/")) + lodash.some(contentTypes, (contentType) => + lodash.includes(contentType, "image/"), + ) ) { return CONTENT_KIND.IMAGE; } if ( - _.some(contentTypes, (contentType) => _.startsWith(contentType, "text/")) + lodash.some(contentTypes, (contentType) => + lodash.startsWith(contentType, "text/"), + ) ) { return CONTENT_KIND.TEXT; } @@ -330,7 +340,7 @@ class SchemaRoutes { status === "2xx"; getSchemaFromRequestType = (requestInfo) => { - const content = _.get(requestInfo, "content"); + const content = lodash.get(requestInfo, "content"); if (!content) return null; @@ -367,13 +377,13 @@ class SchemaRoutes { typeName, [operationId], ); - const foundedSchemaByName = _.find( + const foundedSchemaByName = lodash.find( parsedSchemas, (parsedSchema) => this.typeNameFormatter.format(parsedSchema.name) === content, ); - const foundSchemaByContent = _.find(parsedSchemas, (parsedSchema) => - _.isEqual(parsedSchema.content, content), + const foundSchemaByContent = lodash.find(parsedSchemas, (parsedSchema) => + lodash.isEqual(parsedSchema.content, content), ); const foundSchema = foundedSchemaByName || foundSchemaByContent; @@ -388,13 +398,16 @@ class SchemaRoutes { // const foundedSchemaByName = _.find(parsedSchemas, ({ name }) => name === refType || name === refTypeWithoutOpId) // TODO:HACK fix problem of swagger2opeanpi - const typeNameWithoutOpId = _.replace( + const typeNameWithoutOpId = lodash.replace( refTypeInfo.typeName, operationId, "", ); if ( - _.find(parsedSchemas, (schema) => schema.name === typeNameWithoutOpId) + lodash.find( + parsedSchemas, + (schema) => schema.name === typeNameWithoutOpId, + ) ) { return this.typeNameFormatter.format(typeNameWithoutOpId); } @@ -427,7 +440,7 @@ class SchemaRoutes { operationId, defaultType, }) => - _.reduce( + lodash.reduce( requestInfos, (acc, requestInfo, status) => { const contentTypes = this.getContentTypes([requestInfo]); @@ -452,7 +465,7 @@ class SchemaRoutes { requestInfo.description || "", true, ), - status: _.isNaN(+status) ? status : +status, + status: lodash.isNaN(+status) ? status : +status, isSuccess: this.isSuccessStatus(status), }, ]; @@ -529,7 +542,7 @@ class SchemaRoutes { }; convertRouteParamsIntoObject = (params) => { - return _.reduce( + return lodash.reduce( params, (objectSchema, schemaPart) => { if (!schemaPart || !schemaPart.name) return objectSchema; @@ -537,7 +550,7 @@ class SchemaRoutes { let usageName = `${schemaPart.name}`; if (usageName.includes(".")) { - usageName = _.camelCase(usageName); + usageName = lodash.camelCase(usageName); } return { @@ -612,7 +625,7 @@ class SchemaRoutes { // but request body data type contains form data types like File if ( this.FORM_DATA_TYPES.some((dataType) => - _.includes(content, `: ${dataType}`), + lodash.includes(content, `: ${dataType}`), ) ) { contentKind = CONTENT_KIND.FORM_DATA; @@ -651,7 +664,7 @@ class SchemaRoutes { }) => { if (!queryParams || !queryParams.length) return null; - const pathParams = _.reduce( + const pathParams = lodash.reduce( pathArgsSchemas, (acc, pathArgSchema) => { if (pathArgSchema.name) { @@ -666,10 +679,10 @@ class SchemaRoutes { {}, ); - const fixedQueryParams = _.reduce( - _.get(queryObjectSchema, "properties", {}), + const fixedQueryParams = lodash.reduce( + lodash.get(queryObjectSchema, "properties", {}), (acc, property, name) => { - if (name && _.isObject(property)) { + if (name && lodash.isObject(property)) { acc[name] = { ...property, in: "query", @@ -742,7 +755,7 @@ class SchemaRoutes { }); if (idx > -1) { - _.assign(responseBodyInfo.responses[idx], { + lodash.assign(responseBodyInfo.responses[idx], { ...successResponse.schema, type: successResponse.type, }); @@ -880,8 +893,10 @@ class SchemaRoutes { const firstTag = tags && tags.length > 0 ? tags[0] : null; const moduleName = moduleNameFirstTag && firstTag - ? _.camelCase(firstTag) - : _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]); + ? lodash.camelCase(firstTag) + : lodash.camelCase( + lodash.compact(lodash.split(route, "/"))[moduleNameIndex], + ); let hasSecurity = !!globalSecurity?.length; if (security) { hasSecurity = security.length > 0; @@ -1050,7 +1065,7 @@ class SchemaRoutes { return { id: routeId, - namespace: _.replace(moduleName, /^(\d)/, "v$1"), + namespace: lodash.replace(moduleName, /^(\d)/, "v$1"), routeName, routeParams, requestBodyInfo, @@ -1090,12 +1105,12 @@ class SchemaRoutes { attachSchema = ({ usageSchema, parsedSchemas }) => { this.config.routeNameDuplicatesMap.clear(); - const pathsEntries = _.entries(usageSchema.paths); + const pathsEntries = lodash.entries(usageSchema.paths); - _.forEach(pathsEntries, ([rawRouteName, routeInfoByMethodsMap]) => { + lodash.forEach(pathsEntries, ([rawRouteName, routeInfoByMethodsMap]) => { const routeInfosMap = this.createRequestsMap(routeInfoByMethodsMap); - _.forEach(routeInfosMap, (routeInfo, method) => { + lodash.forEach(routeInfosMap, (routeInfo, method) => { const parsedRouteInfo = this.parseRouteInfo( rawRouteName, routeInfo, @@ -1144,7 +1159,7 @@ class SchemaRoutes { }, ); - const routeGroups = _.reduce( + const routeGroups = lodash.reduce( groupedRoutes, (acc, routesGroup, moduleName) => { if (moduleName === "$outOfModule") { @@ -1154,7 +1169,7 @@ class SchemaRoutes { acc.combined.push({ moduleName, - routes: _.map(routesGroup, (route) => { + routes: lodash.map(routesGroup, (route) => { const { original: originalName, usage: usageName } = route.routeName; @@ -1163,7 +1178,7 @@ class SchemaRoutes { if ( routesGroup.length > 1 && usageName !== originalName && - !_.some( + !lodash.some( routesGroup, ({ routeName, id }) => id !== route.id && originalName === routeName.original, @@ -1192,7 +1207,7 @@ class SchemaRoutes { routeGroups.outOfModule = this.sortRoutes(routeGroups.outOfModule); } if (routeGroups.combined) { - _.each(routeGroups.combined, (routeGroup) => { + lodash.each(routeGroups.combined, (routeGroup) => { routeGroup.routes = this.sortRoutes(routeGroup.routes); }); } @@ -1202,9 +1217,11 @@ class SchemaRoutes { }; sortRoutes = (routes) => { - return _.slice(routes).sort((routeA, routeB) => - routeA.routeName.usage.localeCompare(routeB.routeName.usage), - ); + return lodash + .slice(routes) + .sort((routeA, routeB) => + routeA.routeName.usage.localeCompare(routeB.routeName.usage), + ); }; } diff --git a/src/schema-walker.js b/src/schema-walker.js index 7fd922f9..a9891df0 100644 --- a/src/schema-walker.js +++ b/src/schema-walker.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; // TODO: WIP // this class will be needed to walk by schema everywhere @@ -24,7 +24,7 @@ class SchemaWalker { * @param schema {Record} */ addSchema = (name, schema) => { - this.schemas.set(name, _.cloneDeep(schema)); + this.schemas.set(name, lodash.cloneDeep(schema)); }; /** @@ -80,7 +80,7 @@ class SchemaWalker { _getRefDataFromSchema = (schema, ref) => { const path = ref.replace("#", "").split("/"); - const refData = _.get(schema, path); + const refData = lodash.get(schema, path); if (refData) { this.caches.set(ref, refData); } diff --git a/src/swagger-schema-resolver.js b/src/swagger-schema-resolver.js index b79cd85a..a5dda295 100644 --- a/src/swagger-schema-resolver.js +++ b/src/swagger-schema-resolver.js @@ -1,6 +1,6 @@ -import yaml from "js-yaml"; -import _ from "lodash"; -import converter from "swagger2openapi"; +import * as yaml from "js-yaml"; +import * as lodash from "lodash"; +import * as swagger2openapi from "swagger2openapi"; import { Request } from "./util/request.js"; class SwaggerSchemaResolver { @@ -67,8 +67,8 @@ class SwaggerSchemaResolver { */ convertSwaggerObject(swaggerSchema, converterOptions) { return new Promise((resolve) => { - const result = _.cloneDeep(swaggerSchema); - result.info = _.merge( + const result = lodash.cloneDeep(swaggerSchema); + result.info = lodash.merge( { title: "No title", version: "", @@ -77,9 +77,9 @@ class SwaggerSchemaResolver { ); if (!result.openapi) { - result.paths = _.merge({}, result.paths); + result.paths = lodash.merge({}, result.paths); - converter.convertObj( + swagger2openapi.convertObj( result, { ...converterOptions, @@ -88,10 +88,10 @@ class SwaggerSchemaResolver { rbname: "requestBodyName", }, (err, options) => { - const parsedSwaggerSchema = _.get( + const parsedSwaggerSchema = lodash.get( err, "options.openapi", - _.get(options, "openapi"), + lodash.get(options, "openapi"), ); if (!parsedSwaggerSchema && err) { throw new Error(err); @@ -106,7 +106,7 @@ class SwaggerSchemaResolver { } else { resolve({ usageSchema: result, - originalSchema: _.cloneDeep(result), + originalSchema: lodash.cloneDeep(result), }); } }); @@ -148,36 +148,40 @@ class SwaggerSchemaResolver { } fixSwaggerSchema({ usageSchema, originalSchema }) { - const usagePaths = _.get(usageSchema, "paths"); - const originalPaths = _.get(originalSchema, "paths"); + const usagePaths = lodash.get(usageSchema, "paths"); + const originalPaths = lodash.get(originalSchema, "paths"); // walk by routes - _.each(usagePaths, (usagePathObject, route) => { - const originalPathObject = _.get(originalPaths, route); + lodash.each(usagePaths, (usagePathObject, route) => { + const originalPathObject = lodash.get(originalPaths, route); // walk by methods - _.each(usagePathObject, (usageRouteInfo, methodName) => { - const originalRouteInfo = _.get(originalPathObject, methodName); - const usageRouteParams = _.get(usageRouteInfo, "parameters", []); - const originalRouteParams = _.get(originalRouteInfo, "parameters", []); + lodash.each(usagePathObject, (usageRouteInfo, methodName) => { + const originalRouteInfo = lodash.get(originalPathObject, methodName); + const usageRouteParams = lodash.get(usageRouteInfo, "parameters", []); + const originalRouteParams = lodash.get( + originalRouteInfo, + "parameters", + [], + ); if (typeof usageRouteInfo === "object") { - usageRouteInfo.consumes = _.uniq( - _.compact([ + usageRouteInfo.consumes = lodash.uniq( + lodash.compact([ ...(usageRouteInfo.consumes || []), ...(originalRouteInfo.consumes || []), ]), ); - usageRouteInfo.produces = _.uniq( - _.compact([ + usageRouteInfo.produces = lodash.uniq( + lodash.compact([ ...(usageRouteInfo.produces || []), ...(originalRouteInfo.produces || []), ]), ); } - _.each(originalRouteParams, (originalRouteParam) => { - const existUsageParam = _.find( + lodash.each(originalRouteParams, (originalRouteParam) => { + const existUsageParam = lodash.find( usageRouteParams, (param) => originalRouteParam.in === param.in && diff --git a/src/templates-worker.js b/src/templates-worker.js index 0dc63823..10fe50bc 100644 --- a/src/templates-worker.js +++ b/src/templates-worker.js @@ -1,8 +1,8 @@ import { resolve } from "node:path"; -import path from "node:path"; -import url from "node:url"; +import * as path from "node:path"; +import * as url from "node:url"; import * as Eta from "eta"; -import _ from "lodash"; +import * as lodash from "lodash"; class TemplatesWorker { /** @@ -61,7 +61,8 @@ class TemplatesWorker { cropExtension = (path) => this.config.templateExtensions.reduce( - (path, ext) => (_.endsWith(path, ext) ? path.replace(ext, "") : path), + (path, ext) => + lodash.endsWith(path, ext) ? path.replace(ext, "") : path, path, ); @@ -78,7 +79,8 @@ class TemplatesWorker { requireFnFromTemplate = async (packageOrPath) => { const isPath = - _.startsWith(packageOrPath, "./") || _.startsWith(packageOrPath, "../"); + lodash.startsWith(packageOrPath, "./") || + lodash.startsWith(packageOrPath, "../"); if (isPath) { return await import( @@ -110,7 +112,7 @@ class TemplatesWorker { if (fileContent) { this.logger.log( - `"${_.lowerCase(name)}" template found in "${templatePaths.custom}"`, + `"${lodash.lowerCase(name)}" template found in "${templatePaths.custom}"`, ); return fileContent; } @@ -122,14 +124,14 @@ class TemplatesWorker { } else { if (templatePaths.custom) { this.logger.warn( - `"${_.lowerCase(name)}" template not found in "${ + `"${lodash.lowerCase(name)}" template not found in "${ templatePaths.custom }"`, "\nCode generator will use the default template", ); } else { this.logger.log( - `Code generator will use the default template for "${_.lowerCase( + `Code generator will use the default template for "${lodash.lowerCase( name, )}"`, ); @@ -155,7 +157,7 @@ class TemplatesWorker { ); } - return _.reduce( + return lodash.reduce( this.config.templateInfos, (acc, { fileName, name }) => ({ ...acc, @@ -174,12 +176,12 @@ class TemplatesWorker { }; getTemplateContent = (path) => { - const foundTemplatePathKey = _.keys(this.config.templatePaths).find((key) => - _.startsWith(path, `@${key}`), - ); + const foundTemplatePathKey = lodash + .keys(this.config.templatePaths) + .find((key) => lodash.startsWith(path, `@${key}`)); const rawPath = resolve( - _.replace( + lodash.replace( path, `@${foundTemplatePathKey}`, this.config.templatePaths[foundTemplatePathKey], diff --git a/src/translators/javascript.js b/src/translators/javascript.js index f90f0d14..b0692e0a 100644 --- a/src/translators/javascript.js +++ b/src/translators/javascript.js @@ -1,4 +1,4 @@ -import ts from "typescript"; +import * as typescript from "typescript"; import { Translator } from "./translator.js"; class JavascriptTranslator extends Translator { @@ -9,7 +9,10 @@ class JavascriptTranslator extends Translator { compileTSCode = (input) => { const fileNameFull = `${input.fileName}${input.fileExtension}`; const output = {}; - const host = ts.createCompilerHost(this.config.compilerTsConfig, true); + const host = typescript.createCompilerHost( + this.config.compilerTsConfig, + true, + ); const fileNames = [fileNameFull]; const originalSourceFileGet = host.getSourceFile.bind(host); host.getSourceFile = ( @@ -26,12 +29,12 @@ class JavascriptTranslator extends Translator { shouldCreateNewSourceFile, ); - return ts.createSourceFile( + return typescript.createSourceFile( sourceFileName, input.fileContent, languageVersion, true, - ts.ScriptKind.TS, + typescript.ScriptKind.TS, ); }; @@ -39,7 +42,9 @@ class JavascriptTranslator extends Translator { output[fileName] = contents; }; - ts.createProgram(fileNames, this.config.compilerTsConfig, host).emit(); + typescript + .createProgram(fileNames, this.config.compilerTsConfig, host) + .emit(); return output; }; @@ -47,8 +52,8 @@ class JavascriptTranslator extends Translator { translate = async (input) => { const compiled = this.compileTSCode(input); - const jsFileName = `${input.fileName}${ts.Extension.Js}`; - const dtsFileName = `${input.fileName}${ts.Extension.Dts}`; + const jsFileName = `${input.fileName}${typescript.Extension.Js}`; + const dtsFileName = `${input.fileName}${typescript.Extension.Dts}`; const sourceContent = compiled[jsFileName]; const tsImportRows = input.fileContent .split("\n") @@ -66,12 +71,12 @@ class JavascriptTranslator extends Translator { return [ { fileName: input.fileName, - fileExtension: ts.Extension.Js, + fileExtension: typescript.Extension.Js, fileContent: await this.codeFormatter.formatCode(sourceContent), }, { fileName: input.fileName, - fileExtension: ts.Extension.Dts, + fileExtension: typescript.Extension.Dts, fileContent: await this.codeFormatter.formatCode(declarationContent), }, ]; diff --git a/src/type-name-formatter.js b/src/type-name-formatter.js index a5ed4b8a..a96dc087 100644 --- a/src/type-name-formatter.js +++ b/src/type-name-formatter.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; /** * @typedef {"enum-key" | "type-name"} FormattingSchemaType @@ -50,7 +50,7 @@ class TypeNameFormatter { // constant names like LEFT_ARROW, RIGHT_FORWARD, ETC_KEY, _KEY_NUM_ if (/^([A-Z_]{1,})$/g.test(name)) { - return _.compact([typePrefix, name, typeSuffix]).join("_"); + return lodash.compact([typePrefix, name, typeSuffix]).join("_"); } if (this.formattedModelNamesMap.has(hashKey)) { @@ -59,8 +59,8 @@ class TypeNameFormatter { const fixedModelName = this.fixModelName(name, { type: schemaType }); - const formattedName = _.replace( - _.startCase(`${typePrefix}_${fixedModelName}_${typeSuffix}`), + const formattedName = lodash.replace( + lodash.startCase(`${typePrefix}_${fixedModelName}_${typeSuffix}`), /\s/g, "", ); @@ -101,7 +101,7 @@ class TypeNameFormatter { .replace(/(\.?%22)|\./g, "_") .replace(/__+$/, ""); - if (name.includes("-")) name = _.startCase(name).replace(/ /g, ""); + if (name.includes("-")) name = lodash.startCase(name).replace(/ /g, ""); } return name; diff --git a/src/util/file-system.js b/src/util/file-system.js index dfb1d472..ea362d4d 100644 --- a/src/util/file-system.js +++ b/src/util/file-system.js @@ -1,7 +1,7 @@ -import fs from "node:fs"; +import * as fs from "node:fs"; import { dirname, resolve } from "node:path"; -import url from "node:url"; -import _ from "lodash"; +import * as url from "node:url"; +import * as lodash from "lodash"; import { Logger } from "./logger.js"; const FILE_PREFIX = `/* eslint-disable */ @@ -45,7 +45,7 @@ class FileSystem { }; cropExtension = (fileName) => { - const fileNameParts = _.split(fileName, "."); + const fileNameParts = lodash.split(fileName, "."); if (fileNameParts.length > 1) { fileNameParts.pop(); @@ -88,7 +88,7 @@ class FileSystem { const absolutePath = resolve(__dirname, path, `./${fileName}`); const fileContent = `${withPrefix ? FILE_PREFIX : ""}${content}`; - return fs.writeFileSync(absolutePath, fileContent, _.noop); + return fs.writeFileSync(absolutePath, fileContent, lodash.noop); }; } diff --git a/src/util/id.js b/src/util/id.js index 043dadab..d5dcc7b0 100644 --- a/src/util/id.js +++ b/src/util/id.js @@ -1,7 +1,7 @@ -import { customAlphabet } from "nanoid"; +import * as nanoid from "nanoid"; const ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789"; -const generateId = customAlphabet(ALPHABET, 12); +const generateId = nanoid.customAlphabet(ALPHABET, 12); export { generateId }; diff --git a/src/util/internal-case.js b/src/util/internal-case.js index 78c2aa5b..e56e84df 100644 --- a/src/util/internal-case.js +++ b/src/util/internal-case.js @@ -1,7 +1,7 @@ -import _ from "lodash"; +import * as lodash from "lodash"; function internalCase(value) { - return _.camelCase(_.lowerCase(value)); + return lodash.camelCase(lodash.lowerCase(value)); } export { internalCase }; diff --git a/src/util/logger.js b/src/util/logger.js index f671d528..0f293a9b 100644 --- a/src/util/logger.js +++ b/src/util/logger.js @@ -1,5 +1,5 @@ -import _ from "lodash"; -import { emojify } from "node-emoji"; +import * as lodash from "lodash"; +import * as nodeEmoji from "node-emoji"; class Logger { firstLog = true; @@ -15,7 +15,7 @@ class Logger { createLogMessage = ({ type, emojiName, messages }) => { if (this.config.silent) return; - const emoji = emojify(emojiName); + const emoji = nodeEmoji.emojify(emojiName); if (this.firstLog) { this.firstLog = false; @@ -43,8 +43,8 @@ class Logger { } logFn( "[message]", - ..._.map(messages, (message) => - _.startsWith(message, "\n") + ...lodash.map(messages, (message) => + lodash.startsWith(message, "\n") ? `\n ${message.replace(/\n/, "")}` : message, ), @@ -56,8 +56,8 @@ class Logger { console[type]( emoji, " ", - ..._.map(messages, (message) => - _.startsWith(message, "\n") + ...lodash.map(messages, (message) => + lodash.startsWith(message, "\n") ? `\n${emoji} ${message.replace(/\n/, "")}` : message, ), diff --git a/src/util/name-resolver.js b/src/util/name-resolver.js index 8d0ca42f..03f6503b 100644 --- a/src/util/name-resolver.js +++ b/src/util/name-resolver.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; class NameResolver { reservedNames = []; @@ -25,7 +25,7 @@ class NameResolver { * @param {string[]} names */ reserve(names) { - const fixedNames = _.uniq(_.compact(names)); + const fixedNames = lodash.uniq(lodash.compact(names)); for (const name of fixedNames) { if (this.reservedNames.indexOf(name) === -1) { this.reservedNames.push(name); @@ -40,7 +40,10 @@ class NameResolver { } isReserved(name) { - return _.some(this.reservedNames, (reservedName) => reservedName === name); + return lodash.some( + this.reservedNames, + (reservedName) => reservedName === name, + ); } /** @@ -72,9 +75,9 @@ class NameResolver { return usageName; } else if (Array.isArray(variants)) { let usageName = null; - const uniqVariants = _.uniq(_.compact(variants)); + const uniqVariants = lodash.uniq(lodash.compact(variants)); - _.forEach(uniqVariants, (variant) => { + lodash.forEach(uniqVariants, (variant) => { if (!usageName && (!shouldReserve || !this.isReserved(variant))) { usageName = variant; } diff --git a/src/util/object-assign.js b/src/util/object-assign.js index 3eaff3a8..d008a501 100644 --- a/src/util/object-assign.js +++ b/src/util/object-assign.js @@ -1,14 +1,13 @@ -import _ from "lodash"; +import * as lodash from "lodash"; const objectAssign = (target, updaterFn) => { if (!updaterFn) return; const update = typeof updaterFn === "function" ? updaterFn(target) : updaterFn; - const undefinedKeys = _.map( - update, - (value, key) => value === undefined && key, - ).filter(Boolean); - Object.assign(target, _.merge(target, update)); + const undefinedKeys = lodash + .map(update, (value, key) => value === undefined && key) + .filter(Boolean); + Object.assign(target, lodash.merge(target, update)); undefinedKeys.forEach((key) => { target[key] = undefined; }); diff --git a/src/util/pascal-case.js b/src/util/pascal-case.js index eb6b37d9..6fd57658 100644 --- a/src/util/pascal-case.js +++ b/src/util/pascal-case.js @@ -1,7 +1,7 @@ -import _ from "lodash"; +import * as lodash from "lodash"; function pascalCase(value) { - return _.upperFirst(_.camelCase(value)); + return lodash.upperFirst(lodash.camelCase(value)); } export { pascalCase }; diff --git a/src/util/request.js b/src/util/request.js index 2efa39ee..326f2736 100644 --- a/src/util/request.js +++ b/src/util/request.js @@ -1,4 +1,4 @@ -import _ from "lodash"; +import * as lodash from "lodash"; class Request { /** @@ -28,7 +28,7 @@ class Request { */ const requestOptions = {}; - if (disableStrictSSL && !_.startsWith(url, "http://")) { + if (disableStrictSSL && !lodash.startsWith(url, "http://")) { const undiciGlobalDispatcher = global[Symbol.for("undici.globalDispatcher.1")]; if (!undiciGlobalDispatcher) { @@ -47,7 +47,7 @@ class Request { }; } - _.merge(requestOptions, options, this.config.requestOptions); + lodash.merge(requestOptions, options, this.config.requestOptions); try { const response = await fetch(url, requestOptions);