@sebspark/openapi-typegen 0.1.1 → 0.2.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/index.js +7 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -47,11 +47,14 @@ var header = `/**
|
|
|
47
47
|
* Do not make direct changes to the file.
|
|
48
48
|
*/
|
|
49
49
|
|
|
50
|
-
import {
|
|
50
|
+
import type {
|
|
51
51
|
APIServerDefinition,
|
|
52
52
|
BaseClient,
|
|
53
53
|
GenericRouteHandler,
|
|
54
54
|
} from '@sebspark/openapi-core'
|
|
55
|
+
import type { Request } from 'express'
|
|
56
|
+
|
|
57
|
+
type Req = Pick<Request, 'url' | 'baseUrl' | 'cookies' | 'hostname'>
|
|
55
58
|
|
|
56
59
|
/* tslint:disable */
|
|
57
60
|
/* eslint-disable */`;
|
|
@@ -259,7 +262,7 @@ ${Object.entries(map).map(
|
|
|
259
262
|
([url, methods]) => ` '${url}': {
|
|
260
263
|
${Object.entries(methods).map(
|
|
261
264
|
([method, definition]) => ` '${method}': {
|
|
262
|
-
handler: (${serializeArgs(definition.args)}) => Promise<[${definition.response.code}, ${definition.response.type}]>
|
|
265
|
+
handler: (${serializeArgs(definition.args, true)}) => Promise<[${definition.response.code}, ${definition.response.type}]>
|
|
263
266
|
pre?: GenericRouteHandler | GenericRouteHandler[]
|
|
264
267
|
}`
|
|
265
268
|
).join("\n")}
|
|
@@ -330,13 +333,13 @@ var optional = (params) => {
|
|
|
330
333
|
const anyRequired = rxRequiredParams.test(params) || !params.includes(":");
|
|
331
334
|
return anyRequired ? "" : "?";
|
|
332
335
|
};
|
|
333
|
-
var serializeArgs = (args) => {
|
|
336
|
+
var serializeArgs = (args, includeRequest = false) => {
|
|
334
337
|
if (!args)
|
|
335
338
|
return "";
|
|
336
339
|
const argsString = Object.entries(args).map(([key, value]) => {
|
|
337
340
|
return `${key}${optional(value)}: ${value}`;
|
|
338
341
|
}).join(",");
|
|
339
|
-
return `args${optional(argsString)}: {${argsString}}`;
|
|
342
|
+
return `args${optional(argsString)}: ${includeRequest ? "Req & " : ""}{${argsString}}`;
|
|
340
343
|
};
|
|
341
344
|
|
|
342
345
|
// src/openapi/parser.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sebspark/openapi-typegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"typecheck": "vitest typecheck --passWithNoTests"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"@types/yargs": "17.0.
|
|
22
|
+
"@types/yargs": "17.0.31",
|
|
23
23
|
"tsconfig": "*"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"boxen": "<6",
|
|
28
28
|
"chalk": "<5",
|
|
29
29
|
"change-case": "4.1.2",
|
|
30
|
-
"prettier": "3.0
|
|
30
|
+
"prettier": "3.1.0",
|
|
31
31
|
"yargs": "17.7.2",
|
|
32
|
-
"yarn": "1.22.
|
|
32
|
+
"yarn": "1.22.20"
|
|
33
33
|
}
|
|
34
34
|
}
|