swagger-typescript-api 13.0.27 → 13.1.0

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/dist/cli.cjs CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- 'use strict';var chunkNP4SPLZD_cjs=require('./chunk-NP4SPLZD.cjs'),i=require('path'),f=require('url'),citty=require('citty'),consola=require('consola');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 i__namespace=/*#__PURE__*/_interopNamespace(i);var f__namespace=/*#__PURE__*/_interopNamespace(f);var o=new chunkNP4SPLZD_cjs.e({}),b=citty.defineCommand({meta:{name:"generate-templates",description:'Generate ".ejs" templates needed for generate api'},args:{"clean-output":{type:"boolean",description:"clean output folder before generate template. WARNING: May cause data loss",default:o.cleanOutput},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(chunkNP4SPLZD_cjs.b)})`,default:o.httpClientType},modular:{type:"boolean",description:"generate templates needed to separate files for http client, data contracts, and routes",default:o.modular},output:{type:"string",alias:"o",description:"output path of generated templates",default:o.output,required:true},rewrite:{type:"boolean",alias:"r",description:"rewrite content in existing templates",default:o.rewrite},silent:{type:"boolean",description:"Output only errors to console",default:o.silent},debug:{type:"boolean",description:"additional information about processes inside this tool",default:o.debug}},run:async({args:e})=>{await chunkNP4SPLZD_cjs.f({cleanOutput:e["clean-output"],httpClientType:e["http-client"],modular:e.modular,output:e.output,rewrite:e.rewrite,silent:e.silent,debug:e.debug});}}),t=new chunkNP4SPLZD_cjs.d({}),h=citty.defineCommand({meta:{name:"generate",description:chunkNP4SPLZD_cjs.a.description},args:{path:{type:"string",alias:"p",description:"path/url to swagger scheme",required:true},output:{type:"string",alias:"o",description:"output path of typescript api file",default:"./"},name:{type:"string",alias:"n",description:"name of output typescript api file",default:t.fileName},templates:{type:"string",alias:"t",description:"path to folder containing templates"},"default-as-success":{type:"boolean",alias:"d",description:'use "default" response status code as success response too. some swagger schemas use "default" response status code as success response type by default.',default:t.defaultResponseAsSuccess},responses:{type:"boolean",alias:"r",description:"generate additional information about request responses also add typings for bad responses",default:t.generateResponses},"union-enums":{type:"boolean",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:t.generateUnionEnums},"add-readonly":{type:"boolean",description:"generate readonly properties",default:t.addReadonly},"route-types":{type:"boolean",description:"generate type definitions for API routes",default:t.generateRouteTypes},"no-client":{type:"boolean",description:"do not generate an API class",default:false},"enum-names-as-values":{type:"boolean",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:t.enumNamesAsValues},"extract-request-params":{type:"boolean",description:"extract request params to data contract (Also combine path params and query params into one object)",default:t.extractRequestParams},"extract-request-body":{type:"boolean",description:"extract request body type to data contract",default:t.extractRequestBody},"extract-response-body":{type:"boolean",description:"extract response body type to data contract",default:t.extractResponseBody},"extract-response-error":{type:"boolean",description:"extract response error type to data contract",default:t.extractResponseError},"extract-responses":{type:"boolean",description:"extract all responses described in /components/responses",default:t.extractResponses},modular:{type:"boolean",description:"generate separated files for http client, data contracts, and routes",default:t.modular},js:{type:"boolean",description:"generate js api module with declaration file",default:t.toJS},"module-name-index":{type:"string",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:t.moduleNameIndex.toString()},"module-name-first-tag":{type:"boolean",description:"splits routes based on the first tag",default:t.moduleNameFirstTag},axios:{type:"boolean",description:"generate axios http client",default:false},"unwrap-response-data":{type:"boolean",description:"unwrap the data item from the response",default:t.unwrapResponseData},"disable-throw-on-error":{type:"boolean",description:"Do not throw an error when response.ok is not true",default:t.disableThrowOnError},"single-http-client":{type:"boolean",description:"Ability to send HttpClient instance to Api constructor",default:t.singleHttpClient},silent:{type:"boolean",description:"Output only errors to console",default:t.silent},"default-response":{type:"string",description:"default type for empty response schema",default:t.defaultResponseType},"type-prefix":{type:"string",description:"data contract name prefix",default:t.typePrefix},"type-suffix":{type:"string",description:"data contract name suffix",default:t.typeSuffix},"clean-output":{type:"boolean",description:"clean output folder before generate api. WARNING: May cause data loss",default:t.cleanOutput},"api-class-name":{type:"string",description:"name of the api class",default:t.apiClassName},patch:{type:"boolean",description:"fix up small errors in the swagger source definition",default:t.patch},debug:{type:"boolean",description:"additional information about processes inside this tool",default:t.debug},"another-array-type":{type:"boolean",description:"generate array types as Array<Type> (by default Type[])",default:t.anotherArrayType},"sort-types":{type:"boolean",description:"sort fields and types",default:t.sortTypes},"extract-enums":{type:"boolean",description:"extract all enums from inline interface/type content to typescript enum construction",default:t.extractEnums},"sort-routes":{type:"boolean",description:"sort routes in alphabetical order",default:t.sortRoutes},"custom-config":{type:"string",description:"custom config: primitiveTypeConstructs, hooks, ... "}},run:async({args:e})=>{let a;if(e["custom-config"])try{let s=f__namespace.pathToFileURL(i__namespace.resolve(process.cwd(),e["custom-config"])).toString();a=await import(s),a=a.default||a,a&&consola.consola.info(`Found custom config at: ${s}`);}catch(s){consola.consola.error("Error loading custom config:",s);}await chunkNP4SPLZD_cjs.g({addReadonly:e["add-readonly"],anotherArrayType:e["another-array-type"],apiClassName:e["api-class-name"],cleanOutput:e["clean-output"],debug:e.debug,defaultResponseAsSuccess:e["default-as-success"],defaultResponseType:e["default-response"],disableThrowOnError:e["disable-throw-on-error"],enumNamesAsValues:e["enum-names-as-values"],extractEnums:e["extract-enums"],extractRequestBody:e["extract-request-body"],extractRequestParams:e["extract-request-params"],extractResponseBody:e["extract-response-body"],extractResponseError:e["extract-response-error"],extractResponses:e["extract-responses"],fileName:e.name,generateClient:!e["no-client"],generateResponses:e.responses,generateRouteTypes:e["route-types"],generateUnionEnums:e["union-enums"],httpClientType:e["http-client"]||e.axios?chunkNP4SPLZD_cjs.b.AXIOS:chunkNP4SPLZD_cjs.b.FETCH,input:i__namespace.resolve(process.cwd(),e.path),modular:e.modular,moduleNameFirstTag:e["module-name-first-tag"],moduleNameIndex:+e["module-name-index"]||0,output:i__namespace.resolve(process.cwd(),e.output||"."),patch:e.patch,silent:e.silent,singleHttpClient:e["single-http-client"],sortRoutes:e["sort-routes"],sortTypes:e["sort-types"],templates:e.templates,toJS:e.js,typePrefix:e["type-prefix"],typeSuffix:e["type-suffix"],unwrapResponseData:e["unwrap-response-data"],url:e.path,...a});}}),x=citty.defineCommand({meta:{name:chunkNP4SPLZD_cjs.a.name,description:chunkNP4SPLZD_cjs.a.description,version:chunkNP4SPLZD_cjs.a.version},subCommands:{generate:h,"generate-templates":b}});citty.runMain(x);//# sourceMappingURL=cli.cjs.map
2
+ 'use strict';var chunkNO753Z7P_cjs=require('./chunk-NO753Z7P.cjs'),s=require('path'),c12=require('c12'),citty=require('citty');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 s__namespace=/*#__PURE__*/_interopNamespace(s);var o=new chunkNO753Z7P_cjs.e({}),f=citty.defineCommand({meta:{name:"generate-templates",description:'Generate ".ejs" templates needed for generate api'},args:{"clean-output":{type:"boolean",description:"clean output folder before generate template. WARNING: May cause data loss",default:o.cleanOutput},debug:{type:"boolean",description:"additional information about processes inside this tool",default:o.debug},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(chunkNO753Z7P_cjs.b)})`,default:o.httpClientType},modular:{type:"boolean",description:"generate templates needed to separate files for http client, data contracts, and routes",default:o.modular},output:{type:"string",alias:"o",description:"output path of generated templates",default:o.output,required:true},rewrite:{type:"boolean",alias:"r",description:"rewrite content in existing templates",default:o.rewrite},silent:{type:"boolean",description:"Output only errors to console",default:o.silent}},run:async({args:e})=>{await chunkNO753Z7P_cjs.f({cleanOutput:e["clean-output"],httpClientType:e["http-client"],modular:e.modular,output:e.output,rewrite:e.rewrite,silent:e.silent,debug:e.debug});}}),t=new chunkNO753Z7P_cjs.d({}),y=citty.defineCommand({meta:{name:"generate",description:chunkNO753Z7P_cjs.a.description},args:{"add-readonly":{type:"boolean",description:"generate readonly properties",default:t.addReadonly},"another-array-type":{type:"boolean",description:"generate array types as Array<Type> (by default Type[])",default:t.anotherArrayType},"api-class-name":{type:"string",description:"name of the api class",default:t.apiClassName},axios:{type:"boolean",description:"generate axios http client",default:false},"clean-output":{type:"boolean",description:"clean output folder before generate api. WARNING: May cause data loss",default:t.cleanOutput},client:{type:"boolean",description:"do not generate an API class",default:t.generateClient},"custom-config":{type:"string",description:"custom config: primitiveTypeConstructs, hooks, ... "},debug:{type:"boolean",description:"additional information about processes inside this tool",default:t.debug},"default-as-success":{type:"boolean",alias:"d",description:'use "default" response status code as success response too. some swagger schemas use "default" response status code as success response type by default.',default:t.defaultResponseAsSuccess},"default-response":{type:"string",description:"default type for empty response schema",default:t.defaultResponseType},"disable-throw-on-error":{type:"boolean",description:"Do not throw an error when response.ok is not true",default:t.disableThrowOnError},"enum-names-as-values":{type:"boolean",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:t.enumNamesAsValues},"extract-enums":{type:"boolean",description:"extract all enums from inline interface/type content to typescript enum construction",default:t.extractEnums},"extract-request-body":{type:"boolean",description:"extract request body type to data contract",default:t.extractRequestBody},"extract-request-params":{type:"boolean",description:"extract request params to data contract (Also combine path params and query params into one object)",default:t.extractRequestParams},"extract-response-body":{type:"boolean",description:"extract response body type to data contract",default:t.extractResponseBody},"extract-response-error":{type:"boolean",description:"extract response error type to data contract",default:t.extractResponseError},"extract-responses":{type:"boolean",description:"extract all responses described in /components/responses",default:t.extractResponses},"generate-union-enums":{type:"boolean",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:t.generateUnionEnums},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(chunkNO753Z7P_cjs.b)})`},js:{type:"boolean",description:"generate js api module with declaration file",default:t.toJS},modular:{type:"boolean",description:"generate separated files for http client, data contracts, and routes",default:t.modular},"module-name-first-tag":{type:"boolean",description:"splits routes based on the first tag",default:t.moduleNameFirstTag},"module-name-index":{type:"string",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:t.moduleNameIndex.toString()},name:{type:"string",alias:"n",description:"name of output typescript api file",default:t.fileName},output:{type:"string",alias:"o",description:"output path of typescript api file",default:"./"},patch:{type:"boolean",description:"fix up small errors in the swagger source definition",default:t.patch},path:{type:"string",alias:"p",description:"path/url to swagger scheme",required:true},responses:{type:"boolean",alias:"r",description:"generate additional information about request responses also add typings for bad responses",default:t.generateResponses},"route-types":{type:"boolean",description:"generate type definitions for API routes",default:t.generateRouteTypes},silent:{type:"boolean",description:"Output only errors to console",default:t.silent},"single-http-client":{type:"boolean",description:"Ability to send HttpClient instance to Api constructor",default:t.singleHttpClient},"sort-routes":{type:"boolean",description:"sort routes in alphabetical order",default:t.sortRoutes},"sort-types":{type:"boolean",description:"sort fields and types",default:t.sortTypes},templates:{type:"string",alias:"t",description:"path to folder containing templates"},"type-prefix":{type:"string",description:"data contract name prefix",default:t.typePrefix},"type-suffix":{type:"string",description:"data contract name suffix",default:t.typeSuffix},"unwrap-response-data":{type:"boolean",description:"unwrap the data item from the response",default:t.unwrapResponseData}},run:async({args:e})=>{let d=await c12.loadConfig({configFile:e["custom-config"]});await chunkNO753Z7P_cjs.g({addReadonly:e["add-readonly"],anotherArrayType:e["another-array-type"],apiClassName:e["api-class-name"],cleanOutput:e["clean-output"],debug:e.debug,defaultResponseAsSuccess:e["default-as-success"],defaultResponseType:e["default-response"],disableThrowOnError:e["disable-throw-on-error"],enumNamesAsValues:e["enum-names-as-values"],extractEnums:e["extract-enums"],extractRequestBody:e["extract-request-body"],extractRequestParams:e["extract-request-params"],extractResponseBody:e["extract-response-body"],extractResponseError:e["extract-response-error"],extractResponses:e["extract-responses"],fileName:e.name,generateClient:e.client,generateResponses:e.responses,generateRouteTypes:e["route-types"],generateUnionEnums:e["generate-union-enums"],httpClientType:e["http-client"]||e.axios?chunkNO753Z7P_cjs.b.AXIOS:chunkNO753Z7P_cjs.b.FETCH,input:s__namespace.resolve(process.cwd(),e.path),modular:e.modular,moduleNameFirstTag:e["module-name-first-tag"],moduleNameIndex:+e["module-name-index"]||0,output:s__namespace.resolve(process.cwd(),e.output||"."),patch:e.patch,silent:e.silent,singleHttpClient:e["single-http-client"],sortRoutes:e["sort-routes"],sortTypes:e["sort-types"],templates:e.templates,toJS:e.js,typePrefix:e["type-prefix"],typeSuffix:e["type-suffix"],unwrapResponseData:e["unwrap-response-data"],url:e.path,...d.config});}}),b=citty.defineCommand({meta:{name:chunkNO753Z7P_cjs.a.name,description:chunkNO753Z7P_cjs.a.description,version:chunkNO753Z7P_cjs.a.version},subCommands:{generate:y,"generate-templates":f}});citty.runMain(b);//# sourceMappingURL=cli.cjs.map
3
3
  //# sourceMappingURL=cli.cjs.map
package/dist/cli.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"names":["templateGenBaseConfig","TemplatesGenConfig","generateTemplatesCommand","defineCommand","HTTP_CLIENT","args","generateTemplates","codeGenBaseConfig","CodeGenConfig","generateCommand","package_default","customConfig","customConfigPath","f","i","consola","error","generateApi","main","runMain"],"mappings":";ijBAaA,IAAMA,EAAwB,IAAIC,mBAAAA,CAAmB,EAAE,CAAA,CAEjDC,EAA2BC,mBAAc,CAAA,CAC7C,KAAM,CACJ,IAAA,CAAM,qBACN,WAAa,CAAA,mDACf,EACA,IAAM,CAAA,CACJ,eAAgB,CACd,IAAA,CAAM,UACN,WACE,CAAA,4EAAA,CACF,QAASH,CAAsB,CAAA,WACjC,CACA,CAAA,aAAA,CAAe,CACb,IAAA,CAAM,SACN,WAAa,CAAA,CAAA,mCAAA,EAAsC,OAAO,MACxDI,CAAAA,mBACF,CAAC,CACD,CAAA,CAAA,CAAA,OAAA,CAASJ,EAAsB,cACjC,CAAA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CAAAA,CAAK,IAAc,CACtD,CAAA,OAAA,CAASA,EAAK,OACd,CAAA,kBAAA,CAAoBA,EAAK,uBAAuB,CAAA,CAChD,gBAAiB,CAACA,CAAAA,CAAK,mBAAmB,CAAK,EAAA,CAAA,CAC/C,OAAaS,YAAQ,CAAA,OAAA,CAAA,OAAA,CAAQ,GAAI,EAAA,CAAIT,CAAK,CAAA,MAAA,EAAqB,GAAG,CAClE,CAAA,KAAA,CAAOA,EAAK,KACZ,CAAA,MAAA,CAAQA,EAAK,MACb,CAAA,gBAAA,CAAkBA,EAAK,oBAAoB,CAAA,CAC3C,WAAYA,CAAK,CAAA,aAAa,EAC9B,SAAWA,CAAAA,CAAAA,CAAK,YAAY,CAC5B,CAAA,SAAA,CAAWA,CAAK,CAAA,SAAA,CAChB,IAAMA,CAAAA,CAAAA,CAAK,GACX,UAAYA,CAAAA,CAAAA,CAAK,aAAa,CAC9B,CAAA,UAAA,CAAYA,EAAK,aAAa,CAAA,CAC9B,mBAAoBA,CAAK,CAAA,sBAAsB,EAC/C,GAAKA,CAAAA,CAAAA,CAAK,KACV,GAAGM,CACL,CAAC,EACH,CACF,CAAC,CAAA,CAEKO,CAAOf,CAAAA,mBAAAA,CAAc,CACzB,IAAM,CAAA,CACJ,KAAMO,mBAAY,CAAA,IAAA,CAClB,YAAaA,mBAAY,CAAA,WAAA,CACzB,QAASA,mBAAY,CAAA,OACvB,EACA,WAAa,CAAA,CACX,SAAUD,CACV,CAAA,oBAAA,CAAsBP,CACxB,CACF,CAAC,CAEDiB,CAAAA,aAAAA,CAAQD,CAAI,CAAA","file":"cli.cjs","sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport * as url from \"node:url\";\nimport { defineCommand, runMain } from \"citty\";\nimport { consola } from \"consola\";\nimport packageJson from \"./package.json\" with { type: \"json\" };\nimport { TemplatesGenConfig } from \"./src/commands/generate-templates/configuration.js\";\nimport { CodeGenConfig } from \"./src/configuration.js\";\nimport { HTTP_CLIENT } from \"./src/constants.js\";\nimport { generateApi, generateTemplates } from \"./src/index.js\";\nimport type { HttpClientType } from \"./types/index.js\";\n\nconst templateGenBaseConfig = new TemplatesGenConfig({});\n\nconst generateTemplatesCommand = defineCommand({\n meta: {\n name: \"generate-templates\",\n description: 'Generate \".ejs\" templates needed for generate api',\n },\n args: {\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate template. WARNING: May cause data loss\",\n default: templateGenBaseConfig.cleanOutput,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n default: templateGenBaseConfig.httpClientType,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate templates needed to separate files for http client, data contracts, and routes\",\n default: templateGenBaseConfig.modular,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of generated templates\",\n default: templateGenBaseConfig.output,\n required: true,\n },\n rewrite: {\n type: \"boolean\",\n alias: \"r\",\n description: \"rewrite content in existing templates\",\n default: templateGenBaseConfig.rewrite,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: templateGenBaseConfig.silent,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: templateGenBaseConfig.debug,\n },\n },\n run: async ({ args }) => {\n await generateTemplates({\n cleanOutput: args[\"clean-output\"],\n httpClientType: args[\"http-client\"] as HttpClientType,\n modular: args.modular,\n output: args.output,\n rewrite: args.rewrite,\n silent: args.silent,\n debug: args.debug,\n });\n },\n});\n\nconst codeGenBaseConfig = new CodeGenConfig({});\n\nconst generateCommand = defineCommand({\n meta: {\n name: \"generate\",\n description: packageJson.description,\n },\n args: {\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"path/url to swagger scheme\",\n required: true,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of typescript api file\",\n default: \"./\",\n },\n name: {\n type: \"string\",\n alias: \"n\",\n description: \"name of output typescript api file\",\n default: codeGenBaseConfig.fileName,\n },\n templates: {\n type: \"string\",\n alias: \"t\",\n description: \"path to folder containing templates\",\n },\n \"default-as-success\": {\n type: \"boolean\",\n alias: \"d\",\n description:\n 'use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.',\n default: codeGenBaseConfig.defaultResponseAsSuccess,\n },\n responses: {\n type: \"boolean\",\n alias: \"r\",\n description:\n \"generate additional information about request responses also add typings for bad responses\",\n default: codeGenBaseConfig.generateResponses,\n },\n \"union-enums\": {\n type: \"boolean\",\n description: 'generate all \"enum\" types as union types (T1 | T2 | TN)',\n default: codeGenBaseConfig.generateUnionEnums,\n },\n \"add-readonly\": {\n type: \"boolean\",\n description: \"generate readonly properties\",\n default: codeGenBaseConfig.addReadonly,\n },\n \"route-types\": {\n type: \"boolean\",\n description: \"generate type definitions for API routes\",\n default: codeGenBaseConfig.generateRouteTypes,\n },\n \"no-client\": {\n type: \"boolean\",\n description: \"do not generate an API class\",\n default: false,\n },\n \"enum-names-as-values\": {\n type: \"boolean\",\n description:\n \"use values in 'x-enumNames' as enum values (not only as keys)\",\n default: codeGenBaseConfig.enumNamesAsValues,\n },\n \"extract-request-params\": {\n type: \"boolean\",\n description:\n \"extract request params to data contract (Also combine path params and query params into one object)\",\n default: codeGenBaseConfig.extractRequestParams,\n },\n \"extract-request-body\": {\n type: \"boolean\",\n description: \"extract request body type to data contract\",\n default: codeGenBaseConfig.extractRequestBody,\n },\n \"extract-response-body\": {\n type: \"boolean\",\n description: \"extract response body type to data contract\",\n default: codeGenBaseConfig.extractResponseBody,\n },\n \"extract-response-error\": {\n type: \"boolean\",\n description: \"extract response error type to data contract\",\n default: codeGenBaseConfig.extractResponseError,\n },\n \"extract-responses\": {\n type: \"boolean\",\n description: \"extract all responses described in /components/responses\",\n default: codeGenBaseConfig.extractResponses,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate separated files for http client, data contracts, and routes\",\n default: codeGenBaseConfig.modular,\n },\n js: {\n type: \"boolean\",\n description: \"generate js api module with declaration file\",\n default: codeGenBaseConfig.toJS,\n },\n \"module-name-index\": {\n type: \"string\",\n description:\n \"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)\",\n default: codeGenBaseConfig.moduleNameIndex.toString(),\n },\n \"module-name-first-tag\": {\n type: \"boolean\",\n description: \"splits routes based on the first tag\",\n default: codeGenBaseConfig.moduleNameFirstTag,\n },\n axios: {\n type: \"boolean\",\n description: \"generate axios http client\",\n default: false,\n },\n \"unwrap-response-data\": {\n type: \"boolean\",\n description: \"unwrap the data item from the response\",\n default: codeGenBaseConfig.unwrapResponseData,\n },\n \"disable-throw-on-error\": {\n type: \"boolean\",\n description: \"Do not throw an error when response.ok is not true\",\n default: codeGenBaseConfig.disableThrowOnError,\n },\n \"single-http-client\": {\n type: \"boolean\",\n description: \"Ability to send HttpClient instance to Api constructor\",\n default: codeGenBaseConfig.singleHttpClient,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: codeGenBaseConfig.silent,\n },\n \"default-response\": {\n type: \"string\",\n description: \"default type for empty response schema\",\n default: codeGenBaseConfig.defaultResponseType,\n },\n \"type-prefix\": {\n type: \"string\",\n description: \"data contract name prefix\",\n default: codeGenBaseConfig.typePrefix,\n },\n \"type-suffix\": {\n type: \"string\",\n description: \"data contract name suffix\",\n default: codeGenBaseConfig.typeSuffix,\n },\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate api. WARNING: May cause data loss\",\n default: codeGenBaseConfig.cleanOutput,\n },\n \"api-class-name\": {\n type: \"string\",\n description: \"name of the api class\",\n default: codeGenBaseConfig.apiClassName,\n },\n patch: {\n type: \"boolean\",\n description: \"fix up small errors in the swagger source definition\",\n default: codeGenBaseConfig.patch,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: codeGenBaseConfig.debug,\n },\n \"another-array-type\": {\n type: \"boolean\",\n description: \"generate array types as Array<Type> (by default Type[])\",\n default: codeGenBaseConfig.anotherArrayType,\n },\n \"sort-types\": {\n type: \"boolean\",\n description: \"sort fields and types\",\n default: codeGenBaseConfig.sortTypes,\n },\n \"extract-enums\": {\n type: \"boolean\",\n description:\n \"extract all enums from inline interface/type content to typescript enum construction\",\n default: codeGenBaseConfig.extractEnums,\n },\n \"sort-routes\": {\n type: \"boolean\",\n description: \"sort routes in alphabetical order\",\n default: codeGenBaseConfig.sortRoutes,\n },\n \"custom-config\": {\n type: \"string\",\n description: \"custom config: primitiveTypeConstructs, hooks, ... \",\n },\n },\n run: async ({ args }) => {\n let customConfig = undefined;\n\n if (args[\"custom-config\"]) {\n try {\n const customConfigPath = url\n .pathToFileURL(path.resolve(process.cwd(), args[\"custom-config\"]))\n .toString();\n customConfig = await import(customConfigPath);\n customConfig = customConfig.default || customConfig;\n if (customConfig) {\n consola.info(`Found custom config at: ${customConfigPath}`);\n }\n } catch (error) {\n consola.error(\"Error loading custom config:\", error);\n }\n }\n\n await generateApi({\n addReadonly: args[\"add-readonly\"],\n anotherArrayType: args[\"another-array-type\"],\n apiClassName: args[\"api-class-name\"],\n cleanOutput: args[\"clean-output\"],\n debug: args.debug,\n defaultResponseAsSuccess: args[\"default-as-success\"],\n defaultResponseType: args[\"default-response\"],\n disableThrowOnError: args[\"disable-throw-on-error\"],\n enumNamesAsValues: args[\"enum-names-as-values\"],\n extractEnums: args[\"extract-enums\"],\n extractRequestBody: args[\"extract-request-body\"],\n extractRequestParams: args[\"extract-request-params\"],\n extractResponseBody: args[\"extract-response-body\"],\n extractResponseError: args[\"extract-response-error\"],\n extractResponses: args[\"extract-responses\"],\n fileName: args.name,\n generateClient: !args[\"no-client\"],\n generateResponses: args.responses,\n generateRouteTypes: args[\"route-types\"],\n generateUnionEnums: args[\"union-enums\"],\n httpClientType:\n args[\"http-client\"] || args.axios\n ? HTTP_CLIENT.AXIOS\n : HTTP_CLIENT.FETCH,\n input: path.resolve(process.cwd(), args.path as string),\n modular: args.modular,\n moduleNameFirstTag: args[\"module-name-first-tag\"],\n moduleNameIndex: +args[\"module-name-index\"] || 0,\n output: path.resolve(process.cwd(), (args.output as string) || \".\"),\n patch: args.patch,\n silent: args.silent,\n singleHttpClient: args[\"single-http-client\"],\n sortRoutes: args[\"sort-routes\"],\n sortTypes: args[\"sort-types\"],\n templates: args.templates,\n toJS: args.js,\n typePrefix: args[\"type-prefix\"],\n typeSuffix: args[\"type-suffix\"],\n unwrapResponseData: args[\"unwrap-response-data\"],\n url: args.path,\n ...customConfig,\n });\n },\n});\n\nconst main = defineCommand({\n meta: {\n name: packageJson.name,\n description: packageJson.description,\n version: packageJson.version,\n },\n subCommands: {\n generate: generateCommand,\n \"generate-templates\": generateTemplatesCommand,\n },\n});\n\nrunMain(main);\n"]}
1
+ {"version":3,"sources":["../index.ts"],"names":["templateGenBaseConfig","TemplatesGenConfig","generateTemplatesCommand","defineCommand","HTTP_CLIENT","args","generateTemplates","codeGenBaseConfig","CodeGenConfig","generateCommand","package_default","customConfig","loadConfig","generateApi","s","main","runMain"],"mappings":";qeAYA,IAAMA,EAAwB,IAAIC,mBAAAA,CAAmB,EAAE,CAAA,CAEjDC,EAA2BC,mBAAc,CAAA,CAC7C,KAAM,CACJ,IAAA,CAAM,qBACN,WAAa,CAAA,mDACf,EACA,IAAM,CAAA,CACJ,eAAgB,CACd,IAAA,CAAM,UACN,WACE,CAAA,4EAAA,CACF,QAASH,CAAsB,CAAA,WACjC,EACA,KAAO,CAAA,CACL,KAAM,SACN,CAAA,WAAA,CAAa,0DACb,OAASA,CAAAA,CAAAA,CAAsB,KACjC,CACA,CAAA,aAAA,CAAe,CACb,IAAM,CAAA,QAAA,CACN,YAAa,CAAsC,mCAAA,EAAA,MAAA,CAAO,OACxDI,mBACF,CAAC,IACD,OAASJ,CAAAA,CAAAA,CAAsB,cACjC,CACA,CAAA,OAAA,CAAS,CACP,IAAM,CAAA,SAAA,CACN,YACE,yFACF,CAAA,OAAA,CAASA,EAAsB,OACjC,CAAA,CACA,OAAQ,CACN,IAAA,CAAM,SACN,K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,WAAYA,CAAK,CAAA,aAAa,EAC9B,kBAAoBA,CAAAA,CAAAA,CAAK,sBAAsB,CAC/C,CAAA,GAAA,CAAKA,EAAK,IACV,CAAA,GAAGM,EAAa,MAClB,CAAC,EACH,CACF,CAAC,EAEKI,CAAOZ,CAAAA,mBAAAA,CAAc,CACzB,IAAM,CAAA,CACJ,KAAMO,mBAAY,CAAA,IAAA,CAClB,YAAaA,mBAAY,CAAA,WAAA,CACzB,QAASA,mBAAY,CAAA,OACvB,EACA,WAAa,CAAA,CACX,SAAUD,CACV,CAAA,oBAAA,CAAsBP,CACxB,CACF,CAAC,CAEDc,CAAAA,aAAAA,CAAQD,CAAI,CAAA","file":"cli.cjs","sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport { loadConfig } from \"c12\";\nimport { defineCommand, runMain } from \"citty\";\nimport packageJson from \"./package.json\" with { type: \"json\" };\nimport { TemplatesGenConfig } from \"./src/commands/generate-templates/configuration.js\";\nimport { CodeGenConfig } from \"./src/configuration.js\";\nimport { HTTP_CLIENT } from \"./src/constants.js\";\nimport { generateApi, generateTemplates } from \"./src/index.js\";\nimport type { GenerateApiParams, HttpClientType } from \"./types/index.js\";\n\nconst templateGenBaseConfig = new TemplatesGenConfig({});\n\nconst generateTemplatesCommand = defineCommand({\n meta: {\n name: \"generate-templates\",\n description: 'Generate \".ejs\" templates needed for generate api',\n },\n args: {\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate template. WARNING: May cause data loss\",\n default: templateGenBaseConfig.cleanOutput,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: templateGenBaseConfig.debug,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n default: templateGenBaseConfig.httpClientType,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate templates needed to separate files for http client, data contracts, and routes\",\n default: templateGenBaseConfig.modular,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of generated templates\",\n default: templateGenBaseConfig.output,\n required: true,\n },\n rewrite: {\n type: \"boolean\",\n alias: \"r\",\n description: \"rewrite content in existing templates\",\n default: templateGenBaseConfig.rewrite,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: templateGenBaseConfig.silent,\n },\n },\n run: async ({ args }) => {\n await generateTemplates({\n cleanOutput: args[\"clean-output\"],\n httpClientType: args[\"http-client\"] as HttpClientType,\n modular: args.modular,\n output: args.output,\n rewrite: args.rewrite,\n silent: args.silent,\n debug: args.debug,\n });\n },\n});\n\nconst codeGenBaseConfig = new CodeGenConfig({});\n\nconst generateCommand = defineCommand({\n meta: {\n name: \"generate\",\n description: packageJson.description,\n },\n args: {\n \"add-readonly\": {\n type: \"boolean\",\n description: \"generate readonly properties\",\n default: codeGenBaseConfig.addReadonly,\n },\n \"another-array-type\": {\n type: \"boolean\",\n description: \"generate array types as Array<Type> (by default Type[])\",\n default: codeGenBaseConfig.anotherArrayType,\n },\n \"api-class-name\": {\n type: \"string\",\n description: \"name of the api class\",\n default: codeGenBaseConfig.apiClassName,\n },\n axios: {\n type: \"boolean\",\n description: \"generate axios http client\",\n default: false,\n },\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate api. WARNING: May cause data loss\",\n default: codeGenBaseConfig.cleanOutput,\n },\n client: {\n type: \"boolean\",\n description: \"do not generate an API class\",\n default: codeGenBaseConfig.generateClient,\n },\n \"custom-config\": {\n type: \"string\",\n description: \"custom config: primitiveTypeConstructs, hooks, ... \",\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: codeGenBaseConfig.debug,\n },\n \"default-as-success\": {\n type: \"boolean\",\n alias: \"d\",\n description:\n 'use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.',\n default: codeGenBaseConfig.defaultResponseAsSuccess,\n },\n \"default-response\": {\n type: \"string\",\n description: \"default type for empty response schema\",\n default: codeGenBaseConfig.defaultResponseType,\n },\n \"disable-throw-on-error\": {\n type: \"boolean\",\n description: \"Do not throw an error when response.ok is not true\",\n default: codeGenBaseConfig.disableThrowOnError,\n },\n \"enum-names-as-values\": {\n type: \"boolean\",\n description:\n \"use values in 'x-enumNames' as enum values (not only as keys)\",\n default: codeGenBaseConfig.enumNamesAsValues,\n },\n \"extract-enums\": {\n type: \"boolean\",\n description:\n \"extract all enums from inline interface/type content to typescript enum construction\",\n default: codeGenBaseConfig.extractEnums,\n },\n \"extract-request-body\": {\n type: \"boolean\",\n description: \"extract request body type to data contract\",\n default: codeGenBaseConfig.extractRequestBody,\n },\n \"extract-request-params\": {\n type: \"boolean\",\n description:\n \"extract request params to data contract (Also combine path params and query params into one object)\",\n default: codeGenBaseConfig.extractRequestParams,\n },\n \"extract-response-body\": {\n type: \"boolean\",\n description: \"extract response body type to data contract\",\n default: codeGenBaseConfig.extractResponseBody,\n },\n \"extract-response-error\": {\n type: \"boolean\",\n description: \"extract response error type to data contract\",\n default: codeGenBaseConfig.extractResponseError,\n },\n \"extract-responses\": {\n type: \"boolean\",\n description: \"extract all responses described in /components/responses\",\n default: codeGenBaseConfig.extractResponses,\n },\n \"generate-union-enums\": {\n type: \"boolean\",\n description: 'generate all \"enum\" types as union types (T1 | T2 | TN)',\n default: codeGenBaseConfig.generateUnionEnums,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n },\n js: {\n type: \"boolean\",\n description: \"generate js api module with declaration file\",\n default: codeGenBaseConfig.toJS,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate separated files for http client, data contracts, and routes\",\n default: codeGenBaseConfig.modular,\n },\n \"module-name-first-tag\": {\n type: \"boolean\",\n description: \"splits routes based on the first tag\",\n default: codeGenBaseConfig.moduleNameFirstTag,\n },\n \"module-name-index\": {\n type: \"string\",\n description:\n \"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)\",\n default: codeGenBaseConfig.moduleNameIndex.toString(),\n },\n name: {\n type: \"string\",\n alias: \"n\",\n description: \"name of output typescript api file\",\n default: codeGenBaseConfig.fileName,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of typescript api file\",\n default: \"./\",\n },\n patch: {\n type: \"boolean\",\n description: \"fix up small errors in the swagger source definition\",\n default: codeGenBaseConfig.patch,\n },\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"path/url to swagger scheme\",\n required: true,\n },\n responses: {\n type: \"boolean\",\n alias: \"r\",\n description:\n \"generate additional information about request responses also add typings for bad responses\",\n default: codeGenBaseConfig.generateResponses,\n },\n \"route-types\": {\n type: \"boolean\",\n description: \"generate type definitions for API routes\",\n default: codeGenBaseConfig.generateRouteTypes,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: codeGenBaseConfig.silent,\n },\n \"single-http-client\": {\n type: \"boolean\",\n description: \"Ability to send HttpClient instance to Api constructor\",\n default: codeGenBaseConfig.singleHttpClient,\n },\n \"sort-routes\": {\n type: \"boolean\",\n description: \"sort routes in alphabetical order\",\n default: codeGenBaseConfig.sortRoutes,\n },\n \"sort-types\": {\n type: \"boolean\",\n description: \"sort fields and types\",\n default: codeGenBaseConfig.sortTypes,\n },\n templates: {\n type: \"string\",\n alias: \"t\",\n description: \"path to folder containing templates\",\n },\n \"type-prefix\": {\n type: \"string\",\n description: \"data contract name prefix\",\n default: codeGenBaseConfig.typePrefix,\n },\n \"type-suffix\": {\n type: \"string\",\n description: \"data contract name suffix\",\n default: codeGenBaseConfig.typeSuffix,\n },\n \"unwrap-response-data\": {\n type: \"boolean\",\n description: \"unwrap the data item from the response\",\n default: codeGenBaseConfig.unwrapResponseData,\n },\n },\n run: async ({ args }) => {\n const customConfig = await loadConfig<GenerateApiParams>({\n configFile: args[\"custom-config\"],\n });\n\n await generateApi({\n addReadonly: args[\"add-readonly\"],\n anotherArrayType: args[\"another-array-type\"],\n apiClassName: args[\"api-class-name\"],\n cleanOutput: args[\"clean-output\"],\n debug: args.debug,\n defaultResponseAsSuccess: args[\"default-as-success\"],\n defaultResponseType: args[\"default-response\"],\n disableThrowOnError: args[\"disable-throw-on-error\"],\n enumNamesAsValues: args[\"enum-names-as-values\"],\n extractEnums: args[\"extract-enums\"],\n extractRequestBody: args[\"extract-request-body\"],\n extractRequestParams: args[\"extract-request-params\"],\n extractResponseBody: args[\"extract-response-body\"],\n extractResponseError: args[\"extract-response-error\"],\n extractResponses: args[\"extract-responses\"],\n fileName: args.name,\n generateClient: args.client,\n generateResponses: args.responses,\n generateRouteTypes: args[\"route-types\"],\n generateUnionEnums: args[\"generate-union-enums\"],\n httpClientType:\n args[\"http-client\"] || args.axios\n ? HTTP_CLIENT.AXIOS\n : HTTP_CLIENT.FETCH,\n input: path.resolve(process.cwd(), args.path as string),\n modular: args.modular,\n moduleNameFirstTag: args[\"module-name-first-tag\"],\n moduleNameIndex: +args[\"module-name-index\"] || 0,\n output: path.resolve(process.cwd(), (args.output as string) || \".\"),\n patch: args.patch,\n silent: args.silent,\n singleHttpClient: args[\"single-http-client\"],\n sortRoutes: args[\"sort-routes\"],\n sortTypes: args[\"sort-types\"],\n templates: args.templates,\n toJS: args.js,\n typePrefix: args[\"type-prefix\"],\n typeSuffix: args[\"type-suffix\"],\n unwrapResponseData: args[\"unwrap-response-data\"],\n url: args.path,\n ...customConfig.config,\n });\n },\n});\n\nconst main = defineCommand({\n meta: {\n name: packageJson.name,\n description: packageJson.description,\n version: packageJson.version,\n },\n subCommands: {\n generate: generateCommand,\n \"generate-templates\": generateTemplatesCommand,\n },\n});\n\nrunMain(main);\n"]}
package/dist/cli.js CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
- import {e,f as f$1,b as b$1,d,a,g}from'./chunk-WJYL7LUK.js';import*as i from'node:path';import*as f from'node:url';import {defineCommand,runMain}from'citty';import {consola}from'consola';var o=new e({}),b=defineCommand({meta:{name:"generate-templates",description:'Generate ".ejs" templates needed for generate api'},args:{"clean-output":{type:"boolean",description:"clean output folder before generate template. WARNING: May cause data loss",default:o.cleanOutput},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(b$1)})`,default:o.httpClientType},modular:{type:"boolean",description:"generate templates needed to separate files for http client, data contracts, and routes",default:o.modular},output:{type:"string",alias:"o",description:"output path of generated templates",default:o.output,required:true},rewrite:{type:"boolean",alias:"r",description:"rewrite content in existing templates",default:o.rewrite},silent:{type:"boolean",description:"Output only errors to console",default:o.silent},debug:{type:"boolean",description:"additional information about processes inside this tool",default:o.debug}},run:async({args:e})=>{await f$1({cleanOutput:e["clean-output"],httpClientType:e["http-client"],modular:e.modular,output:e.output,rewrite:e.rewrite,silent:e.silent,debug:e.debug});}}),t=new d({}),h=defineCommand({meta:{name:"generate",description:a.description},args:{path:{type:"string",alias:"p",description:"path/url to swagger scheme",required:true},output:{type:"string",alias:"o",description:"output path of typescript api file",default:"./"},name:{type:"string",alias:"n",description:"name of output typescript api file",default:t.fileName},templates:{type:"string",alias:"t",description:"path to folder containing templates"},"default-as-success":{type:"boolean",alias:"d",description:'use "default" response status code as success response too. some swagger schemas use "default" response status code as success response type by default.',default:t.defaultResponseAsSuccess},responses:{type:"boolean",alias:"r",description:"generate additional information about request responses also add typings for bad responses",default:t.generateResponses},"union-enums":{type:"boolean",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:t.generateUnionEnums},"add-readonly":{type:"boolean",description:"generate readonly properties",default:t.addReadonly},"route-types":{type:"boolean",description:"generate type definitions for API routes",default:t.generateRouteTypes},"no-client":{type:"boolean",description:"do not generate an API class",default:false},"enum-names-as-values":{type:"boolean",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:t.enumNamesAsValues},"extract-request-params":{type:"boolean",description:"extract request params to data contract (Also combine path params and query params into one object)",default:t.extractRequestParams},"extract-request-body":{type:"boolean",description:"extract request body type to data contract",default:t.extractRequestBody},"extract-response-body":{type:"boolean",description:"extract response body type to data contract",default:t.extractResponseBody},"extract-response-error":{type:"boolean",description:"extract response error type to data contract",default:t.extractResponseError},"extract-responses":{type:"boolean",description:"extract all responses described in /components/responses",default:t.extractResponses},modular:{type:"boolean",description:"generate separated files for http client, data contracts, and routes",default:t.modular},js:{type:"boolean",description:"generate js api module with declaration file",default:t.toJS},"module-name-index":{type:"string",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:t.moduleNameIndex.toString()},"module-name-first-tag":{type:"boolean",description:"splits routes based on the first tag",default:t.moduleNameFirstTag},axios:{type:"boolean",description:"generate axios http client",default:false},"unwrap-response-data":{type:"boolean",description:"unwrap the data item from the response",default:t.unwrapResponseData},"disable-throw-on-error":{type:"boolean",description:"Do not throw an error when response.ok is not true",default:t.disableThrowOnError},"single-http-client":{type:"boolean",description:"Ability to send HttpClient instance to Api constructor",default:t.singleHttpClient},silent:{type:"boolean",description:"Output only errors to console",default:t.silent},"default-response":{type:"string",description:"default type for empty response schema",default:t.defaultResponseType},"type-prefix":{type:"string",description:"data contract name prefix",default:t.typePrefix},"type-suffix":{type:"string",description:"data contract name suffix",default:t.typeSuffix},"clean-output":{type:"boolean",description:"clean output folder before generate api. WARNING: May cause data loss",default:t.cleanOutput},"api-class-name":{type:"string",description:"name of the api class",default:t.apiClassName},patch:{type:"boolean",description:"fix up small errors in the swagger source definition",default:t.patch},debug:{type:"boolean",description:"additional information about processes inside this tool",default:t.debug},"another-array-type":{type:"boolean",description:"generate array types as Array<Type> (by default Type[])",default:t.anotherArrayType},"sort-types":{type:"boolean",description:"sort fields and types",default:t.sortTypes},"extract-enums":{type:"boolean",description:"extract all enums from inline interface/type content to typescript enum construction",default:t.extractEnums},"sort-routes":{type:"boolean",description:"sort routes in alphabetical order",default:t.sortRoutes},"custom-config":{type:"string",description:"custom config: primitiveTypeConstructs, hooks, ... "}},run:async({args:e})=>{let a;if(e["custom-config"])try{let s=f.pathToFileURL(i.resolve(process.cwd(),e["custom-config"])).toString();a=await import(s),a=a.default||a,a&&consola.info(`Found custom config at: ${s}`);}catch(s){consola.error("Error loading custom config:",s);}await g({addReadonly:e["add-readonly"],anotherArrayType:e["another-array-type"],apiClassName:e["api-class-name"],cleanOutput:e["clean-output"],debug:e.debug,defaultResponseAsSuccess:e["default-as-success"],defaultResponseType:e["default-response"],disableThrowOnError:e["disable-throw-on-error"],enumNamesAsValues:e["enum-names-as-values"],extractEnums:e["extract-enums"],extractRequestBody:e["extract-request-body"],extractRequestParams:e["extract-request-params"],extractResponseBody:e["extract-response-body"],extractResponseError:e["extract-response-error"],extractResponses:e["extract-responses"],fileName:e.name,generateClient:!e["no-client"],generateResponses:e.responses,generateRouteTypes:e["route-types"],generateUnionEnums:e["union-enums"],httpClientType:e["http-client"]||e.axios?b$1.AXIOS:b$1.FETCH,input:i.resolve(process.cwd(),e.path),modular:e.modular,moduleNameFirstTag:e["module-name-first-tag"],moduleNameIndex:+e["module-name-index"]||0,output:i.resolve(process.cwd(),e.output||"."),patch:e.patch,silent:e.silent,singleHttpClient:e["single-http-client"],sortRoutes:e["sort-routes"],sortTypes:e["sort-types"],templates:e.templates,toJS:e.js,typePrefix:e["type-prefix"],typeSuffix:e["type-suffix"],unwrapResponseData:e["unwrap-response-data"],url:e.path,...a});}}),x=defineCommand({meta:{name:a.name,description:a.description,version:a.version},subCommands:{generate:h,"generate-templates":b}});runMain(x);//# sourceMappingURL=cli.js.map
2
+ import {e,f as f$1,b as b$1,d,a,g}from'./chunk-TVX6OCDM.js';import*as s from'node:path';import {loadConfig}from'c12';import {defineCommand,runMain}from'citty';var o=new e({}),f=defineCommand({meta:{name:"generate-templates",description:'Generate ".ejs" templates needed for generate api'},args:{"clean-output":{type:"boolean",description:"clean output folder before generate template. WARNING: May cause data loss",default:o.cleanOutput},debug:{type:"boolean",description:"additional information about processes inside this tool",default:o.debug},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(b$1)})`,default:o.httpClientType},modular:{type:"boolean",description:"generate templates needed to separate files for http client, data contracts, and routes",default:o.modular},output:{type:"string",alias:"o",description:"output path of generated templates",default:o.output,required:true},rewrite:{type:"boolean",alias:"r",description:"rewrite content in existing templates",default:o.rewrite},silent:{type:"boolean",description:"Output only errors to console",default:o.silent}},run:async({args:e})=>{await f$1({cleanOutput:e["clean-output"],httpClientType:e["http-client"],modular:e.modular,output:e.output,rewrite:e.rewrite,silent:e.silent,debug:e.debug});}}),t=new d({}),y=defineCommand({meta:{name:"generate",description:a.description},args:{"add-readonly":{type:"boolean",description:"generate readonly properties",default:t.addReadonly},"another-array-type":{type:"boolean",description:"generate array types as Array<Type> (by default Type[])",default:t.anotherArrayType},"api-class-name":{type:"string",description:"name of the api class",default:t.apiClassName},axios:{type:"boolean",description:"generate axios http client",default:false},"clean-output":{type:"boolean",description:"clean output folder before generate api. WARNING: May cause data loss",default:t.cleanOutput},client:{type:"boolean",description:"do not generate an API class",default:t.generateClient},"custom-config":{type:"string",description:"custom config: primitiveTypeConstructs, hooks, ... "},debug:{type:"boolean",description:"additional information about processes inside this tool",default:t.debug},"default-as-success":{type:"boolean",alias:"d",description:'use "default" response status code as success response too. some swagger schemas use "default" response status code as success response type by default.',default:t.defaultResponseAsSuccess},"default-response":{type:"string",description:"default type for empty response schema",default:t.defaultResponseType},"disable-throw-on-error":{type:"boolean",description:"Do not throw an error when response.ok is not true",default:t.disableThrowOnError},"enum-names-as-values":{type:"boolean",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:t.enumNamesAsValues},"extract-enums":{type:"boolean",description:"extract all enums from inline interface/type content to typescript enum construction",default:t.extractEnums},"extract-request-body":{type:"boolean",description:"extract request body type to data contract",default:t.extractRequestBody},"extract-request-params":{type:"boolean",description:"extract request params to data contract (Also combine path params and query params into one object)",default:t.extractRequestParams},"extract-response-body":{type:"boolean",description:"extract response body type to data contract",default:t.extractResponseBody},"extract-response-error":{type:"boolean",description:"extract response error type to data contract",default:t.extractResponseError},"extract-responses":{type:"boolean",description:"extract all responses described in /components/responses",default:t.extractResponses},"generate-union-enums":{type:"boolean",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:t.generateUnionEnums},"http-client":{type:"string",description:`http client type (possible values: ${Object.values(b$1)})`},js:{type:"boolean",description:"generate js api module with declaration file",default:t.toJS},modular:{type:"boolean",description:"generate separated files for http client, data contracts, and routes",default:t.modular},"module-name-first-tag":{type:"boolean",description:"splits routes based on the first tag",default:t.moduleNameFirstTag},"module-name-index":{type:"string",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:t.moduleNameIndex.toString()},name:{type:"string",alias:"n",description:"name of output typescript api file",default:t.fileName},output:{type:"string",alias:"o",description:"output path of typescript api file",default:"./"},patch:{type:"boolean",description:"fix up small errors in the swagger source definition",default:t.patch},path:{type:"string",alias:"p",description:"path/url to swagger scheme",required:true},responses:{type:"boolean",alias:"r",description:"generate additional information about request responses also add typings for bad responses",default:t.generateResponses},"route-types":{type:"boolean",description:"generate type definitions for API routes",default:t.generateRouteTypes},silent:{type:"boolean",description:"Output only errors to console",default:t.silent},"single-http-client":{type:"boolean",description:"Ability to send HttpClient instance to Api constructor",default:t.singleHttpClient},"sort-routes":{type:"boolean",description:"sort routes in alphabetical order",default:t.sortRoutes},"sort-types":{type:"boolean",description:"sort fields and types",default:t.sortTypes},templates:{type:"string",alias:"t",description:"path to folder containing templates"},"type-prefix":{type:"string",description:"data contract name prefix",default:t.typePrefix},"type-suffix":{type:"string",description:"data contract name suffix",default:t.typeSuffix},"unwrap-response-data":{type:"boolean",description:"unwrap the data item from the response",default:t.unwrapResponseData}},run:async({args:e})=>{let d=await loadConfig({configFile:e["custom-config"]});await g({addReadonly:e["add-readonly"],anotherArrayType:e["another-array-type"],apiClassName:e["api-class-name"],cleanOutput:e["clean-output"],debug:e.debug,defaultResponseAsSuccess:e["default-as-success"],defaultResponseType:e["default-response"],disableThrowOnError:e["disable-throw-on-error"],enumNamesAsValues:e["enum-names-as-values"],extractEnums:e["extract-enums"],extractRequestBody:e["extract-request-body"],extractRequestParams:e["extract-request-params"],extractResponseBody:e["extract-response-body"],extractResponseError:e["extract-response-error"],extractResponses:e["extract-responses"],fileName:e.name,generateClient:e.client,generateResponses:e.responses,generateRouteTypes:e["route-types"],generateUnionEnums:e["generate-union-enums"],httpClientType:e["http-client"]||e.axios?b$1.AXIOS:b$1.FETCH,input:s.resolve(process.cwd(),e.path),modular:e.modular,moduleNameFirstTag:e["module-name-first-tag"],moduleNameIndex:+e["module-name-index"]||0,output:s.resolve(process.cwd(),e.output||"."),patch:e.patch,silent:e.silent,singleHttpClient:e["single-http-client"],sortRoutes:e["sort-routes"],sortTypes:e["sort-types"],templates:e.templates,toJS:e.js,typePrefix:e["type-prefix"],typeSuffix:e["type-suffix"],unwrapResponseData:e["unwrap-response-data"],url:e.path,...d.config});}}),b=defineCommand({meta:{name:a.name,description:a.description,version:a.version},subCommands:{generate:y,"generate-templates":f}});runMain(b);//# sourceMappingURL=cli.js.map
3
3
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts"],"names":["templateGenBaseConfig","TemplatesGenConfig","generateTemplatesCommand","defineCommand","HTTP_CLIENT","args","generateTemplates","codeGenBaseConfig","CodeGenConfig","generateCommand","package_default","customConfig","customConfigPath","consola","error","generateApi","main","runMain"],"mappings":";2LAaA,IAAMA,EAAwB,IAAIC,CAAAA,CAAmB,EAAE,CAAA,CAEjDC,EAA2BC,aAAc,CAAA,CAC7C,KAAM,CACJ,IAAA,CAAM,qBACN,WAAa,CAAA,mDACf,EACA,IAAM,CAAA,CACJ,eAAgB,CACd,IAAA,CAAM,UACN,WACE,CAAA,4EAAA,CACF,QAASH,CAAsB,CAAA,WACjC,CACA,CAAA,aAAA,CAAe,CACb,IAAA,CAAM,SACN,WAAa,CAAA,CAAA,mCAAA,EAAsC,OAAO,MACxDI,CAAAA,GACF,CAAC,CACD,CAAA,CAAA,CAAA,OAAA,CAASJ,EAAsB,cACjC,CAAA,CACA,QAAS,CACP,IAAA,C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AASA,EAAK,OACd,CAAA,kBAAA,CAAoBA,EAAK,uBAAuB,CAAA,CAChD,gBAAiB,CAACA,CAAAA,CAAK,mBAAmB,CAAK,EAAA,CAAA,CAC/C,OAAa,CAAQ,CAAA,OAAA,CAAA,OAAA,CAAQ,GAAI,EAAA,CAAIA,CAAK,CAAA,MAAA,EAAqB,GAAG,CAClE,CAAA,KAAA,CAAOA,EAAK,KACZ,CAAA,MAAA,CAAQA,EAAK,MACb,CAAA,gBAAA,CAAkBA,EAAK,oBAAoB,CAAA,CAC3C,WAAYA,CAAK,CAAA,aAAa,EAC9B,SAAWA,CAAAA,CAAAA,CAAK,YAAY,CAC5B,CAAA,SAAA,CAAWA,CAAK,CAAA,SAAA,CAChB,IAAMA,CAAAA,CAAAA,CAAK,GACX,UAAYA,CAAAA,CAAAA,CAAK,aAAa,CAC9B,CAAA,UAAA,CAAYA,EAAK,aAAa,CAAA,CAC9B,mBAAoBA,CAAK,CAAA,sBAAsB,EAC/C,GAAKA,CAAAA,CAAAA,CAAK,KACV,GAAGM,CACL,CAAC,EACH,CACF,CAAC,CAAA,CAEKK,CAAOb,CAAAA,aAAAA,CAAc,CACzB,IAAM,CAAA,CACJ,KAAMO,CAAY,CAAA,IAAA,CAClB,YAAaA,CAAY,CAAA,WAAA,CACzB,QAASA,CAAY,CAAA,OACvB,EACA,WAAa,CAAA,CACX,SAAUD,CACV,CAAA,oBAAA,CAAsBP,CACxB,CACF,CAAC,CAEDe,CAAAA,OAAAA,CAAQD,CAAI,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport * as url from \"node:url\";\nimport { defineCommand, runMain } from \"citty\";\nimport { consola } from \"consola\";\nimport packageJson from \"./package.json\" with { type: \"json\" };\nimport { TemplatesGenConfig } from \"./src/commands/generate-templates/configuration.js\";\nimport { CodeGenConfig } from \"./src/configuration.js\";\nimport { HTTP_CLIENT } from \"./src/constants.js\";\nimport { generateApi, generateTemplates } from \"./src/index.js\";\nimport type { HttpClientType } from \"./types/index.js\";\n\nconst templateGenBaseConfig = new TemplatesGenConfig({});\n\nconst generateTemplatesCommand = defineCommand({\n meta: {\n name: \"generate-templates\",\n description: 'Generate \".ejs\" templates needed for generate api',\n },\n args: {\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate template. WARNING: May cause data loss\",\n default: templateGenBaseConfig.cleanOutput,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n default: templateGenBaseConfig.httpClientType,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate templates needed to separate files for http client, data contracts, and routes\",\n default: templateGenBaseConfig.modular,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of generated templates\",\n default: templateGenBaseConfig.output,\n required: true,\n },\n rewrite: {\n type: \"boolean\",\n alias: \"r\",\n description: \"rewrite content in existing templates\",\n default: templateGenBaseConfig.rewrite,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: templateGenBaseConfig.silent,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: templateGenBaseConfig.debug,\n },\n },\n run: async ({ args }) => {\n await generateTemplates({\n cleanOutput: args[\"clean-output\"],\n httpClientType: args[\"http-client\"] as HttpClientType,\n modular: args.modular,\n output: args.output,\n rewrite: args.rewrite,\n silent: args.silent,\n debug: args.debug,\n });\n },\n});\n\nconst codeGenBaseConfig = new CodeGenConfig({});\n\nconst generateCommand = defineCommand({\n meta: {\n name: \"generate\",\n description: packageJson.description,\n },\n args: {\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"path/url to swagger scheme\",\n required: true,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of typescript api file\",\n default: \"./\",\n },\n name: {\n type: \"string\",\n alias: \"n\",\n description: \"name of output typescript api file\",\n default: codeGenBaseConfig.fileName,\n },\n templates: {\n type: \"string\",\n alias: \"t\",\n description: \"path to folder containing templates\",\n },\n \"default-as-success\": {\n type: \"boolean\",\n alias: \"d\",\n description:\n 'use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.',\n default: codeGenBaseConfig.defaultResponseAsSuccess,\n },\n responses: {\n type: \"boolean\",\n alias: \"r\",\n description:\n \"generate additional information about request responses also add typings for bad responses\",\n default: codeGenBaseConfig.generateResponses,\n },\n \"union-enums\": {\n type: \"boolean\",\n description: 'generate all \"enum\" types as union types (T1 | T2 | TN)',\n default: codeGenBaseConfig.generateUnionEnums,\n },\n \"add-readonly\": {\n type: \"boolean\",\n description: \"generate readonly properties\",\n default: codeGenBaseConfig.addReadonly,\n },\n \"route-types\": {\n type: \"boolean\",\n description: \"generate type definitions for API routes\",\n default: codeGenBaseConfig.generateRouteTypes,\n },\n \"no-client\": {\n type: \"boolean\",\n description: \"do not generate an API class\",\n default: false,\n },\n \"enum-names-as-values\": {\n type: \"boolean\",\n description:\n \"use values in 'x-enumNames' as enum values (not only as keys)\",\n default: codeGenBaseConfig.enumNamesAsValues,\n },\n \"extract-request-params\": {\n type: \"boolean\",\n description:\n \"extract request params to data contract (Also combine path params and query params into one object)\",\n default: codeGenBaseConfig.extractRequestParams,\n },\n \"extract-request-body\": {\n type: \"boolean\",\n description: \"extract request body type to data contract\",\n default: codeGenBaseConfig.extractRequestBody,\n },\n \"extract-response-body\": {\n type: \"boolean\",\n description: \"extract response body type to data contract\",\n default: codeGenBaseConfig.extractResponseBody,\n },\n \"extract-response-error\": {\n type: \"boolean\",\n description: \"extract response error type to data contract\",\n default: codeGenBaseConfig.extractResponseError,\n },\n \"extract-responses\": {\n type: \"boolean\",\n description: \"extract all responses described in /components/responses\",\n default: codeGenBaseConfig.extractResponses,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate separated files for http client, data contracts, and routes\",\n default: codeGenBaseConfig.modular,\n },\n js: {\n type: \"boolean\",\n description: \"generate js api module with declaration file\",\n default: codeGenBaseConfig.toJS,\n },\n \"module-name-index\": {\n type: \"string\",\n description:\n \"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)\",\n default: codeGenBaseConfig.moduleNameIndex.toString(),\n },\n \"module-name-first-tag\": {\n type: \"boolean\",\n description: \"splits routes based on the first tag\",\n default: codeGenBaseConfig.moduleNameFirstTag,\n },\n axios: {\n type: \"boolean\",\n description: \"generate axios http client\",\n default: false,\n },\n \"unwrap-response-data\": {\n type: \"boolean\",\n description: \"unwrap the data item from the response\",\n default: codeGenBaseConfig.unwrapResponseData,\n },\n \"disable-throw-on-error\": {\n type: \"boolean\",\n description: \"Do not throw an error when response.ok is not true\",\n default: codeGenBaseConfig.disableThrowOnError,\n },\n \"single-http-client\": {\n type: \"boolean\",\n description: \"Ability to send HttpClient instance to Api constructor\",\n default: codeGenBaseConfig.singleHttpClient,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: codeGenBaseConfig.silent,\n },\n \"default-response\": {\n type: \"string\",\n description: \"default type for empty response schema\",\n default: codeGenBaseConfig.defaultResponseType,\n },\n \"type-prefix\": {\n type: \"string\",\n description: \"data contract name prefix\",\n default: codeGenBaseConfig.typePrefix,\n },\n \"type-suffix\": {\n type: \"string\",\n description: \"data contract name suffix\",\n default: codeGenBaseConfig.typeSuffix,\n },\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate api. WARNING: May cause data loss\",\n default: codeGenBaseConfig.cleanOutput,\n },\n \"api-class-name\": {\n type: \"string\",\n description: \"name of the api class\",\n default: codeGenBaseConfig.apiClassName,\n },\n patch: {\n type: \"boolean\",\n description: \"fix up small errors in the swagger source definition\",\n default: codeGenBaseConfig.patch,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: codeGenBaseConfig.debug,\n },\n \"another-array-type\": {\n type: \"boolean\",\n description: \"generate array types as Array<Type> (by default Type[])\",\n default: codeGenBaseConfig.anotherArrayType,\n },\n \"sort-types\": {\n type: \"boolean\",\n description: \"sort fields and types\",\n default: codeGenBaseConfig.sortTypes,\n },\n \"extract-enums\": {\n type: \"boolean\",\n description:\n \"extract all enums from inline interface/type content to typescript enum construction\",\n default: codeGenBaseConfig.extractEnums,\n },\n \"sort-routes\": {\n type: \"boolean\",\n description: \"sort routes in alphabetical order\",\n default: codeGenBaseConfig.sortRoutes,\n },\n \"custom-config\": {\n type: \"string\",\n description: \"custom config: primitiveTypeConstructs, hooks, ... \",\n },\n },\n run: async ({ args }) => {\n let customConfig = undefined;\n\n if (args[\"custom-config\"]) {\n try {\n const customConfigPath = url\n .pathToFileURL(path.resolve(process.cwd(), args[\"custom-config\"]))\n .toString();\n customConfig = await import(customConfigPath);\n customConfig = customConfig.default || customConfig;\n if (customConfig) {\n consola.info(`Found custom config at: ${customConfigPath}`);\n }\n } catch (error) {\n consola.error(\"Error loading custom config:\", error);\n }\n }\n\n await generateApi({\n addReadonly: args[\"add-readonly\"],\n anotherArrayType: args[\"another-array-type\"],\n apiClassName: args[\"api-class-name\"],\n cleanOutput: args[\"clean-output\"],\n debug: args.debug,\n defaultResponseAsSuccess: args[\"default-as-success\"],\n defaultResponseType: args[\"default-response\"],\n disableThrowOnError: args[\"disable-throw-on-error\"],\n enumNamesAsValues: args[\"enum-names-as-values\"],\n extractEnums: args[\"extract-enums\"],\n extractRequestBody: args[\"extract-request-body\"],\n extractRequestParams: args[\"extract-request-params\"],\n extractResponseBody: args[\"extract-response-body\"],\n extractResponseError: args[\"extract-response-error\"],\n extractResponses: args[\"extract-responses\"],\n fileName: args.name,\n generateClient: !args[\"no-client\"],\n generateResponses: args.responses,\n generateRouteTypes: args[\"route-types\"],\n generateUnionEnums: args[\"union-enums\"],\n httpClientType:\n args[\"http-client\"] || args.axios\n ? HTTP_CLIENT.AXIOS\n : HTTP_CLIENT.FETCH,\n input: path.resolve(process.cwd(), args.path as string),\n modular: args.modular,\n moduleNameFirstTag: args[\"module-name-first-tag\"],\n moduleNameIndex: +args[\"module-name-index\"] || 0,\n output: path.resolve(process.cwd(), (args.output as string) || \".\"),\n patch: args.patch,\n silent: args.silent,\n singleHttpClient: args[\"single-http-client\"],\n sortRoutes: args[\"sort-routes\"],\n sortTypes: args[\"sort-types\"],\n templates: args.templates,\n toJS: args.js,\n typePrefix: args[\"type-prefix\"],\n typeSuffix: args[\"type-suffix\"],\n unwrapResponseData: args[\"unwrap-response-data\"],\n url: args.path,\n ...customConfig,\n });\n },\n});\n\nconst main = defineCommand({\n meta: {\n name: packageJson.name,\n description: packageJson.description,\n version: packageJson.version,\n },\n subCommands: {\n generate: generateCommand,\n \"generate-templates\": generateTemplatesCommand,\n },\n});\n\nrunMain(main);\n"]}
1
+ {"version":3,"sources":["../index.ts"],"names":["templateGenBaseConfig","TemplatesGenConfig","generateTemplatesCommand","defineCommand","HTTP_CLIENT","args","generateTemplates","codeGenBaseConfig","CodeGenConfig","generateCommand","package_default","customConfig","loadConfig","generateApi","main","runMain"],"mappings":";+JAYA,IAAMA,EAAwB,IAAIC,CAAAA,CAAmB,EAAE,CAAA,CAEjDC,EAA2BC,aAAc,CAAA,CAC7C,KAAM,CACJ,IAAA,CAAM,qBACN,WAAa,CAAA,mDACf,EACA,IAAM,CAAA,CACJ,eAAgB,CACd,IAAA,CAAM,UACN,WACE,CAAA,4EAAA,CACF,QAASH,CAAsB,CAAA,WACjC,EACA,KAAO,CAAA,CACL,KAAM,SACN,CAAA,WAAA,CAAa,0DACb,OAASA,CAAAA,CAAAA,CAAsB,KACjC,CACA,CAAA,aAAA,CAAe,CACb,IAAM,CAAA,QAAA,CACN,YAAa,CAAsC,mCAAA,EAAA,MAAA,CAAO,OACxDI,GACF,CAAC,IACD,OAASJ,CAAAA,CAAAA,CAAsB,cACjC,CACA,CAAA,OAAA,CAAS,CACP,IAAM,CAAA,SAAA,CACN,YACE,yFACF,CAAA,OAAA,CAASA,EAAsB,OACjC,CAAA,CACA,OAAQ,CACN,IAAA,CAAM,SACN,KAAO,CAAA,GAAA,CACP,YAAa,oCACb,CAAA,OAAA,CAASA,EA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sB,CAC/C,CAAA,GAAA,CAAKA,EAAK,IACV,CAAA,GAAGM,EAAa,MAClB,CAAC,EACH,CACF,CAAC,EAEKG,CAAOX,CAAAA,aAAAA,CAAc,CACzB,IAAM,CAAA,CACJ,KAAMO,CAAY,CAAA,IAAA,CAClB,YAAaA,CAAY,CAAA,WAAA,CACzB,QAASA,CAAY,CAAA,OACvB,EACA,WAAa,CAAA,CACX,SAAUD,CACV,CAAA,oBAAA,CAAsBP,CACxB,CACF,CAAC,CAEDa,CAAAA,OAAAA,CAAQD,CAAI,CAAA","file":"cli.js","sourcesContent":["#!/usr/bin/env node\n\nimport * as path from \"node:path\";\nimport { loadConfig } from \"c12\";\nimport { defineCommand, runMain } from \"citty\";\nimport packageJson from \"./package.json\" with { type: \"json\" };\nimport { TemplatesGenConfig } from \"./src/commands/generate-templates/configuration.js\";\nimport { CodeGenConfig } from \"./src/configuration.js\";\nimport { HTTP_CLIENT } from \"./src/constants.js\";\nimport { generateApi, generateTemplates } from \"./src/index.js\";\nimport type { GenerateApiParams, HttpClientType } from \"./types/index.js\";\n\nconst templateGenBaseConfig = new TemplatesGenConfig({});\n\nconst generateTemplatesCommand = defineCommand({\n meta: {\n name: \"generate-templates\",\n description: 'Generate \".ejs\" templates needed for generate api',\n },\n args: {\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate template. WARNING: May cause data loss\",\n default: templateGenBaseConfig.cleanOutput,\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: templateGenBaseConfig.debug,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n default: templateGenBaseConfig.httpClientType,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate templates needed to separate files for http client, data contracts, and routes\",\n default: templateGenBaseConfig.modular,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of generated templates\",\n default: templateGenBaseConfig.output,\n required: true,\n },\n rewrite: {\n type: \"boolean\",\n alias: \"r\",\n description: \"rewrite content in existing templates\",\n default: templateGenBaseConfig.rewrite,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: templateGenBaseConfig.silent,\n },\n },\n run: async ({ args }) => {\n await generateTemplates({\n cleanOutput: args[\"clean-output\"],\n httpClientType: args[\"http-client\"] as HttpClientType,\n modular: args.modular,\n output: args.output,\n rewrite: args.rewrite,\n silent: args.silent,\n debug: args.debug,\n });\n },\n});\n\nconst codeGenBaseConfig = new CodeGenConfig({});\n\nconst generateCommand = defineCommand({\n meta: {\n name: \"generate\",\n description: packageJson.description,\n },\n args: {\n \"add-readonly\": {\n type: \"boolean\",\n description: \"generate readonly properties\",\n default: codeGenBaseConfig.addReadonly,\n },\n \"another-array-type\": {\n type: \"boolean\",\n description: \"generate array types as Array<Type> (by default Type[])\",\n default: codeGenBaseConfig.anotherArrayType,\n },\n \"api-class-name\": {\n type: \"string\",\n description: \"name of the api class\",\n default: codeGenBaseConfig.apiClassName,\n },\n axios: {\n type: \"boolean\",\n description: \"generate axios http client\",\n default: false,\n },\n \"clean-output\": {\n type: \"boolean\",\n description:\n \"clean output folder before generate api. WARNING: May cause data loss\",\n default: codeGenBaseConfig.cleanOutput,\n },\n client: {\n type: \"boolean\",\n description: \"do not generate an API class\",\n default: codeGenBaseConfig.generateClient,\n },\n \"custom-config\": {\n type: \"string\",\n description: \"custom config: primitiveTypeConstructs, hooks, ... \",\n },\n debug: {\n type: \"boolean\",\n description: \"additional information about processes inside this tool\",\n default: codeGenBaseConfig.debug,\n },\n \"default-as-success\": {\n type: \"boolean\",\n alias: \"d\",\n description:\n 'use \"default\" response status code as success response too. some swagger schemas use \"default\" response status code as success response type by default.',\n default: codeGenBaseConfig.defaultResponseAsSuccess,\n },\n \"default-response\": {\n type: \"string\",\n description: \"default type for empty response schema\",\n default: codeGenBaseConfig.defaultResponseType,\n },\n \"disable-throw-on-error\": {\n type: \"boolean\",\n description: \"Do not throw an error when response.ok is not true\",\n default: codeGenBaseConfig.disableThrowOnError,\n },\n \"enum-names-as-values\": {\n type: \"boolean\",\n description:\n \"use values in 'x-enumNames' as enum values (not only as keys)\",\n default: codeGenBaseConfig.enumNamesAsValues,\n },\n \"extract-enums\": {\n type: \"boolean\",\n description:\n \"extract all enums from inline interface/type content to typescript enum construction\",\n default: codeGenBaseConfig.extractEnums,\n },\n \"extract-request-body\": {\n type: \"boolean\",\n description: \"extract request body type to data contract\",\n default: codeGenBaseConfig.extractRequestBody,\n },\n \"extract-request-params\": {\n type: \"boolean\",\n description:\n \"extract request params to data contract (Also combine path params and query params into one object)\",\n default: codeGenBaseConfig.extractRequestParams,\n },\n \"extract-response-body\": {\n type: \"boolean\",\n description: \"extract response body type to data contract\",\n default: codeGenBaseConfig.extractResponseBody,\n },\n \"extract-response-error\": {\n type: \"boolean\",\n description: \"extract response error type to data contract\",\n default: codeGenBaseConfig.extractResponseError,\n },\n \"extract-responses\": {\n type: \"boolean\",\n description: \"extract all responses described in /components/responses\",\n default: codeGenBaseConfig.extractResponses,\n },\n \"generate-union-enums\": {\n type: \"boolean\",\n description: 'generate all \"enum\" types as union types (T1 | T2 | TN)',\n default: codeGenBaseConfig.generateUnionEnums,\n },\n \"http-client\": {\n type: \"string\",\n description: `http client type (possible values: ${Object.values(\n HTTP_CLIENT,\n )})`,\n },\n js: {\n type: \"boolean\",\n description: \"generate js api module with declaration file\",\n default: codeGenBaseConfig.toJS,\n },\n modular: {\n type: \"boolean\",\n description:\n \"generate separated files for http client, data contracts, and routes\",\n default: codeGenBaseConfig.modular,\n },\n \"module-name-first-tag\": {\n type: \"boolean\",\n description: \"splits routes based on the first tag\",\n default: codeGenBaseConfig.moduleNameFirstTag,\n },\n \"module-name-index\": {\n type: \"string\",\n description:\n \"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)\",\n default: codeGenBaseConfig.moduleNameIndex.toString(),\n },\n name: {\n type: \"string\",\n alias: \"n\",\n description: \"name of output typescript api file\",\n default: codeGenBaseConfig.fileName,\n },\n output: {\n type: \"string\",\n alias: \"o\",\n description: \"output path of typescript api file\",\n default: \"./\",\n },\n patch: {\n type: \"boolean\",\n description: \"fix up small errors in the swagger source definition\",\n default: codeGenBaseConfig.patch,\n },\n path: {\n type: \"string\",\n alias: \"p\",\n description: \"path/url to swagger scheme\",\n required: true,\n },\n responses: {\n type: \"boolean\",\n alias: \"r\",\n description:\n \"generate additional information about request responses also add typings for bad responses\",\n default: codeGenBaseConfig.generateResponses,\n },\n \"route-types\": {\n type: \"boolean\",\n description: \"generate type definitions for API routes\",\n default: codeGenBaseConfig.generateRouteTypes,\n },\n silent: {\n type: \"boolean\",\n description: \"Output only errors to console\",\n default: codeGenBaseConfig.silent,\n },\n \"single-http-client\": {\n type: \"boolean\",\n description: \"Ability to send HttpClient instance to Api constructor\",\n default: codeGenBaseConfig.singleHttpClient,\n },\n \"sort-routes\": {\n type: \"boolean\",\n description: \"sort routes in alphabetical order\",\n default: codeGenBaseConfig.sortRoutes,\n },\n \"sort-types\": {\n type: \"boolean\",\n description: \"sort fields and types\",\n default: codeGenBaseConfig.sortTypes,\n },\n templates: {\n type: \"string\",\n alias: \"t\",\n description: \"path to folder containing templates\",\n },\n \"type-prefix\": {\n type: \"string\",\n description: \"data contract name prefix\",\n default: codeGenBaseConfig.typePrefix,\n },\n \"type-suffix\": {\n type: \"string\",\n description: \"data contract name suffix\",\n default: codeGenBaseConfig.typeSuffix,\n },\n \"unwrap-response-data\": {\n type: \"boolean\",\n description: \"unwrap the data item from the response\",\n default: codeGenBaseConfig.unwrapResponseData,\n },\n },\n run: async ({ args }) => {\n const customConfig = await loadConfig<GenerateApiParams>({\n configFile: args[\"custom-config\"],\n });\n\n await generateApi({\n addReadonly: args[\"add-readonly\"],\n anotherArrayType: args[\"another-array-type\"],\n apiClassName: args[\"api-class-name\"],\n cleanOutput: args[\"clean-output\"],\n debug: args.debug,\n defaultResponseAsSuccess: args[\"default-as-success\"],\n defaultResponseType: args[\"default-response\"],\n disableThrowOnError: args[\"disable-throw-on-error\"],\n enumNamesAsValues: args[\"enum-names-as-values\"],\n extractEnums: args[\"extract-enums\"],\n extractRequestBody: args[\"extract-request-body\"],\n extractRequestParams: args[\"extract-request-params\"],\n extractResponseBody: args[\"extract-response-body\"],\n extractResponseError: args[\"extract-response-error\"],\n extractResponses: args[\"extract-responses\"],\n fileName: args.name,\n generateClient: args.client,\n generateResponses: args.responses,\n generateRouteTypes: args[\"route-types\"],\n generateUnionEnums: args[\"generate-union-enums\"],\n httpClientType:\n args[\"http-client\"] || args.axios\n ? HTTP_CLIENT.AXIOS\n : HTTP_CLIENT.FETCH,\n input: path.resolve(process.cwd(), args.path as string),\n modular: args.modular,\n moduleNameFirstTag: args[\"module-name-first-tag\"],\n moduleNameIndex: +args[\"module-name-index\"] || 0,\n output: path.resolve(process.cwd(), (args.output as string) || \".\"),\n patch: args.patch,\n silent: args.silent,\n singleHttpClient: args[\"single-http-client\"],\n sortRoutes: args[\"sort-routes\"],\n sortTypes: args[\"sort-types\"],\n templates: args.templates,\n toJS: args.js,\n typePrefix: args[\"type-prefix\"],\n typeSuffix: args[\"type-suffix\"],\n unwrapResponseData: args[\"unwrap-response-data\"],\n url: args.path,\n ...customConfig.config,\n });\n },\n});\n\nconst main = defineCommand({\n meta: {\n name: packageJson.name,\n description: packageJson.description,\n version: packageJson.version,\n },\n subCommands: {\n generate: generateCommand,\n \"generate-templates\": generateTemplatesCommand,\n },\n});\n\nrunMain(main);\n"]}
package/dist/lib.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkNP4SPLZD_cjs=require('./chunk-NP4SPLZD.cjs');Object.defineProperty(exports,"constants",{enumerable:true,get:function(){return chunkNP4SPLZD_cjs.c}});Object.defineProperty(exports,"generateApi",{enumerable:true,get:function(){return chunkNP4SPLZD_cjs.g}});Object.defineProperty(exports,"generateTemplates",{enumerable:true,get:function(){return chunkNP4SPLZD_cjs.f}});//# sourceMappingURL=lib.cjs.map
1
+ 'use strict';var chunkNO753Z7P_cjs=require('./chunk-NO753Z7P.cjs');Object.defineProperty(exports,"constants",{enumerable:true,get:function(){return chunkNO753Z7P_cjs.c}});Object.defineProperty(exports,"generateApi",{enumerable:true,get:function(){return chunkNO753Z7P_cjs.g}});Object.defineProperty(exports,"generateTemplates",{enumerable:true,get:function(){return chunkNO753Z7P_cjs.f}});//# sourceMappingURL=lib.cjs.map
2
2
  //# sourceMappingURL=lib.cjs.map
package/dist/lib.d.cts ADDED
@@ -0,0 +1,3 @@
1
+ export { generateApi } from './_tsup-dts-rollup.cjs';
2
+ export { constants } from './_tsup-dts-rollup.cjs';
3
+ export { generateTemplates } from './_tsup-dts-rollup.cjs';
package/dist/lib.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { generateApi } from './_tsup-dts-rollup.js';
2
+ export { constants } from './_tsup-dts-rollup.js';
3
+ export { generateTemplates } from './_tsup-dts-rollup.js';
package/dist/lib.js CHANGED
@@ -1,2 +1,2 @@
1
- export{c as constants,g as generateApi,f as generateTemplates}from'./chunk-WJYL7LUK.js';//# sourceMappingURL=lib.js.map
1
+ export{c as constants,g as generateApi,f as generateTemplates}from'./chunk-TVX6OCDM.js';//# sourceMappingURL=lib.js.map
2
2
  //# sourceMappingURL=lib.js.map
package/package.json CHANGED
@@ -1,28 +1,31 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "13.0.27",
3
+ "version": "13.1.0",
4
4
  "description": "Generate the API client for Fetch or Axios from an OpenAPI Specification",
5
5
  "homepage": "https://github.com/acacode/swagger-typescript-api",
6
6
  "bugs": "https://github.com/acacode/swagger-typescript-api/issues",
7
7
  "repository": "github:acacode/swagger-typescript-api",
8
8
  "license": "MIT",
9
9
  "author": "Sergey Volkov <js2me@outlook.com>",
10
- "contributors": [
10
+ "maintainers": [
11
11
  "Sora Morimoto <sora@morimoto.io>"
12
12
  ],
13
13
  "type": "module",
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": {
17
+ "types": "./dist/lib.d.ts",
17
18
  "default": "./dist/lib.js"
18
19
  },
19
20
  "require": {
21
+ "types": "./dist/lib.d.cts",
20
22
  "default": "./dist/lib.cjs"
21
23
  }
22
24
  }
23
25
  },
24
26
  "main": "./dist/lib.cjs",
25
27
  "module": "./dist/lib.js",
28
+ "types": "./dist/lib.d.cts",
26
29
  "bin": {
27
30
  "sta": "./dist/cli.js",
28
31
  "swagger-typescript-api": "./dist/cli.js"
@@ -40,43 +43,54 @@
40
43
  "format:check": "biome format .",
41
44
  "lint": "biome check",
42
45
  "prepack": "tsup",
43
- "test": "vitest run"
46
+ "test": "vitest run",
47
+ "typedoc": "typedoc"
44
48
  },
45
49
  "dependencies": {
50
+ "@biomejs/js-api": "^0.7.1",
51
+ "@biomejs/wasm-nodejs": "^1.9.4",
46
52
  "@types/swagger-schema-official": "^2.0.25",
53
+ "c12": "^3.0.3",
47
54
  "citty": "^0.1.6",
48
55
  "consola": "^3.4.2",
49
- "cosmiconfig": "^9.0.0",
50
56
  "eta": "^2.2.0",
51
57
  "js-yaml": "^4.1.0",
52
58
  "lodash": "^4.17.21",
53
59
  "nanoid": "^5.1.5",
54
- "prettier": "~3.5.3",
55
60
  "swagger-schema-official": "2.0.0-bab6bed",
56
61
  "swagger2openapi": "^7.0.8",
57
- "typescript": "~5.8.2"
62
+ "typescript": "~5.8.3"
58
63
  },
59
64
  "devDependencies": {
60
65
  "@biomejs/biome": "1.9.4",
61
66
  "@changesets/changelog-github": "0.5.1",
62
67
  "@changesets/cli": "2.28.1",
68
+ "@microsoft/api-extractor": "7.52.3",
63
69
  "@tsconfig/node18": "18.2.4",
64
70
  "@tsconfig/strictest": "2.0.5",
65
71
  "@types/js-yaml": "4.0.9",
66
72
  "@types/lodash": "4.17.16",
67
- "@types/node": "22.13.13",
73
+ "@types/node": "22.14.1",
68
74
  "@types/swagger2openapi": "7.0.4",
69
75
  "axios": "1.8.4",
70
76
  "openapi-types": "12.1.3",
71
77
  "tsup": "8.4.0",
72
- "vitest": "3.0.9"
78
+ "typedoc": "0.28.2",
79
+ "vitest": "3.1.1"
73
80
  },
74
- "packageManager": "yarn@4.7.0",
81
+ "packageManager": "yarn@4.9.1",
75
82
  "engines": {
76
83
  "node": ">=18.0.0"
77
84
  },
78
85
  "publishConfig": {
79
86
  "access": "public",
87
+ "provenance": true,
80
88
  "registry": "https://registry.npmjs.org"
89
+ },
90
+ "typedocOptions": {
91
+ "entryPoints": [
92
+ "src/index.ts"
93
+ ],
94
+ "skipErrorChecking": true
81
95
  }
82
96
  }