swagger-typescript-api 13.0.14 → 13.0.15
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/{chunk-PZ627X5P.cjs → chunk-HJEBGORP.cjs} +6 -6
- package/dist/chunk-HJEBGORP.cjs.map +1 -0
- package/dist/{chunk-FPPX3UNW.js → chunk-W6DHQSAC.js} +3 -3
- package/dist/chunk-W6DHQSAC.js.map +1 -0
- package/dist/cli.cjs +3 -3
- package/dist/cli.js +1 -1
- package/dist/lib.cjs +4 -4
- package/dist/lib.js +1 -1
- package/dist/types.d.cts +41 -36
- package/dist/types.d.ts +41 -36
- package/package.json +14 -14
- package/dist/chunk-FPPX3UNW.js.map +0 -1
- package/dist/chunk-PZ627X5P.cjs.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var chunkHJEBGORP_cjs = require('./chunk-HJEBGORP.cjs');
|
|
5
5
|
var path = require('path');
|
|
6
6
|
var v = require('lodash');
|
|
7
7
|
var A = require('didyoumean');
|
|
@@ -35,9 +35,9 @@ ${r}`].filter(Boolean).join(`
|
|
|
35
35
|
${n.description&&`
|
|
36
36
|
${n.description}`}
|
|
37
37
|
|
|
38
|
-
${i}`);};var L=e=>{console.log(e.input.version);};var I={number:e=>+e,numeric:e=>+e,str:e=>`${e}`,string:e=>`${e}`,bool:e=>!!e,boolean:e=>!!e},M=e=>{let t=null,n=[],a=null,s=e.includes("--no-");v__default.default.compact(v__default.default.split(e," ").map(i=>i.replace(/,/g,""))).forEach(i=>{if(i.startsWith("-"))n.push(i);else if(a===null&&(i.startsWith("{")||i.startsWith("[")||i.startsWith("<"))){let p=i.replace(/[{[<>}\].]/g,""),m=i.includes("...");a={raw:i,variadic:m,name:p,formatter:I[p]||I.string};}});let r=n.slice().sort((i,p)=>p.length-i.length)[0];return v__default.default.isEmpty(r)||(t=v__default.default.camelCase((s?r.replace("--no-",""):r).replace(/(--?)/,""))),{isNoFlag:s,raw:e,name:t,keys:n,value:a}},x=e=>{let t=M(e.flags);return t.name?{required:!!e.required,description:`${e.description||""}`,default:e.default,flags:t,operation:e.operation,internal:e.internal}:(console.warn("invalid option",e),null)};var W=e=>{let t={},n=(s,{addVersion:r=!1,addHelp:i=!0}={})=>(t[s.name]={name:s.name,description:`${s.description||""}`,options:v__default.default.compact(v__default.default.map(s.options,x))},r&&t[s.name].options.unshift(x({flags:"-v, --version",description:"output the current version",operation:()=>L(a)})),i&&t[s.name].options.push(x({flags:"-h, --help",description:"display help for command",operation:()=>R(t,a,t[s.name])})),a),a={commands:t,input:e,addCommand:n,execute:s=>H(s,t)};return n({name:c,options:[]},{addVersion:!1,addHelp:!1}),v__default.default.forEach(e.options,s=>{let r=x(s);if(r){if(_.includes(r.name)){console.warn("reserved option",r.name);return}t[c].options.push(r);}}),t[c].options.unshift(x({flags:"-v, --version",description:"output the current version",operation:()=>L(a)})),t[c].options.push(x({flags:"-h, --help",description:"display help for command",operation:()=>R(t,a,t[c])})),v__default.default.forEach(e.commands,n),a};var o=new
|
|
38
|
+
${i}`);};var L=e=>{console.log(e.input.version);};var I={number:e=>+e,numeric:e=>+e,str:e=>`${e}`,string:e=>`${e}`,bool:e=>!!e,boolean:e=>!!e},M=e=>{let t=null,n=[],a=null,s=e.includes("--no-");v__default.default.compact(v__default.default.split(e," ").map(i=>i.replace(/,/g,""))).forEach(i=>{if(i.startsWith("-"))n.push(i);else if(a===null&&(i.startsWith("{")||i.startsWith("[")||i.startsWith("<"))){let p=i.replace(/[{[<>}\].]/g,""),m=i.includes("...");a={raw:i,variadic:m,name:p,formatter:I[p]||I.string};}});let r=n.slice().sort((i,p)=>p.length-i.length)[0];return v__default.default.isEmpty(r)||(t=v__default.default.camelCase((s?r.replace("--no-",""):r).replace(/(--?)/,""))),{isNoFlag:s,raw:e,name:t,keys:n,value:a}},x=e=>{let t=M(e.flags);return t.name?{required:!!e.required,description:`${e.description||""}`,default:e.default,flags:t,operation:e.operation,internal:e.internal}:(console.warn("invalid option",e),null)};var W=e=>{let t={},n=(s,{addVersion:r=!1,addHelp:i=!0}={})=>(t[s.name]={name:s.name,description:`${s.description||""}`,options:v__default.default.compact(v__default.default.map(s.options,x))},r&&t[s.name].options.unshift(x({flags:"-v, --version",description:"output the current version",operation:()=>L(a)})),i&&t[s.name].options.push(x({flags:"-h, --help",description:"display help for command",operation:()=>R(t,a,t[s.name])})),a),a={commands:t,input:e,addCommand:n,execute:s=>H(s,t)};return n({name:c,options:[]},{addVersion:!1,addHelp:!1}),v__default.default.forEach(e.options,s=>{let r=x(s);if(r){if(_.includes(r.name)){console.warn("reserved option",r.name);return}t[c].options.push(r);}}),t[c].options.unshift(x({flags:"-v, --version",description:"output the current version",operation:()=>L(a)})),t[c].options.push(x({flags:"-h, --help",description:"display help for command",operation:()=>R(t,a,t[c])})),v__default.default.forEach(e.commands,n),a};var o=new chunkHJEBGORP_cjs.d({}),w=new chunkHJEBGORP_cjs.e({}),V=W({name:chunkHJEBGORP_cjs.a.name,alias:"sta",version:chunkHJEBGORP_cjs.a.version,description:`Generate api via swagger scheme.
|
|
39
39
|
Supports OA 3.0, 2.0, JSON, yaml.`,options:[{flags:"-p, --path <string>",description:"path/url to swagger scheme",required:!0},{flags:"-o, --output <string>",description:"output path of typescript api file",default:"./"},{flags:"-n, --name <string>",description:"name of output typescript api file",default:o.fileName},{flags:"-t, --templates <string>",description:"path to folder containing templates"},{flags:"-d, --default-as-success",description:`use "default" response status code as success response too.
|
|
40
40
|
some swagger schemas use "default" response status code as success response type by default.`,default:o.defaultResponseAsSuccess,internal:{name:"defaultResponseAsSuccess"}},{flags:"-r, --responses",description:`generate additional information about request responses
|
|
41
|
-
also add typings for bad responses`,default:o.generateResponses,internal:{name:"generateResponses"}},{flags:"--union-enums",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:o.generateUnionEnums,internal:{name:"generateUnionEnums"}},{flags:"--add-readonly",description:"generate readonly properties",default:o.addReadonly},{flags:"--route-types",description:"generate type definitions for API routes",default:o.generateRouteTypes,internal:{name:"generateRouteTypes"}},{flags:"--no-client",description:"do not generate an API class",default:o.generateClient},{flags:"--enum-names-as-values",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:o.enumNamesAsValues},{flags:"--extract-request-params",description:"extract request params to data contract (Also combine path params and query params into one object)",default:o.extractRequestParams,internal:{formatter:Boolean}},{flags:"--extract-request-body",description:"extract request body type to data contract",default:o.extractRequestBody,internal:{formatter:Boolean}},{flags:"--extract-response-body",description:"extract response body type to data contract",default:o.extractResponseBody,internal:{formatter:Boolean}},{flags:"--extract-response-error",description:"extract response error type to data contract",default:o.extractResponseError,internal:{formatter:Boolean}},{flags:"--extract-responses",description:"extract all responses described in /components/responses",default:o.extractResponses,internal:{formatter:Boolean}},{flags:"--modular",description:"generate separated files for http client, data contracts, and routes",default:o.modular,internal:{formatter:Boolean}},{flags:"--js",description:"generate js api module with declaration file",default:o.toJS,internal:{formatter:Boolean,name:"toJS"}},{flags:"--module-name-index <number>",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:o.moduleNameIndex,internal:{formatter:e=>+e||0}},{flags:"--module-name-first-tag",description:"splits routes based on the first tag",default:o.moduleNameFirstTag},{flags:"--disableStrictSSL",description:"disabled strict SSL",default:o.disableStrictSSL,internal:{formatter:Boolean}},{flags:"--disableProxy",description:"disabled proxy",default:o.disableProxy,internal:{formatter:Boolean}},{flags:"--axios",description:"generate axios http client",default:o.httpClientType===
|
|
41
|
+
also add typings for bad responses`,default:o.generateResponses,internal:{name:"generateResponses"}},{flags:"--union-enums",description:'generate all "enum" types as union types (T1 | T2 | TN)',default:o.generateUnionEnums,internal:{name:"generateUnionEnums"}},{flags:"--add-readonly",description:"generate readonly properties",default:o.addReadonly},{flags:"--route-types",description:"generate type definitions for API routes",default:o.generateRouteTypes,internal:{name:"generateRouteTypes"}},{flags:"--no-client",description:"do not generate an API class",default:o.generateClient},{flags:"--enum-names-as-values",description:"use values in 'x-enumNames' as enum values (not only as keys)",default:o.enumNamesAsValues},{flags:"--extract-request-params",description:"extract request params to data contract (Also combine path params and query params into one object)",default:o.extractRequestParams,internal:{formatter:Boolean}},{flags:"--extract-request-body",description:"extract request body type to data contract",default:o.extractRequestBody,internal:{formatter:Boolean}},{flags:"--extract-response-body",description:"extract response body type to data contract",default:o.extractResponseBody,internal:{formatter:Boolean}},{flags:"--extract-response-error",description:"extract response error type to data contract",default:o.extractResponseError,internal:{formatter:Boolean}},{flags:"--extract-responses",description:"extract all responses described in /components/responses",default:o.extractResponses,internal:{formatter:Boolean}},{flags:"--modular",description:"generate separated files for http client, data contracts, and routes",default:o.modular,internal:{formatter:Boolean}},{flags:"--js",description:"generate js api module with declaration file",default:o.toJS,internal:{formatter:Boolean,name:"toJS"}},{flags:"--module-name-index <number>",description:"determines which path index should be used for routes separation (example: GET:/fruits/getFruit -> index:0 -> moduleName -> fruits)",default:o.moduleNameIndex,internal:{formatter:e=>+e||0}},{flags:"--module-name-first-tag",description:"splits routes based on the first tag",default:o.moduleNameFirstTag},{flags:"--disableStrictSSL",description:"disabled strict SSL",default:o.disableStrictSSL,internal:{formatter:Boolean}},{flags:"--disableProxy",description:"disabled proxy",default:o.disableProxy,internal:{formatter:Boolean}},{flags:"--axios",description:"generate axios http client",default:o.httpClientType===chunkHJEBGORP_cjs.b.AXIOS},{flags:"--unwrap-response-data",description:"unwrap the data item from the response",default:o.unwrapResponseData},{flags:"--disable-throw-on-error",description:"Do not throw an error when response.ok is not true",default:o.disableThrowOnError},{flags:"--single-http-client",description:"Ability to send HttpClient instance to Api constructor",default:o.singleHttpClient,internal:{formatter:Boolean}},{flags:"--silent",description:"Output only errors to console",default:o.silent,internal:{formatter:Boolean}},{flags:"--default-response <type>",description:"default type for empty response schema",default:o.defaultResponseType,internal:{name:"defaultResponseType"}},{flags:"--type-prefix <string>",description:"data contract name prefix",default:o.typePrefix},{flags:"--type-suffix <string>",description:"data contract name suffix",default:o.typeSuffix},{flags:"--clean-output",description:"clean output folder before generate api. WARNING: May cause data loss",default:o.cleanOutput,internal:{formatter:Boolean}},{flags:"--api-class-name <string>",description:"name of the api class",default:o.apiClassName},{flags:"--patch",description:"fix up small errors in the swagger source definition",default:o.patch,internal:{formatter:Boolean}},{flags:"--debug",description:"additional information about processes inside this tool",default:o.debug},{flags:"--another-array-type",description:"generate array types as Array<Type> (by default Type[])",default:o.anotherArrayType},{flags:"--sort-types",description:"sort fields and types",default:o.sortTypes},{flags:"--extract-enums",description:"extract all enums from inline interface\\type content to typescript enum construction",default:o.extractEnums},{flags:"--sort-routes",description:"sort routes in alphabetical order",default:o.sortRoutes},{flags:"--custom-config <string>",description:"custom config: primitiveTypeConstructs, hooks, ... ",default:""}]});V.addCommand({name:"generate-templates",description:'Generate ".ejs" templates needed for generate api',options:[{flags:"-o, --output <string>",description:"output path of generated templates",default:w.output},{flags:"-m, --modular",description:"generate templates needed to separate files for http client, data contracts, and routes",default:w.modular,internal:{formatter:Boolean}},{flags:"--http-client <string>",description:`http client type (possible values: ${Object.values(chunkHJEBGORP_cjs.b).map(e=>`"${e}"`).join(", ")})`,default:w.httpClientType,internal:{name:"httpClientType"}},{flags:"-c, --clean-output",description:"clean output folder before generate template. WARNING: May cause data loss",default:w.cleanOutput,internal:{formatter:Boolean}},{flags:"-r, --rewrite",description:"rewrite content in existing templates",default:w.rewrite,internal:{formatter:Boolean}},{flags:"--silent",description:"Output only errors to console",default:w.silent,internal:{formatter:Boolean}}]});var K=async()=>{let{command:e,options:t}=await V.execute({args:process.argv}),n=null,a;if(t.customConfig){try{a=path.resolve(process.cwd(),t.customConfig),n=await import(a),n=n.default||n;}catch(s){console.error("Error loading custom config",s);}n&&console.log(`\u2728 found custom config at: ${a}`);}try{switch(e){case null:{await chunkHJEBGORP_cjs.g({...t,name:t.name,url:t.path,generateRouteTypes:t.generateRouteTypes,generateClient:!!(t.axios||t.client),httpClientType:t.axios?chunkHJEBGORP_cjs.b.AXIOS:chunkHJEBGORP_cjs.b.FETCH,input:path.resolve(process.cwd(),t.path),output:path.resolve(process.cwd(),t.output||"."),...n});break}case"generate-templates":{await chunkHJEBGORP_cjs.f(t);break}default:break}}catch(s){console.error(s),process.exit(1);}process.exit(0);};K();
|
|
42
42
|
//# sourceMappingURL=cli.cjs.map
|
|
43
43
|
//# sourceMappingURL=cli.cjs.map
|
package/dist/cli.js
CHANGED
package/dist/lib.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var chunkHJEBGORP_cjs = require('./chunk-HJEBGORP.cjs');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
Object.defineProperty(exports, "constants", {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: function () { return
|
|
10
|
+
get: function () { return chunkHJEBGORP_cjs.c; }
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "generateApi", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function () { return
|
|
14
|
+
get: function () { return chunkHJEBGORP_cjs.g; }
|
|
15
15
|
});
|
|
16
16
|
Object.defineProperty(exports, "generateTemplates", {
|
|
17
17
|
enumerable: true,
|
|
18
|
-
get: function () { return
|
|
18
|
+
get: function () { return chunkHJEBGORP_cjs.f; }
|
|
19
19
|
});
|
|
20
20
|
//# sourceMappingURL=lib.cjs.map
|
|
21
21
|
//# sourceMappingURL=lib.cjs.map
|
package/dist/lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
export { c as constants, g as generateApi, f as generateTemplates } from './chunk-
|
|
2
|
+
export { c as constants, g as generateApi, f as generateTemplates } from './chunk-W6DHQSAC.js';
|
|
3
3
|
//# sourceMappingURL=lib.js.map
|
|
4
4
|
//# sourceMappingURL=lib.js.map
|
package/dist/types.d.cts
CHANGED
|
@@ -1216,7 +1216,7 @@ interface GenerateApiParamsBase {
|
|
|
1216
1216
|
requestOptions?: null | Partial<RequestInit>;
|
|
1217
1217
|
|
|
1218
1218
|
/** ts compiler configuration object (for --to-js option) */
|
|
1219
|
-
compilerTsConfig?: Record<string,
|
|
1219
|
+
compilerTsConfig?: Record<string, unknown>;
|
|
1220
1220
|
|
|
1221
1221
|
/**
|
|
1222
1222
|
* custom ts->* translator
|
|
@@ -1289,28 +1289,28 @@ type CodeGenConstruct = {
|
|
|
1289
1289
|
CodeGenKeyword: {
|
|
1290
1290
|
UtilRequiredKeys: string;
|
|
1291
1291
|
};
|
|
1292
|
-
ArrayType: (content:
|
|
1293
|
-
StringValue: (content:
|
|
1294
|
-
BooleanValue: (content:
|
|
1295
|
-
NumberValue: (content:
|
|
1296
|
-
NullValue: (content:
|
|
1297
|
-
UnionType: (content:
|
|
1298
|
-
ExpressionGroup: (content:
|
|
1299
|
-
IntersectionType: (content:
|
|
1300
|
-
RecordType: (content:
|
|
1301
|
-
TypeField: (content:
|
|
1302
|
-
InterfaceDynamicField: (content:
|
|
1303
|
-
EnumField: (content:
|
|
1304
|
-
EnumFieldsWrapper: (content:
|
|
1305
|
-
ObjectWrapper: (content:
|
|
1306
|
-
MultilineComment: (content:
|
|
1307
|
-
TypeWithGeneric: (content:
|
|
1292
|
+
ArrayType: (content: unknown) => string;
|
|
1293
|
+
StringValue: (content: unknown) => string;
|
|
1294
|
+
BooleanValue: (content: unknown) => string;
|
|
1295
|
+
NumberValue: (content: unknown) => string;
|
|
1296
|
+
NullValue: (content: unknown) => string;
|
|
1297
|
+
UnionType: (content: unknown) => string;
|
|
1298
|
+
ExpressionGroup: (content: unknown) => string;
|
|
1299
|
+
IntersectionType: (content: unknown) => string;
|
|
1300
|
+
RecordType: (content: unknown) => string;
|
|
1301
|
+
TypeField: (content: unknown) => string;
|
|
1302
|
+
InterfaceDynamicField: (content: unknown) => string;
|
|
1303
|
+
EnumField: (content: unknown) => string;
|
|
1304
|
+
EnumFieldsWrapper: (content: unknown) => string;
|
|
1305
|
+
ObjectWrapper: (content: unknown) => string;
|
|
1306
|
+
MultilineComment: (content: unknown) => string;
|
|
1307
|
+
TypeWithGeneric: (content: unknown) => string;
|
|
1308
1308
|
};
|
|
1309
1309
|
|
|
1310
1310
|
type PrimitiveTypeStructValue =
|
|
1311
1311
|
| string
|
|
1312
1312
|
| ((
|
|
1313
|
-
schema: Record<string,
|
|
1313
|
+
schema: Record<string, unknown>,
|
|
1314
1314
|
parser: SchemaParser,
|
|
1315
1315
|
) => string);
|
|
1316
1316
|
|
|
@@ -1373,60 +1373,65 @@ type BuildRoutePath = {
|
|
|
1373
1373
|
|
|
1374
1374
|
interface Hooks {
|
|
1375
1375
|
/** calls before parse\process route path */
|
|
1376
|
-
onPreBuildRoutePath: (routePath: string) => string |
|
|
1376
|
+
onPreBuildRoutePath: (routePath: string) => string | undefined;
|
|
1377
1377
|
/** calls after parse\process route path */
|
|
1378
|
-
onBuildRoutePath: (data: BuildRoutePath) => BuildRoutePath |
|
|
1378
|
+
onBuildRoutePath: (data: BuildRoutePath) => BuildRoutePath | undefined;
|
|
1379
1379
|
/** calls before insert path param name into string path interpolation */
|
|
1380
1380
|
onInsertPathParam: (
|
|
1381
1381
|
paramName: string,
|
|
1382
1382
|
index: number,
|
|
1383
1383
|
arr: BuildRouteParam[],
|
|
1384
1384
|
resultRoute: string,
|
|
1385
|
-
) => string |
|
|
1385
|
+
) => string | undefined;
|
|
1386
1386
|
/** calls after parse schema component */
|
|
1387
|
-
onCreateComponent: (
|
|
1387
|
+
onCreateComponent: (
|
|
1388
|
+
component: SchemaComponent,
|
|
1389
|
+
) => SchemaComponent | undefined;
|
|
1388
1390
|
/** calls before parse any kind of schema */
|
|
1389
1391
|
onPreParseSchema: (
|
|
1390
|
-
originalSchema:
|
|
1392
|
+
originalSchema: unknown,
|
|
1391
1393
|
typeName: string,
|
|
1392
1394
|
schemaType: string,
|
|
1393
|
-
) =>
|
|
1395
|
+
) => undefined;
|
|
1394
1396
|
/** calls after parse any kind of schema */
|
|
1395
|
-
onParseSchema: (
|
|
1397
|
+
onParseSchema: (
|
|
1398
|
+
originalSchema: unknown,
|
|
1399
|
+
parsedSchema: unknown,
|
|
1400
|
+
) => unknown | undefined;
|
|
1396
1401
|
/** calls after parse route (return type: customized route (ParsedRoute), nothing change (void), false (ignore this route)) */
|
|
1397
|
-
onCreateRoute: (routeData: ParsedRoute) => ParsedRoute |
|
|
1402
|
+
onCreateRoute: (routeData: ParsedRoute) => ParsedRoute | false | undefined;
|
|
1398
1403
|
/** Start point of work this tool (after fetching schema) */
|
|
1399
1404
|
onInit?: <C extends GenerateApiConfiguration["config"]>(
|
|
1400
1405
|
configuration: C,
|
|
1401
1406
|
codeGenProcess: CodeGenProcess,
|
|
1402
|
-
) => C |
|
|
1407
|
+
) => C | undefined;
|
|
1403
1408
|
/** customize configuration object before sending it to ETA templates */
|
|
1404
1409
|
onPrepareConfig?: <C extends GenerateApiConfiguration>(
|
|
1405
1410
|
currentConfiguration: C,
|
|
1406
|
-
) => C |
|
|
1411
|
+
) => C | undefined;
|
|
1407
1412
|
/** customize route name as you need */
|
|
1408
1413
|
onCreateRouteName?: (
|
|
1409
1414
|
routeNameInfo: RouteNameInfo,
|
|
1410
1415
|
rawRouteInfo: RawRouteInfo,
|
|
1411
|
-
) => RouteNameInfo |
|
|
1416
|
+
) => RouteNameInfo | undefined;
|
|
1412
1417
|
/** customize request params (path params, query params) */
|
|
1413
1418
|
onCreateRequestParams?: (
|
|
1414
1419
|
rawType: SchemaComponent["rawTypeData"],
|
|
1415
|
-
) => SchemaComponent["rawTypeData"] |
|
|
1420
|
+
) => SchemaComponent["rawTypeData"] | undefined;
|
|
1416
1421
|
/** customize name of model type */
|
|
1417
1422
|
onFormatTypeName?: (
|
|
1418
1423
|
typeName: string,
|
|
1419
1424
|
rawTypeName?: string,
|
|
1420
1425
|
schemaType?: "type-name" | "enum-key",
|
|
1421
|
-
) => string |
|
|
1426
|
+
) => string | undefined;
|
|
1422
1427
|
/** customize name of route (operationId), you can do it with using onCreateRouteName too */
|
|
1423
1428
|
onFormatRouteName?: (
|
|
1424
1429
|
routeInfo: RawRouteInfo,
|
|
1425
1430
|
templateRouteName: string,
|
|
1426
|
-
) => string |
|
|
1431
|
+
) => string | undefined;
|
|
1427
1432
|
}
|
|
1428
1433
|
|
|
1429
|
-
type RouteNameRouteInfo =
|
|
1434
|
+
type RouteNameRouteInfo = Record<unknown, unknown>;
|
|
1430
1435
|
|
|
1431
1436
|
type RouteNameInfo = {
|
|
1432
1437
|
usage: string;
|
|
@@ -1439,7 +1444,7 @@ type SchemaTypePrimitiveContent = {
|
|
|
1439
1444
|
schemaType: string;
|
|
1440
1445
|
type: string;
|
|
1441
1446
|
typeIdentifier: string;
|
|
1442
|
-
name?:
|
|
1447
|
+
name?: unknown;
|
|
1443
1448
|
description: string;
|
|
1444
1449
|
content: string;
|
|
1445
1450
|
};
|
|
@@ -1625,7 +1630,7 @@ interface GenerateApiConfiguration {
|
|
|
1625
1630
|
input: string;
|
|
1626
1631
|
output: string;
|
|
1627
1632
|
url: string;
|
|
1628
|
-
spec:
|
|
1633
|
+
spec: unknown;
|
|
1629
1634
|
fileName: string;
|
|
1630
1635
|
templatePaths: {
|
|
1631
1636
|
/** `templates/base` */
|
|
@@ -1682,7 +1687,7 @@ interface GenerateApiConfiguration {
|
|
|
1682
1687
|
hooks: Hooks;
|
|
1683
1688
|
enumNamesAsValues: boolean;
|
|
1684
1689
|
version: string;
|
|
1685
|
-
compilerTsConfig: Record<string,
|
|
1690
|
+
compilerTsConfig: Record<string, unknown>;
|
|
1686
1691
|
enumKeyResolverName: string;
|
|
1687
1692
|
typeNameResolverName: string;
|
|
1688
1693
|
specificArgNameResolverName: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -1216,7 +1216,7 @@ interface GenerateApiParamsBase {
|
|
|
1216
1216
|
requestOptions?: null | Partial<RequestInit>;
|
|
1217
1217
|
|
|
1218
1218
|
/** ts compiler configuration object (for --to-js option) */
|
|
1219
|
-
compilerTsConfig?: Record<string,
|
|
1219
|
+
compilerTsConfig?: Record<string, unknown>;
|
|
1220
1220
|
|
|
1221
1221
|
/**
|
|
1222
1222
|
* custom ts->* translator
|
|
@@ -1289,28 +1289,28 @@ type CodeGenConstruct = {
|
|
|
1289
1289
|
CodeGenKeyword: {
|
|
1290
1290
|
UtilRequiredKeys: string;
|
|
1291
1291
|
};
|
|
1292
|
-
ArrayType: (content:
|
|
1293
|
-
StringValue: (content:
|
|
1294
|
-
BooleanValue: (content:
|
|
1295
|
-
NumberValue: (content:
|
|
1296
|
-
NullValue: (content:
|
|
1297
|
-
UnionType: (content:
|
|
1298
|
-
ExpressionGroup: (content:
|
|
1299
|
-
IntersectionType: (content:
|
|
1300
|
-
RecordType: (content:
|
|
1301
|
-
TypeField: (content:
|
|
1302
|
-
InterfaceDynamicField: (content:
|
|
1303
|
-
EnumField: (content:
|
|
1304
|
-
EnumFieldsWrapper: (content:
|
|
1305
|
-
ObjectWrapper: (content:
|
|
1306
|
-
MultilineComment: (content:
|
|
1307
|
-
TypeWithGeneric: (content:
|
|
1292
|
+
ArrayType: (content: unknown) => string;
|
|
1293
|
+
StringValue: (content: unknown) => string;
|
|
1294
|
+
BooleanValue: (content: unknown) => string;
|
|
1295
|
+
NumberValue: (content: unknown) => string;
|
|
1296
|
+
NullValue: (content: unknown) => string;
|
|
1297
|
+
UnionType: (content: unknown) => string;
|
|
1298
|
+
ExpressionGroup: (content: unknown) => string;
|
|
1299
|
+
IntersectionType: (content: unknown) => string;
|
|
1300
|
+
RecordType: (content: unknown) => string;
|
|
1301
|
+
TypeField: (content: unknown) => string;
|
|
1302
|
+
InterfaceDynamicField: (content: unknown) => string;
|
|
1303
|
+
EnumField: (content: unknown) => string;
|
|
1304
|
+
EnumFieldsWrapper: (content: unknown) => string;
|
|
1305
|
+
ObjectWrapper: (content: unknown) => string;
|
|
1306
|
+
MultilineComment: (content: unknown) => string;
|
|
1307
|
+
TypeWithGeneric: (content: unknown) => string;
|
|
1308
1308
|
};
|
|
1309
1309
|
|
|
1310
1310
|
type PrimitiveTypeStructValue =
|
|
1311
1311
|
| string
|
|
1312
1312
|
| ((
|
|
1313
|
-
schema: Record<string,
|
|
1313
|
+
schema: Record<string, unknown>,
|
|
1314
1314
|
parser: SchemaParser,
|
|
1315
1315
|
) => string);
|
|
1316
1316
|
|
|
@@ -1373,60 +1373,65 @@ type BuildRoutePath = {
|
|
|
1373
1373
|
|
|
1374
1374
|
interface Hooks {
|
|
1375
1375
|
/** calls before parse\process route path */
|
|
1376
|
-
onPreBuildRoutePath: (routePath: string) => string |
|
|
1376
|
+
onPreBuildRoutePath: (routePath: string) => string | undefined;
|
|
1377
1377
|
/** calls after parse\process route path */
|
|
1378
|
-
onBuildRoutePath: (data: BuildRoutePath) => BuildRoutePath |
|
|
1378
|
+
onBuildRoutePath: (data: BuildRoutePath) => BuildRoutePath | undefined;
|
|
1379
1379
|
/** calls before insert path param name into string path interpolation */
|
|
1380
1380
|
onInsertPathParam: (
|
|
1381
1381
|
paramName: string,
|
|
1382
1382
|
index: number,
|
|
1383
1383
|
arr: BuildRouteParam[],
|
|
1384
1384
|
resultRoute: string,
|
|
1385
|
-
) => string |
|
|
1385
|
+
) => string | undefined;
|
|
1386
1386
|
/** calls after parse schema component */
|
|
1387
|
-
onCreateComponent: (
|
|
1387
|
+
onCreateComponent: (
|
|
1388
|
+
component: SchemaComponent,
|
|
1389
|
+
) => SchemaComponent | undefined;
|
|
1388
1390
|
/** calls before parse any kind of schema */
|
|
1389
1391
|
onPreParseSchema: (
|
|
1390
|
-
originalSchema:
|
|
1392
|
+
originalSchema: unknown,
|
|
1391
1393
|
typeName: string,
|
|
1392
1394
|
schemaType: string,
|
|
1393
|
-
) =>
|
|
1395
|
+
) => undefined;
|
|
1394
1396
|
/** calls after parse any kind of schema */
|
|
1395
|
-
onParseSchema: (
|
|
1397
|
+
onParseSchema: (
|
|
1398
|
+
originalSchema: unknown,
|
|
1399
|
+
parsedSchema: unknown,
|
|
1400
|
+
) => unknown | undefined;
|
|
1396
1401
|
/** calls after parse route (return type: customized route (ParsedRoute), nothing change (void), false (ignore this route)) */
|
|
1397
|
-
onCreateRoute: (routeData: ParsedRoute) => ParsedRoute |
|
|
1402
|
+
onCreateRoute: (routeData: ParsedRoute) => ParsedRoute | false | undefined;
|
|
1398
1403
|
/** Start point of work this tool (after fetching schema) */
|
|
1399
1404
|
onInit?: <C extends GenerateApiConfiguration["config"]>(
|
|
1400
1405
|
configuration: C,
|
|
1401
1406
|
codeGenProcess: CodeGenProcess,
|
|
1402
|
-
) => C |
|
|
1407
|
+
) => C | undefined;
|
|
1403
1408
|
/** customize configuration object before sending it to ETA templates */
|
|
1404
1409
|
onPrepareConfig?: <C extends GenerateApiConfiguration>(
|
|
1405
1410
|
currentConfiguration: C,
|
|
1406
|
-
) => C |
|
|
1411
|
+
) => C | undefined;
|
|
1407
1412
|
/** customize route name as you need */
|
|
1408
1413
|
onCreateRouteName?: (
|
|
1409
1414
|
routeNameInfo: RouteNameInfo,
|
|
1410
1415
|
rawRouteInfo: RawRouteInfo,
|
|
1411
|
-
) => RouteNameInfo |
|
|
1416
|
+
) => RouteNameInfo | undefined;
|
|
1412
1417
|
/** customize request params (path params, query params) */
|
|
1413
1418
|
onCreateRequestParams?: (
|
|
1414
1419
|
rawType: SchemaComponent["rawTypeData"],
|
|
1415
|
-
) => SchemaComponent["rawTypeData"] |
|
|
1420
|
+
) => SchemaComponent["rawTypeData"] | undefined;
|
|
1416
1421
|
/** customize name of model type */
|
|
1417
1422
|
onFormatTypeName?: (
|
|
1418
1423
|
typeName: string,
|
|
1419
1424
|
rawTypeName?: string,
|
|
1420
1425
|
schemaType?: "type-name" | "enum-key",
|
|
1421
|
-
) => string |
|
|
1426
|
+
) => string | undefined;
|
|
1422
1427
|
/** customize name of route (operationId), you can do it with using onCreateRouteName too */
|
|
1423
1428
|
onFormatRouteName?: (
|
|
1424
1429
|
routeInfo: RawRouteInfo,
|
|
1425
1430
|
templateRouteName: string,
|
|
1426
|
-
) => string |
|
|
1431
|
+
) => string | undefined;
|
|
1427
1432
|
}
|
|
1428
1433
|
|
|
1429
|
-
type RouteNameRouteInfo =
|
|
1434
|
+
type RouteNameRouteInfo = Record<unknown, unknown>;
|
|
1430
1435
|
|
|
1431
1436
|
type RouteNameInfo = {
|
|
1432
1437
|
usage: string;
|
|
@@ -1439,7 +1444,7 @@ type SchemaTypePrimitiveContent = {
|
|
|
1439
1444
|
schemaType: string;
|
|
1440
1445
|
type: string;
|
|
1441
1446
|
typeIdentifier: string;
|
|
1442
|
-
name?:
|
|
1447
|
+
name?: unknown;
|
|
1443
1448
|
description: string;
|
|
1444
1449
|
content: string;
|
|
1445
1450
|
};
|
|
@@ -1625,7 +1630,7 @@ interface GenerateApiConfiguration {
|
|
|
1625
1630
|
input: string;
|
|
1626
1631
|
output: string;
|
|
1627
1632
|
url: string;
|
|
1628
|
-
spec:
|
|
1633
|
+
spec: unknown;
|
|
1629
1634
|
fileName: string;
|
|
1630
1635
|
templatePaths: {
|
|
1631
1636
|
/** `templates/base` */
|
|
@@ -1682,7 +1687,7 @@ interface GenerateApiConfiguration {
|
|
|
1682
1687
|
hooks: Hooks;
|
|
1683
1688
|
enumNamesAsValues: boolean;
|
|
1684
1689
|
version: string;
|
|
1685
|
-
compilerTsConfig: Record<string,
|
|
1690
|
+
compilerTsConfig: Record<string, unknown>;
|
|
1686
1691
|
enumKeyResolverName: string;
|
|
1687
1692
|
typeNameResolverName: string;
|
|
1688
1693
|
specificArgNameResolverName: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swagger-typescript-api",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.15",
|
|
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",
|
|
@@ -34,16 +34,6 @@
|
|
|
34
34
|
"dist",
|
|
35
35
|
"templates"
|
|
36
36
|
],
|
|
37
|
-
"scripts": {
|
|
38
|
-
"build": "tsup",
|
|
39
|
-
"ci": "biome ci .",
|
|
40
|
-
"cli:help": "node index.js -h",
|
|
41
|
-
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
|
|
42
|
-
"cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
|
|
43
|
-
"format": "biome format --write .",
|
|
44
|
-
"format:check": "biome format .",
|
|
45
|
-
"test": "vitest run"
|
|
46
|
-
},
|
|
47
37
|
"dependencies": {
|
|
48
38
|
"@types/swagger-schema-official": "^2.0.25",
|
|
49
39
|
"cosmiconfig": "^9.0.0",
|
|
@@ -65,19 +55,29 @@
|
|
|
65
55
|
"@types/didyoumean": "1.2.2",
|
|
66
56
|
"@types/js-yaml": "4.0.9",
|
|
67
57
|
"@types/lodash": "4.17.7",
|
|
68
|
-
"@types/node": "22.0.
|
|
58
|
+
"@types/node": "22.0.2",
|
|
69
59
|
"@types/swagger2openapi": "7.0.4",
|
|
70
60
|
"axios": "1.7.2",
|
|
71
61
|
"shx": "0.3.4",
|
|
72
62
|
"tsup": "8.2.3",
|
|
73
|
-
"vitest": "2.0.
|
|
63
|
+
"vitest": "2.0.5"
|
|
74
64
|
},
|
|
75
|
-
"packageManager": "yarn@4.3.1",
|
|
76
65
|
"engines": {
|
|
77
66
|
"node": ">=18.0.0"
|
|
78
67
|
},
|
|
79
68
|
"publishConfig": {
|
|
80
69
|
"access": "public",
|
|
70
|
+
"provenance": true,
|
|
81
71
|
"registry": "https://registry.npmjs.org"
|
|
72
|
+
},
|
|
73
|
+
"scripts": {
|
|
74
|
+
"build": "tsup",
|
|
75
|
+
"cli:help": "node index.js -h",
|
|
76
|
+
"cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
|
|
77
|
+
"cli:yaml": "node index.js -r -d -p ./swagger-test-cli.yaml -n swagger-test-cli.ts",
|
|
78
|
+
"format": "biome format --write .",
|
|
79
|
+
"format:check": "biome format .",
|
|
80
|
+
"lint": "biome check",
|
|
81
|
+
"test": "vitest run"
|
|
82
82
|
}
|
|
83
83
|
}
|