swagger-typescript-api 13.0.27 → 13.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,18 +1,30 @@
1
1
  # swagger-typescript-api
2
2
 
3
+ ## 13.0.28
4
+
5
+ ### Patch Changes
6
+
7
+ - [`6851bdc`](https://github.com/acacode/swagger-typescript-api/commit/6851bdcafa83a80a2be09ea3d95b2ec45b81d24a) Thanks [@smorimoto](https://github.com/smorimoto)! - Fix description for `client` option in `generateCommand`.
8
+
9
+ - [#1121](https://github.com/acacode/swagger-typescript-api/pull/1121) [`5eadf67`](https://github.com/acacode/swagger-typescript-api/commit/5eadf67b038ef16f0489c6c7b614f3fdc57f1498) Thanks [@takayukioda](https://github.com/takayukioda)! - Fix to not use `no-` prefix in options.
10
+
11
+ - [`edca5de`](https://github.com/acacode/swagger-typescript-api/commit/edca5ded764b0fa4356ac49389f5d71b6784352d) Thanks [@smorimoto](https://github.com/smorimoto)! - Fix option name for `generateUnionEnums` in `generateCommand`.
12
+
13
+ - [`9fa8f41`](https://github.com/acacode/swagger-typescript-api/commit/9fa8f4113c8c24070da79cf2d3242ba433ca94d3) Thanks [@smorimoto](https://github.com/smorimoto)! - Sort the CLI arguments alphabetically.
14
+
3
15
  ## 13.0.27
4
16
 
5
17
  ### Patch Changes
6
18
 
7
- - [#1113](https://github.com/acacode/swagger-typescript-api/pull/1113) [`bdb3277`](https://github.com/acacode/swagger-typescript-api/commit/bdb3277302e566bbe182bd13c3ff22f07bd14aa6) Thanks [@smorimoto](https://github.com/smorimoto)! - Add `shims` option in tsup configuration and update `rootDir` path in templates generation process.
19
+ - [#1119](https://github.com/acacode/swagger-typescript-api/pull/1119) [`c5e8d45`](https://github.com/acacode/swagger-typescript-api/commit/c5e8d45d08edad509c23b3f66c2a6c0ffed570a2) Thanks [@smorimoto](https://github.com/smorimoto)! - Add `shims` option in tsup configuration and update `rootDir` path in templates generation process.
8
20
 
9
- - [#1051](https://github.com/acacode/swagger-typescript-api/pull/1051) [`1fe8e24`](https://github.com/acacode/swagger-typescript-api/commit/1fe8e249993642a3fe5cc8da47ef4288421f9774) Thanks [@yepninja](https://github.com/yepninja)! - Resolve internal references in Swagger v2 to OpenAPI v3 conversion by adding `resolveInternal` option and enhancing type definitions for request payloads.
21
+ - [#1119](https://github.com/acacode/swagger-typescript-api/pull/1119) [`c5e8d45`](https://github.com/acacode/swagger-typescript-api/commit/c5e8d45d08edad509c23b3f66c2a6c0ffed570a2) Thanks [@smorimoto](https://github.com/smorimoto)! - Resolve internal references in Swagger v2 to OpenAPI v3 conversion by adding `resolveInternal` option and enhancing type definitions for request payloads.
10
22
 
11
- - [#1118](https://github.com/acacode/swagger-typescript-api/pull/1118) [`00f8995`](https://github.com/acacode/swagger-typescript-api/commit/00f8995f621521e2c0b66ca1660cb3d839f81bc8) Thanks [@smorimoto](https://github.com/smorimoto)! - Fix default value for `no-client` option in `generateCommand` to `false`.
23
+ - [#1119](https://github.com/acacode/swagger-typescript-api/pull/1119) [`c5e8d45`](https://github.com/acacode/swagger-typescript-api/commit/c5e8d45d08edad509c23b3f66c2a6c0ffed570a2) Thanks [@smorimoto](https://github.com/smorimoto)! - Fix default value for `no-client` option in `generateCommand` to `false`.
12
24
 
13
- - [#1113](https://github.com/acacode/swagger-typescript-api/pull/1113) [`28d43b4`](https://github.com/acacode/swagger-typescript-api/commit/28d43b49604f6fa00155a4e4ac95322d5ca86713) Thanks [@smorimoto](https://github.com/smorimoto)! - Add `required` property to output path in `generateTemplatesCommand`.
25
+ - [#1119](https://github.com/acacode/swagger-typescript-api/pull/1119) [`c5e8d45`](https://github.com/acacode/swagger-typescript-api/commit/c5e8d45d08edad509c23b3f66c2a6c0ffed570a2) Thanks [@smorimoto](https://github.com/smorimoto)! - Add `required` property to output path in `generateTemplatesCommand`.
14
26
 
15
- - [#1069](https://github.com/acacode/swagger-typescript-api/pull/1069) [`c06af2e`](https://github.com/acacode/swagger-typescript-api/commit/c06af2e3cf9b03aa37e3652d5312975bb1292d28) Thanks [@yangdan8](https://github.com/yangdan8)! - Fix documentation and type definition to align with actual implementation by renaming `name` to `fileName`.
27
+ - [#1119](https://github.com/acacode/swagger-typescript-api/pull/1119) [`c5e8d45`](https://github.com/acacode/swagger-typescript-api/commit/c5e8d45d08edad509c23b3f66c2a6c0ffed570a2) Thanks [@smorimoto](https://github.com/smorimoto)! - Fix documentation and type definition to align with actual implementation by renaming `name` to `fileName`.
16
28
 
17
29
  ## 13.0.26
18
30
 
package/README.md CHANGED
@@ -29,7 +29,7 @@ Options:
29
29
  --union-enums generate all "enum" types as union types (T1 | T2 | TN) (default: false)
30
30
  --add-readonly generate readonly properties (default: false)
31
31
  --route-types generate type definitions for API routes (default: false)
32
- --no-client do not generate an API class
32
+ --[no-]client generate an API class (default: true)
33
33
  --enum-names-as-values use values in 'x-enumNames' as enum values (not only as keys) (default: false)
34
34
  --extract-request-params extract request params to data contract (Also combine path params and query params into one object) (default: false)
35
35
  --extract-request-body extract request body type to data contract (default: false)
@@ -1,5 +1,5 @@
1
1
  'use strict';var consola=require('consola'),u=require('lodash'),y=require('typescript'),it=require('prettier'),ht=require('cosmiconfig'),gt=require('nanoid'),Tt=require('js-yaml'),Pt=require('swagger2openapi'),x=require('path'),St=require('url'),Ct=require('eta'),N=require('fs');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var u__default=/*#__PURE__*/_interopDefault(u);var y__namespace=/*#__PURE__*/_interopNamespace(y);var it__namespace=/*#__PURE__*/_interopNamespace(it);var ht__namespace=/*#__PURE__*/_interopNamespace(ht);var gt__namespace=/*#__PURE__*/_interopNamespace(gt);var Tt__namespace=/*#__PURE__*/_interopNamespace(Tt);var Pt__namespace=/*#__PURE__*/_interopNamespace(Pt);var x__namespace=/*#__PURE__*/_interopNamespace(x);var St__namespace=/*#__PURE__*/_interopNamespace(St);var Ct__namespace=/*#__PURE__*/_interopNamespace(Ct);var N__namespace=/*#__PURE__*/_interopNamespace(N);var Dt=Object.defineProperty;var _t=(p,e)=>{for(var t in e)Dt(p,t,{get:e[t],enumerable:true});};var Kt=()=>typeof document>"u"?new URL(`file:${__filename}`).href:document.currentScript&&document.currentScript.src||new URL("main.js",document.baseURI).href,f=Kt();var te=class{config;constructor(e){this.config=e;}removeUnusedImports=e=>{let t="file.ts",s=new Ue(t,e),a=y__namespace.createLanguageService(s).organizeImports({type:"file",fileName:t},{newLineCharacter:y__namespace.sys.newLine},void 0)[0];return a?.textChanges.length?a.textChanges.reduceRight((i,{span:o,newText:n})=>`${i.slice(0,o.start)}${n}${i.slice(o.start+o.length)}`,e):e};prettierFormat=async e=>await it__namespace.format(e,this.config.prettierOptions);formatCode=async(e,{removeUnusedImports:t=true,prettierFormat:s=true}={})=>(t&&(e=this.removeUnusedImports(e)),s&&(e=await this.prettierFormat(e)),e)},Ue=class{fileName;content;compilerOptions;constructor(e,t){this.fileName=e,this.content=t;let s=y__namespace.findConfigFile(e,y__namespace.sys.fileExists);this.compilerOptions=s?y__namespace.convertCompilerOptionsFromJson(y__namespace.readConfigFile(s,y__namespace.sys.readFile).config.compilerOptions,"").options:y__namespace.getDefaultCompilerOptions();}getNewLine(){return "newLine"in y__namespace.sys?y__namespace.sys.newLine:`
2
- `}getScriptFileNames(){return [this.fileName]}getCompilationSettings(){return this.compilerOptions}getDefaultLibFileName(){return y__namespace.getDefaultLibFileName(this.getCompilationSettings())}getCurrentDirectory(){return process.cwd()}getScriptVersion(){return y__namespace.version}getScriptSnapshot(){return y__namespace.ScriptSnapshot.fromString(this.content)}readFile(e,t){return e===this.fileName?this.content:y__namespace.sys.readFile(e,t)}fileExists(e){return y__namespace.sys.fileExists(e)}};var A=class{reservedNames=[];getFallbackName;config;constructor(e,t,s){this.config=e,this.getFallbackName=s,this.reserve(t);}reserve(e){let t=u__default.default.uniq(u__default.default.compact(e));for(let s of t)this.reservedNames.indexOf(s)===-1&&this.reservedNames.push(s);}unreserve(e){this.reservedNames.filter(t=>!e.some(s=>s===t));}isReserved(e){return this.reservedNames.some(t=>t===e)}resolve(e,t,s,r=true){if(typeof t=="function"){let a=null;for(;a===null;){let i=t(e,s);if(i===void 0)return consola.consola.warn("unable to resolve name. current reserved names: ",...this.reservedNames),null;(!r||!this.isReserved(i))&&(a=i);}return r&&this.reserve([a]),a}if(Array.isArray(e)){let a=null,i=u__default.default.uniq(u__default.default.compact(e));for(let o of i)!a&&(!r||!this.isReserved(o))&&(a=o);return a?(r&&this.reserve([a]),a):(consola.consola.debug("trying to resolve name with using fallback name generator using variants",...e),this.resolve(e,this.getFallbackName,s))}return consola.consola.debug("problem with reserving names. current reserved names: ",...this.reservedNames),null}};var Ut=(p=0,e=1)=>Math.random()*(e-p)+p,nt=(p=0,e=1)=>p===e?p:Math.round(Ut(p,e));var re=class extends A{counter=1;fallbackNameCounter=1;countersByVariant=new Map;constructor(e,t){super(e,t,s=>{let r=s[nt(0,s.length-1)];if(r){this.countersByVariant.has(r)||this.countersByVariant.set(r,0);let i=this.countersByVariant.get(r)+1;this.countersByVariant.set(r,i);let o=`${r}${i}`;return consola.consola.debug("generated dirty resolved type name for component - ",o),o}let a=`${this.config.componentTypeNameResolver}${this.fallbackNameCounter++}`;return consola.consola.debug("generated fallback type name for component - ",a),a});}};var ie={};_t(ie,{DEFAULT_BODY_ARG_NAME:()=>Ge,FILE_PREFIX:()=>Gt,HTTP_CLIENT:()=>H,PRETTIER_OPTIONS:()=>ae,PROJECT_VERSION:()=>J,RESERVED_BODY_ARG_NAMES:()=>We,RESERVED_HEADER_ARG_NAMES:()=>Ve,RESERVED_PATH_ARG_NAMES:()=>Be,RESERVED_QUERY_ARG_NAMES:()=>Le,RESERVED_REQ_PARAMS_ARG_NAMES:()=>Wt,SCHEMA_TYPES:()=>l});var ct={name:"swagger-typescript-api",version:"13.0.27",description:"Generate the API client for Fetch or Axios from an OpenAPI Specification",homepage:"https://github.com/acacode/swagger-typescript-api",bugs:"https://github.com/acacode/swagger-typescript-api/issues",repository:"github:acacode/swagger-typescript-api",license:"MIT",author:"Sergey Volkov <js2me@outlook.com>",contributors:["Sora Morimoto <sora@morimoto.io>"],type:"module",exports:{".":{import:{default:"./dist/lib.js"},require:{default:"./dist/lib.cjs"}}},main:"./dist/lib.cjs",module:"./dist/lib.js",bin:{sta:"./dist/cli.js","swagger-typescript-api":"./dist/cli.js"},files:["dist","templates"],scripts:{build:"tsup","cli:help":"node index.js -h","cli:json":"node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts","cli:yaml":"node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",format:"biome format --write .","format:check":"biome format .",lint:"biome check",prepack:"tsup",test:"vitest run"},dependencies:{"@types/swagger-schema-official":"^2.0.25",citty:"^0.1.6",consola:"^3.4.2",cosmiconfig:"^9.0.0",eta:"^2.2.0","js-yaml":"^4.1.0",lodash:"^4.17.21",nanoid:"^5.1.5",prettier:"~3.5.3","swagger-schema-official":"2.0.0-bab6bed",swagger2openapi:"^7.0.8",typescript:"~5.8.2"},devDependencies:{"@biomejs/biome":"1.9.4","@changesets/changelog-github":"0.5.1","@changesets/cli":"2.28.1","@tsconfig/node18":"18.2.4","@tsconfig/strictest":"2.0.5","@types/js-yaml":"4.0.9","@types/lodash":"4.17.16","@types/node":"22.13.13","@types/swagger2openapi":"7.0.4",axios:"1.8.4","openapi-types":"12.1.3",tsup:"8.4.0",vitest:"3.0.9"},packageManager:"yarn@4.7.0",engines:{node:">=18.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var Ge="data",Gt=`/* eslint-disable */
2
+ `}getScriptFileNames(){return [this.fileName]}getCompilationSettings(){return this.compilerOptions}getDefaultLibFileName(){return y__namespace.getDefaultLibFileName(this.getCompilationSettings())}getCurrentDirectory(){return process.cwd()}getScriptVersion(){return y__namespace.version}getScriptSnapshot(){return y__namespace.ScriptSnapshot.fromString(this.content)}readFile(e,t){return e===this.fileName?this.content:y__namespace.sys.readFile(e,t)}fileExists(e){return y__namespace.sys.fileExists(e)}};var A=class{reservedNames=[];getFallbackName;config;constructor(e,t,s){this.config=e,this.getFallbackName=s,this.reserve(t);}reserve(e){let t=u__default.default.uniq(u__default.default.compact(e));for(let s of t)this.reservedNames.indexOf(s)===-1&&this.reservedNames.push(s);}unreserve(e){this.reservedNames.filter(t=>!e.some(s=>s===t));}isReserved(e){return this.reservedNames.some(t=>t===e)}resolve(e,t,s,r=true){if(typeof t=="function"){let a=null;for(;a===null;){let i=t(e,s);if(i===void 0)return consola.consola.warn("unable to resolve name. current reserved names: ",...this.reservedNames),null;(!r||!this.isReserved(i))&&(a=i);}return r&&this.reserve([a]),a}if(Array.isArray(e)){let a=null,i=u__default.default.uniq(u__default.default.compact(e));for(let o of i)!a&&(!r||!this.isReserved(o))&&(a=o);return a?(r&&this.reserve([a]),a):(consola.consola.debug("trying to resolve name with using fallback name generator using variants",...e),this.resolve(e,this.getFallbackName,s))}return consola.consola.debug("problem with reserving names. current reserved names: ",...this.reservedNames),null}};var Ut=(p=0,e=1)=>Math.random()*(e-p)+p,nt=(p=0,e=1)=>p===e?p:Math.round(Ut(p,e));var re=class extends A{counter=1;fallbackNameCounter=1;countersByVariant=new Map;constructor(e,t){super(e,t,s=>{let r=s[nt(0,s.length-1)];if(r){this.countersByVariant.has(r)||this.countersByVariant.set(r,0);let i=this.countersByVariant.get(r)+1;this.countersByVariant.set(r,i);let o=`${r}${i}`;return consola.consola.debug("generated dirty resolved type name for component - ",o),o}let a=`${this.config.componentTypeNameResolver}${this.fallbackNameCounter++}`;return consola.consola.debug("generated fallback type name for component - ",a),a});}};var ie={};_t(ie,{DEFAULT_BODY_ARG_NAME:()=>Ge,FILE_PREFIX:()=>Gt,HTTP_CLIENT:()=>H,PRETTIER_OPTIONS:()=>ae,PROJECT_VERSION:()=>J,RESERVED_BODY_ARG_NAMES:()=>We,RESERVED_HEADER_ARG_NAMES:()=>Ve,RESERVED_PATH_ARG_NAMES:()=>Be,RESERVED_QUERY_ARG_NAMES:()=>Le,RESERVED_REQ_PARAMS_ARG_NAMES:()=>Wt,SCHEMA_TYPES:()=>l});var ct={name:"swagger-typescript-api",version:"13.0.28",description:"Generate the API client for Fetch or Axios from an OpenAPI Specification",homepage:"https://github.com/acacode/swagger-typescript-api",bugs:"https://github.com/acacode/swagger-typescript-api/issues",repository:"github:acacode/swagger-typescript-api",license:"MIT",author:"Sergey Volkov <js2me@outlook.com>",contributors:["Sora Morimoto <sora@morimoto.io>"],type:"module",exports:{".":{import:{default:"./dist/lib.js"},require:{default:"./dist/lib.cjs"}}},main:"./dist/lib.cjs",module:"./dist/lib.js",bin:{sta:"./dist/cli.js","swagger-typescript-api":"./dist/cli.js"},files:["dist","templates"],scripts:{build:"tsup","cli:help":"node index.js -h","cli:json":"node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts","cli:yaml":"node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",format:"biome format --write .","format:check":"biome format .",lint:"biome check",prepack:"tsup",test:"vitest run"},dependencies:{"@types/swagger-schema-official":"^2.0.25",citty:"^0.1.6",consola:"^3.4.2",cosmiconfig:"^9.0.0",eta:"^2.2.0","js-yaml":"^4.1.0",lodash:"^4.17.21",nanoid:"^5.1.5",prettier:"~3.5.3","swagger-schema-official":"2.0.0-bab6bed",swagger2openapi:"^7.0.8",typescript:"~5.8.2"},devDependencies:{"@biomejs/biome":"1.9.4","@changesets/changelog-github":"0.5.1","@changesets/cli":"2.28.1","@tsconfig/node18":"18.2.4","@tsconfig/strictest":"2.0.5","@types/js-yaml":"4.0.9","@types/lodash":"4.17.16","@types/node":"22.13.13","@types/swagger2openapi":"7.0.4",axios:"1.8.4","openapi-types":"12.1.3",tsup:"8.4.0",vitest:"3.0.9"},packageManager:"yarn@4.7.0",engines:{node:">=18.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org"}};var Ge="data",Gt=`/* eslint-disable */
3
3
  /* tslint:disable */
4
4
  // @ts-nocheck
5
5
  /*
@@ -38,5 +38,5 @@ ${e}
38
38
 
39
39
  `,V=class{getFileContent=e=>N__namespace.readFileSync(e,{encoding:"utf8"});readDir=e=>N__namespace.readdirSync(e);pathIsDir=e=>{if(!e)return false;try{return N__namespace.statSync(e).isDirectory()}catch{return false}};cropExtension=e=>{let t=e.split(".");return t.length>1&&t.pop(),t.join(".")};removeDir=e=>{try{typeof N__namespace.rmSync=="function"?N__namespace.rmSync(e,{recursive:!0}):N__namespace.rmdirSync(e,{recursive:!0});}catch(t){consola.consola.debug("failed to remove dir",t);}};createDir=e=>{try{N__namespace.mkdirSync(e,{recursive:!0});}catch(t){consola.consola.debug("failed to create dir",t);}};cleanDir=e=>{this.removeDir(e),this.createDir(e);};pathIsExist=e=>!!e&&N__namespace.existsSync(e);createFile=({path:e,fileName:t,content:s,withPrefix:r})=>{let a=x__namespace.dirname(St__namespace.fileURLToPath(f)),i=x__namespace.resolve(a,e,`./${t}`),o=`${r?es:""}${s}`;return N__namespace.writeFileSync(i,o)}};var ts=["schemaWalker","swaggerSchemaResolver","schemaComponentsMap","typeNameFormatter","templatesWorker","codeFormatter","schemaParserFabric","schemaRoutes","javascriptTranslator"],ke=class{config;swaggerSchemaResolver;schemaComponentsMap;typeNameFormatter;schemaParserFabric;schemaRoutes;fileSystem;codeFormatter;templatesWorker;schemaWalker;javascriptTranslator;constructor(e){this.config=new ne(e),this.fileSystem=new V,this.swaggerSchemaResolver=new Ae(this.config,this.fileSystem),this.schemaWalker=new Ee(this.config,this.swaggerSchemaResolver),this.schemaComponentsMap=new ce(this.config),this.typeNameFormatter=new Me(this.config),this.templatesWorker=new Oe(this.config,this.fileSystem,this.getRenderTemplateData),this.codeFormatter=new te(this.config),this.schemaParserFabric=new we(this.config,this.templatesWorker,this.schemaComponentsMap,this.typeNameFormatter,this.schemaWalker),this.schemaRoutes=new xe(this.config,this.schemaParserFabric,this.schemaComponentsMap,this.templatesWorker,this.typeNameFormatter),this.javascriptTranslator=new $e(this.config,this.codeFormatter);}async start(){this.config.update({templatePaths:this.templatesWorker.getTemplatePaths(this.config)}),this.config.update({templatesToRender:this.templatesWorker.getTemplates(this.config)});let e=await this.swaggerSchemaResolver.create();this.swaggerSchemaResolver.fixSwaggerSchema(e),this.config.update({swaggerSchema:e.usageSchema,originalSchema:e.originalSchema}),this.schemaWalker.addSchema("$usage",e.usageSchema),this.schemaWalker.addSchema("$original",e.originalSchema),consola.consola.info("start generating your typescript api"),this.config.update(this.config.hooks.onInit(this.config,this)||this.config),this.schemaComponentsMap.clear(),u__default.default.each(e.usageSchema.components,(n,c)=>u__default.default.each(n,(h,m)=>{this.schemaComponentsMap.createComponent(this.schemaComponentsMap.createRef(["components",c,m]),h);}));let s=this.schemaComponentsMap.filter(u__default.default.compact(["schemas",this.config.extractResponses&&"responses"])).map(n=>{let c=this.schemaParserFabric.parseSchema(n.rawTypeData,n.typeName);return n.typeData=c,c});this.schemaRoutes.attachSchema({usageSchema:e.usageSchema,parsedSchemas:s});let r={apiConfig:this.createApiConfig(e.usageSchema),config:this.config,modelTypes:this.collectModelTypes(),hasSecurityRoutes:this.schemaRoutes.hasSecurityRoutes,hasQueryRoutes:this.schemaRoutes.hasQueryRoutes,hasFormDataRoutes:this.schemaRoutes.hasFormDataRoutes,generateResponses:this.config.generateResponses,routes:this.schemaRoutes.getGroupedRoutes(),extraTemplates:this.config.extraTemplates,fileName:this.config.fileName,translateToJavaScript:this.config.toJS,customTranslator:this.config.customTranslator?new this.config.customTranslator:null,utils:this.getRenderTemplateData().utils},a=this.config.hooks.onPrepareConfig(r)||r;this.fileSystem.pathIsExist(this.config.output)?this.config.cleanOutput&&(consola.consola.debug("cleaning dir",this.config.output),this.fileSystem.cleanDir(this.config.output)):(consola.consola.debug(`path ${this.config.output} is not exist. creating dir by this path`),this.fileSystem.createDir(this.config.output));let i=await this.generateOutputFiles({configuration:a});if(this.fileSystem.pathIsDir(this.config.output))for(let n of i)this.fileSystem.createFile({path:this.config.output,fileName:`${n.fileName}${n.fileExtension}`,content:n.fileContent,withPrefix:true}),consola.consola.success("api file",`"${n.fileName}${n.fileExtension}"`,`created in ${this.config.output}`);return {files:i,configuration:a,getTemplate:this.templatesWorker.getTemplate,renderTemplate:this.templatesWorker.renderTemplate,createFile:this.fileSystem.createFile,formatTSContent:this.codeFormatter.formatCode}}getRenderTemplateData=()=>({utils:{Ts:this.config.Ts,formatDescription:this.schemaParserFabric.schemaFormatters.formatDescription,internalCase:Q,classNameCase:O,pascalCase:O,getInlineParseContent:this.schemaParserFabric.getInlineParseContent,getParseContent:this.schemaParserFabric.getParseContent,getComponentByRef:this.schemaComponentsMap.get,parseSchema:this.schemaParserFabric.parseSchema,checkAndAddNull:this.schemaParserFabric.schemaUtils.safeAddNullToType,safeAddNullToType:this.schemaParserFabric.schemaUtils.safeAddNullToType,isNeedToAddNull:this.schemaParserFabric.schemaUtils.isNullMissingInType,inlineExtraFormatters:this.schemaParserFabric.schemaFormatters.inline,formatters:this.schemaParserFabric.schemaFormatters.base,formatModelName:this.typeNameFormatter.format,fmtToJSDocLine:(e,{eol:t=true})=>` * ${e}${t?`
40
40
  `:""}`,NameResolver:A,_:u__default.default,require:this.templatesWorker.requireFnFromTemplate},config:this.config});collectModelTypes=()=>{let e=this.schemaComponentsMap.getComponents(),t=[],s=u__default.default.compact(["schemas",this.config.extractResponses&&"responses"]),r=()=>this.schemaComponentsMap.filter(...s).length,a=r(),i=0;for(;i<a;){t=[],i=0;for(let o of e)if(s.includes(o.componentName)){let n=this.prepareModelType(o);n&&t.push(n),i++;}a=r();}return this.config.sortTypes?t.sort(pe("name")):t};prepareModelType=e=>{if(e.$prepared)return e.$prepared;e.typeData||(e.typeData=this.schemaParserFabric.parseSchema(e.rawTypeData,e.typeName));let t=e.typeData,s=this.schemaParserFabric.schemaFormatters.base[t.type]?this.schemaParserFabric.schemaFormatters.base[t.type](t):t,{typeIdentifier:r,name:a,content:i,description:o}=s,n=this.typeNameFormatter.format(a);if(n===null)return null;let c={...s,typeIdentifier:r,name:n,description:o,$content:t.content,rawContent:t.content,content:i,typeData:s};return e.$prepared=c,c};generateOutputFiles=async({configuration:e})=>{let{modular:t,templatesToRender:s}=this.config,r=t?await this.createMultipleFileInfos(s,e):await this.createSingleFileInfo(s,e);if(!u__default.default.isEmpty(e.extraTemplates))for(let a of e.extraTemplates){let i=this.templatesWorker.renderTemplate(this.fileSystem.getFileContent(a.path),e);r.push(...await this.createOutputFileInfo(e,a.name,i));}return r.filter(a=>!!a&&!!a.fileContent)};createMultipleFileInfos=async(e,t)=>{let{routes:s}=t,{fileNames:r,generateRouteTypes:a,generateClient:i}=t.config,o=[];if(s.$outOfModule){if(a){let n=this.templatesWorker.renderTemplate(e.routeTypes,{...t,route:t.routes.$outOfModule});o.push(...await this.createOutputFileInfo(t,r.outOfModuleApi,n));}if(i){let n=this.templatesWorker.renderTemplate(e.api,{...t,route:t.routes.$outOfModule});o.push(...await this.createOutputFileInfo(t,r.outOfModuleApi,n));}}if(s.combined)for(let n of s.combined){if(a){let c=this.templatesWorker.renderTemplate(e.routeTypes,{...t,route:n});o.push(...await this.createOutputFileInfo(t,O(`${n.moduleName}_Route`),c));}if(i){let c=this.templatesWorker.renderTemplate(e.api,{...t,route:n});o.push(...await this.createOutputFileInfo(t,O(n.moduleName),c));}}return [...await this.createOutputFileInfo(t,r.dataContracts,this.templatesWorker.renderTemplate(e.dataContracts,t)),...i?await this.createOutputFileInfo(t,r.httpClient,this.templatesWorker.renderTemplate(e.httpClient,t)):[],...o]};createSingleFileInfo=async(e,t)=>{let{generateRouteTypes:s,generateClient:r}=t.config;return await this.createOutputFileInfo(t,t.fileName,u__default.default.compact([this.templatesWorker.renderTemplate(e.dataContracts,t),s&&this.templatesWorker.renderTemplate(e.routeTypes,t),r&&this.templatesWorker.renderTemplate(e.httpClient,t),r&&this.templatesWorker.renderTemplate(e.api,t)]).join(`
41
- `))};createOutputFileInfo=async(e,t,s)=>{let r=this.fileSystem.cropExtension(t),a=y__namespace.Extension.Ts;return e.translateToJavaScript?(consola.consola.debug("using js translator for",r),await this.javascriptTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):e.customTranslator?(consola.consola.debug("using custom translator for",r),await e.customTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):(consola.consola.debug("generating output for",`${r}${a}`),[{fileName:r,fileExtension:a,fileContent:await this.codeFormatter.formatCode(s)}])};createApiConfig=e=>{let{info:t,servers:s,host:r,basePath:a,externalDocs:i,tags:o}=e,n=s?.[0]||{url:""},{title:c="No title",version:h}=t||{},{url:m}=n;return {info:t||{},servers:s||[],basePath:a,host:r,externalDocs:u__default.default.merge({url:"",description:""},i),tags:u__default.default.compact(o),baseUrl:m,title:c,version:h}};injectClassInstance=(e,t)=>{this[e]=t;for(let s of ts)s!==e&&e in this[s]&&(this[s][e]=t);}};var je=class{cleanOutput=false;output=void 0;httpClientType=H.FETCH;modular=false;rewrite=false;silent=false;debug=false;version=J;constructor(e){this.update(e);}update=e=>{U(this,e);}};var rs=x__namespace.default.dirname(St__namespace.default.fileURLToPath(f)),De=class{config;fileSystem;rootDir=x__namespace.default.resolve(rs,"..");paths={baseTemplates:"templates/base",httpClientTemplates:"templates/base/http-clients",moduleApiTemplates:"templates/modular",defaultApiTemplates:"templates/default"};importTemplatePrefixes=["@base","@modular","@default"];constructor(e){this.config=new je(e),this.fileSystem=new V;}async start(){consola.consola.info('start generating source templates ".ejs" for code generator');let e=this.getTemplates();if(this.config.output){consola.consola.info("preparing output directory for source templates");let t=x__namespace.default.resolve(process.cwd(),this.config.output);this.fileSystem.pathIsExist(t)?this.config.cleanOutput&&this.fileSystem.cleanDir(t):this.fileSystem.createDir(t);for(let s of e){let r=this.fileSystem.cropExtension(s.name),a=x__namespace.default.resolve(t,`${r}.ejs`),i=x__namespace.default.resolve(t,`${r}.eta`),o=this.fileSystem.pathIsExist(a),n=this.fileSystem.pathIsExist(i);!o&&!n?this.fileSystem.createFile({path:t,fileName:s.name,content:s.content,withPrefix:false}):this.config.rewrite&&(o?this.fileSystem.createFile({path:t,fileName:`${r}.ejs`,content:s.content,withPrefix:false}):n&&this.fileSystem.createFile({path:t,fileName:`${r}.eta`,content:s.content,withPrefix:false}));}consola.consola.success(`source templates has been successfully created in "${t}"`);}return {files:e,configuration:this.config,createFile:this.fileSystem.createFile}}getTemplates=()=>{let e=[],t=this.getTemplateNamesFromDir(this.paths.baseTemplates),s=this.getTemplateNamesFromDir(this.paths.httpClientTemplates),r=this.config.modular?this.paths.moduleApiTemplates:this.paths.defaultApiTemplates,a=this.getTemplateNamesFromDir(r),i=s.find(n=>n.startsWith(`${this.config.httpClientType}-`)),o="";i&&(o=this.fixTemplateContent(this.getTemplateContent(`${this.paths.httpClientTemplates}/${i}`)));for(let n of t){let c=n==="http-client.ejs"&&o||this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${n}`));e.push({name:n,content:c});}for(let n of a)e.push({name:n,content:this.fixTemplateContent(this.getTemplateContent(`${r}/${n}`))});return e};fixTemplateContent=e=>{let t=new RegExp(`includeFile\\("(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),s=new RegExp(`includeFile\\(\`(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),r=new RegExp(`includeFile\\('(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g");return e.replace(t,'includeFile("./').replace(s,"includeFile(`./").replace(r,"includeFile('./")};getTemplateNamesFromDir=e=>this.fileSystem.readDir(x__namespace.default.resolve(this.rootDir,e)).filter(t=>t.endsWith(".ejs"));getTemplateContent=e=>this.fileSystem.getFileContent(x__namespace.default.resolve(this.rootDir,e))};async function as(p){return p.debug&&(consola.consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.consola.level=0),await new De(p).start()}async function ki(p){return p.debug&&(consola.consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.consola.level=0),await new ke(p).start()}exports.a=ct;exports.b=H;exports.c=ie;exports.d=ne;exports.e=je;exports.f=as;exports.g=ki;//# sourceMappingURL=chunk-NP4SPLZD.cjs.map
42
- //# sourceMappingURL=chunk-NP4SPLZD.cjs.map
41
+ `))};createOutputFileInfo=async(e,t,s)=>{let r=this.fileSystem.cropExtension(t),a=y__namespace.Extension.Ts;return e.translateToJavaScript?(consola.consola.debug("using js translator for",r),await this.javascriptTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):e.customTranslator?(consola.consola.debug("using custom translator for",r),await e.customTranslator.translate({fileName:r,fileExtension:a,fileContent:s})):(consola.consola.debug("generating output for",`${r}${a}`),[{fileName:r,fileExtension:a,fileContent:await this.codeFormatter.formatCode(s)}])};createApiConfig=e=>{let{info:t,servers:s,host:r,basePath:a,externalDocs:i,tags:o}=e,n=s?.[0]||{url:""},{title:c="No title",version:h}=t||{},{url:m}=n;return {info:t||{},servers:s||[],basePath:a,host:r,externalDocs:u__default.default.merge({url:"",description:""},i),tags:u__default.default.compact(o),baseUrl:m,title:c,version:h}};injectClassInstance=(e,t)=>{this[e]=t;for(let s of ts)s!==e&&e in this[s]&&(this[s][e]=t);}};var je=class{cleanOutput=false;debug=false;httpClientType=H.FETCH;modular=false;output=void 0;rewrite=false;silent=false;version=J;constructor(e){this.update(e);}update=e=>{U(this,e);}};var rs=x__namespace.default.dirname(St__namespace.default.fileURLToPath(f)),De=class{config;fileSystem;rootDir=x__namespace.default.resolve(rs,"..");paths={baseTemplates:"templates/base",httpClientTemplates:"templates/base/http-clients",moduleApiTemplates:"templates/modular",defaultApiTemplates:"templates/default"};importTemplatePrefixes=["@base","@modular","@default"];constructor(e){this.config=new je(e),this.fileSystem=new V;}async start(){consola.consola.info('start generating source templates ".ejs" for code generator');let e=this.getTemplates();if(this.config.output){consola.consola.info("preparing output directory for source templates");let t=x__namespace.default.resolve(process.cwd(),this.config.output);this.fileSystem.pathIsExist(t)?this.config.cleanOutput&&this.fileSystem.cleanDir(t):this.fileSystem.createDir(t);for(let s of e){let r=this.fileSystem.cropExtension(s.name),a=x__namespace.default.resolve(t,`${r}.ejs`),i=x__namespace.default.resolve(t,`${r}.eta`),o=this.fileSystem.pathIsExist(a),n=this.fileSystem.pathIsExist(i);!o&&!n?this.fileSystem.createFile({path:t,fileName:s.name,content:s.content,withPrefix:false}):this.config.rewrite&&(o?this.fileSystem.createFile({path:t,fileName:`${r}.ejs`,content:s.content,withPrefix:false}):n&&this.fileSystem.createFile({path:t,fileName:`${r}.eta`,content:s.content,withPrefix:false}));}consola.consola.success(`source templates has been successfully created in "${t}"`);}return {files:e,configuration:this.config,createFile:this.fileSystem.createFile}}getTemplates=()=>{let e=[],t=this.getTemplateNamesFromDir(this.paths.baseTemplates),s=this.getTemplateNamesFromDir(this.paths.httpClientTemplates),r=this.config.modular?this.paths.moduleApiTemplates:this.paths.defaultApiTemplates,a=this.getTemplateNamesFromDir(r),i=s.find(n=>n.startsWith(`${this.config.httpClientType}-`)),o="";i&&(o=this.fixTemplateContent(this.getTemplateContent(`${this.paths.httpClientTemplates}/${i}`)));for(let n of t){let c=n==="http-client.ejs"&&o||this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${n}`));e.push({name:n,content:c});}for(let n of a)e.push({name:n,content:this.fixTemplateContent(this.getTemplateContent(`${r}/${n}`))});return e};fixTemplateContent=e=>{let t=new RegExp(`includeFile\\("(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),s=new RegExp(`includeFile\\(\`(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g"),r=new RegExp(`includeFile\\('(${this.importTemplatePrefixes.map(a=>`(${a})`).join("|")})/`,"g");return e.replace(t,'includeFile("./').replace(s,"includeFile(`./").replace(r,"includeFile('./")};getTemplateNamesFromDir=e=>this.fileSystem.readDir(x__namespace.default.resolve(this.rootDir,e)).filter(t=>t.endsWith(".ejs"));getTemplateContent=e=>this.fileSystem.getFileContent(x__namespace.default.resolve(this.rootDir,e))};async function as(p){return p.debug&&(consola.consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.consola.level=0),await new De(p).start()}async function ki(p){return p.debug&&(consola.consola.level=Number.MAX_SAFE_INTEGER),p.silent&&(consola.consola.level=0),await new ke(p).start()}exports.a=ct;exports.b=H;exports.c=ie;exports.d=ne;exports.e=je;exports.f=as;exports.g=ki;//# sourceMappingURL=chunk-5CTG45B7.cjs.map
42
+ //# sourceMappingURL=chunk-5CTG45B7.cjs.map