11import { consola } from "consola" ;
2- import lodash from "lodash" ;
2+ import { compact , merge } from "es-toolkit" ;
3+ import { camelCase } from "es-toolkit/compat" ;
34import * as typescript from "typescript" ;
45import type {
56 GenerateApiConfiguration ,
@@ -17,7 +18,7 @@ import { JavascriptTranslator } from "./translators/javascript.js";
1718import type { TranslatorIO } from "./translators/translator.js" ;
1819import { TypeNameFormatter } from "./type-name-formatter.js" ;
1920import { FileSystem } from "./util/file-system.js" ;
20- import { internalCase } from "./util/internal-case .js" ;
21+ import { createLodashCompat } from "./util/lodash-compat .js" ;
2122import { NameResolver } from "./util/name-resolver.js" ;
2223import { pascalCase } from "./util/pascal-case.js" ;
2324import { sortByProperty } from "./util/sort-by-property.js" ;
@@ -121,8 +122,12 @@ export class CodeGenProcess {
121122
122123 this . schemaComponentsMap . clear ( ) ;
123124
124- lodash . each ( swagger . usageSchema . components , ( component , componentName ) =>
125- lodash . each ( component , ( rawTypeData , typeName ) => {
125+ for ( const [ componentName , component ] of Object . entries (
126+ swagger . usageSchema . components || { } ,
127+ ) ) {
128+ for ( const [ typeName , rawTypeData ] of Object . entries (
129+ component as Record < string , unknown > ,
130+ ) ) {
126131 this . schemaComponentsMap . createComponent (
127132 this . schemaComponentsMap . createRef ( [
128133 "components" ,
@@ -131,8 +136,8 @@ export class CodeGenProcess {
131136 ] ) ,
132137 rawTypeData ,
133138 ) ;
134- } ) ,
135- ) ;
139+ }
140+ }
136141
137142 // Set all discriminators at the top
138143 this . schemaComponentsMap . discriminatorsFirst ( ) ;
@@ -141,10 +146,7 @@ export class CodeGenProcess {
141146
142147 const componentsToParse : SchemaComponent [ ] =
143148 this . schemaComponentsMap . filter (
144- lodash . compact ( [
145- "schemas" ,
146- this . config . extractResponses && "responses" ,
147- ] ) ,
149+ compact ( [ "schemas" , this . config . extractResponses && "responses" ] ) ,
148150 ) ;
149151
150152 const parsedSchemas = componentsToParse . map ( ( schemaComponent ) => {
@@ -233,7 +235,7 @@ export class CodeGenProcess {
233235 Ts : this . config . Ts ,
234236 formatDescription :
235237 this . schemaParserFabric . schemaFormatters . formatDescription ,
236- internalCase : internalCase ,
238+ internalCase : camelCase ,
237239 classNameCase : pascalCase ,
238240 pascalCase : pascalCase ,
239241 getInlineParseContent : this . schemaParserFabric . getInlineParseContent ,
@@ -252,7 +254,7 @@ export class CodeGenProcess {
252254 return ` * ${ line } ${ eol ? "\n" : "" } ` ;
253255 } ,
254256 NameResolver : NameResolver ,
255- _ : lodash ,
257+ _ : createLodashCompat ( ) ,
256258 require : this . templatesWorker . requireFnFromTemplate ,
257259 } ,
258260 config : this . config ,
@@ -263,7 +265,7 @@ export class CodeGenProcess {
263265 const components = this . schemaComponentsMap . getComponents ( ) ;
264266 let modelTypes = [ ] ;
265267
266- const modelTypeComponents = lodash . compact ( [
268+ const modelTypeComponents = compact ( [
267269 "schemas" ,
268270 this . config . extractResponses && "responses" ,
269271 ] ) ;
@@ -346,7 +348,7 @@ export class CodeGenProcess {
346348 ? await this . createMultipleFileInfos ( templatesToRender , configuration )
347349 : await this . createSingleFileInfo ( templatesToRender , configuration ) ;
348350
349- if ( ! lodash . isEmpty ( configuration . extraTemplates ) ) {
351+ if ( configuration . extraTemplates ?. length ) {
350352 for ( const extraTemplate of configuration . extraTemplates ) {
351353 const content = this . templatesWorker . renderTemplate (
352354 this . fileSystem . getFileContent ( extraTemplate . path ) ,
@@ -483,29 +485,27 @@ export class CodeGenProcess {
483485 return await this . createOutputFileInfo (
484486 configuration ,
485487 configuration . fileName ,
486- lodash
487- . compact ( [
488+ compact ( [
489+ this . templatesWorker . renderTemplate (
490+ templatesToRender . dataContracts ,
491+ configuration ,
492+ ) ,
493+ generateRouteTypes &&
488494 this . templatesWorker . renderTemplate (
489- templatesToRender . dataContracts ,
495+ templatesToRender . routeTypes ,
490496 configuration ,
491497 ) ,
492- generateRouteTypes &&
493- this . templatesWorker . renderTemplate (
494- templatesToRender . routeTypes ,
495- configuration ,
496- ) ,
497- generateClient &&
498- this . templatesWorker . renderTemplate (
499- templatesToRender . httpClient ,
500- configuration ,
501- ) ,
502- generateClient &&
503- this . templatesWorker . renderTemplate (
504- templatesToRender . api ,
505- configuration ,
506- ) ,
507- ] )
508- . join ( "\n" ) ,
498+ generateClient &&
499+ this . templatesWorker . renderTemplate (
500+ templatesToRender . httpClient ,
501+ configuration ,
502+ ) ,
503+ generateClient &&
504+ this . templatesWorker . renderTemplate (
505+ templatesToRender . api ,
506+ configuration ,
507+ ) ,
508+ ] ) . join ( "\n" ) ,
509509 ) ;
510510 } ;
511511
@@ -557,14 +557,14 @@ export class CodeGenProcess {
557557 servers : servers || [ ] ,
558558 basePath,
559559 host,
560- externalDocs : lodash . merge (
560+ externalDocs : merge (
561561 {
562562 url : "" ,
563563 description : "" ,
564564 } ,
565- externalDocs ,
565+ externalDocs || { } ,
566566 ) ,
567- tags : lodash . compact ( tags ) ,
567+ tags : compact ( tags || [ ] ) ,
568568 baseUrl : serverUrl ,
569569 title,
570570 version,
0 commit comments