@map-colonies/openapi-helpers 2.0.0 → 2.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/generator/generateTypes.mjs +0 -1
- package/dist/generator/generateTypes.mjs.map +1 -1
- package/dist/requestSender/requestSender.d.ts +3 -2
- package/dist/requestSender/requestSender.js +8 -6
- package/dist/requestSender/requestSender.js.map +1 -1
- package/dist/requestSender/types.d.ts +12 -0
- package/package.json +11 -9
|
@@ -8,7 +8,6 @@ const { values: { format: shouldFormat, 'add-typed-request-handler': addTypedReq
|
|
|
8
8
|
args: process.argv.slice(ARGS_SLICE),
|
|
9
9
|
options: {
|
|
10
10
|
format: { type: 'boolean', alias: 'f' },
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
12
11
|
'add-typed-request-handler': { type: 'boolean', alias: 't' },
|
|
13
12
|
},
|
|
14
13
|
allowPositionals: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateTypes.mjs","sourceRoot":"","sources":["../../src/generator/generateTypes.mts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,SAAS,EAAE,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE5D,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,MAAM,EACJ,MAAM,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,EACrF,WAAW,GACZ,GAAG,SAAS,CAAC;IACZ,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC;IACpC,OAAO,EAAE;QACP,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,EAAE;QACvC,
|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AAC,CAAC;AAE3F,IAAI,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;AAE/B,IAAI,sBAAsB,KAAK,IAAI,EAAE,CAAC;IACpC,OAAO,GAAG,yBAAyB,GAAG,OAAO,GAAG,0BAA0B,CAAC;AAC7E,CAAC;AAED,OAAO,GAAG,cAAc,GAAG,OAAO,CAAC;AAEnC,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;IAC1B,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAE9D,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,EAAE,EAAE,GAAG,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;AAChF,CAAC;AAED,MAAM,EAAE,CAAC,SAAS,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAE7C,OAAO,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type express from 'express';
|
|
2
2
|
import { PathsTemplate, OperationsTemplate } from '../common/types';
|
|
3
|
-
import type { RequestSender } from './types';
|
|
3
|
+
import type { RequestSender, RequestSenderOptions } from './types';
|
|
4
4
|
export { RequestSender };
|
|
5
5
|
/**
|
|
6
6
|
* Creates a request sender object that can be used to send fake HTTP requests using supertest based on an OpenAPI specification.
|
|
@@ -10,6 +10,7 @@ export { RequestSender };
|
|
|
10
10
|
* @template Operations - The type representing the operations defined in the OpenAPI specification.
|
|
11
11
|
* @param {string} openapiFilePath - The file path to the OpenAPI specification file.
|
|
12
12
|
* @param {express.Application} app - The Express application instance.
|
|
13
|
+
* @param {RequestSenderOptions} [options] - Optional configuration options for the request sender.
|
|
13
14
|
* @returns {Promise<RequestSender<Paths, Operations>>} A promise that resolves to a RequestSender object.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
@@ -33,4 +34,4 @@ export { RequestSender };
|
|
|
33
34
|
* });
|
|
34
35
|
* ```
|
|
35
36
|
*/
|
|
36
|
-
export declare function createRequestSender<Paths extends PathsTemplate = never, Operations extends OperationsTemplate = never>(openapiFilePath: Operations extends never ? never : string, app: express.Application): Promise<RequestSender<Paths, Operations>>;
|
|
37
|
+
export declare function createRequestSender<Paths extends PathsTemplate = never, Operations extends OperationsTemplate = never>(openapiFilePath: Operations extends never ? never : string, app: express.Application, options?: RequestSenderOptions): Promise<RequestSender<Paths, Operations>>;
|
|
@@ -10,9 +10,9 @@ exports.createRequestSender = createRequestSender;
|
|
|
10
10
|
const node_fs_1 = require("node:fs");
|
|
11
11
|
const supertest_1 = __importDefault(require("supertest"));
|
|
12
12
|
const oas_normalize_1 = __importDefault(require("oas-normalize"));
|
|
13
|
-
function sendRequest(app, options) {
|
|
13
|
+
function sendRequest(app, options, internalOptions = {}) {
|
|
14
14
|
const method = options.method;
|
|
15
|
-
let actualPath = options.path;
|
|
15
|
+
let actualPath = (internalOptions.baseUrl ?? '') + options.path;
|
|
16
16
|
if ('pathParams' in options && options.pathParams !== undefined) {
|
|
17
17
|
actualPath = Object.entries(options.pathParams).reduce((acc, [key, value]) => acc.replace(`{${key}}`, value), actualPath);
|
|
18
18
|
}
|
|
@@ -75,6 +75,7 @@ function getOperationsPathAndMethod(openapi) {
|
|
|
75
75
|
* @template Operations - The type representing the operations defined in the OpenAPI specification.
|
|
76
76
|
* @param {string} openapiFilePath - The file path to the OpenAPI specification file.
|
|
77
77
|
* @param {express.Application} app - The Express application instance.
|
|
78
|
+
* @param {RequestSenderOptions} [options] - Optional configuration options for the request sender.
|
|
78
79
|
* @returns {Promise<RequestSender<Paths, Operations>>} A promise that resolves to a RequestSender object.
|
|
79
80
|
*
|
|
80
81
|
* @example
|
|
@@ -98,19 +99,20 @@ function getOperationsPathAndMethod(openapi) {
|
|
|
98
99
|
* });
|
|
99
100
|
* ```
|
|
100
101
|
*/
|
|
101
|
-
async function createRequestSender(openapiFilePath, app) {
|
|
102
|
+
async function createRequestSender(openapiFilePath, app, options = {}) {
|
|
102
103
|
const fileContent = (0, node_fs_1.readFileSync)(openapiFilePath, 'utf-8');
|
|
103
104
|
const normalized = new oas_normalize_1.default(fileContent);
|
|
104
105
|
const derefed = await normalized.deref();
|
|
105
106
|
const operationsPathAndMethod = getOperationsPathAndMethod(derefed);
|
|
107
|
+
const baseOptions = options;
|
|
106
108
|
const returnObj = {
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
108
|
-
sendRequest: (options) => sendRequest(app, options),
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async, @typescript-eslint/explicit-function-return-type
|
|
110
|
+
sendRequest: (options) => sendRequest(app, options, baseOptions),
|
|
109
111
|
};
|
|
110
112
|
for (const [operation, { path, method }] of Object.entries(operationsPathAndMethod)) {
|
|
111
113
|
// @ts-expect-error as we iterate over all the operations, the operationId is always defined
|
|
112
114
|
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
113
|
-
returnObj[operation] = async (options) => sendRequest(app, { path, method: method, ...options });
|
|
115
|
+
returnObj[operation] = async (options) => sendRequest(app, { path, method: method, ...options }, baseOptions);
|
|
114
116
|
}
|
|
115
117
|
return returnObj;
|
|
116
118
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"requestSender.js","sourceRoot":"","sources":["../../src/requestSender/requestSender.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"requestSender.js","sourceRoot":"","sources":["../../src/requestSender/requestSender.ts"],"names":[],"mappings":";;;;;AAkIA,kDA0BC;AA5JD;;GAEG;AACH,qCAAuC;AACvC,0DAAkC;AAElC,kEAAyC;AAMzC,SAAS,WAAW,CAKlB,GAAwB,EACxB,OAAgD,EAChD,kBAAwC,EAAE;IAE1C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAiB,CAAC;IACzC,IAAI,UAAU,GAAG,CAAC,eAAe,CAAC,OAAO,IAAI,EAAE,CAAC,GAAI,OAAO,CAAC,IAAe,CAAC;IAE5E,IAAI,YAAY,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ACxB,UAAgC,EAAE;IAElC,MAAM,WAAW,GAAG,IAAA,sBAAY,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IAC3D,MAAM,UAAU,GAAG,IAAI,uBAAY,CAAC,WAAW,CAAC,CAAC;IACjD,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,KAAK,EAAE,CAAC;IACzC,MAAM,uBAAuB,GAAG,0BAA0B,CAAC,OAAO,CAAC,CAAC;IACpE,MAAM,WAAW,GAAG,OAAO,CAAC;IAE5B,MAAM,SAAS,GAAG;QAChB,uHAAuH;QACvH,WAAW,EAAE,CACX,OAAgD,EAChD,EAAE,CAAC,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC;KAC5C,CAAC;IAEF,KAAK,MAAM,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,EAAE,CAAC;QACpF,4FAA4F;QAC5F,4EAA4E;QAC5E,SAAS,CAAC,SAAS,CAAC,GAAG,KAAK,EAAE,OAA+D,EAAE,EAAE,CAC/F,WAAW,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAe,EAAE,GAAG,OAAO,EAAE,EAAE,WAAW,CAAC,CAAC;IACjF,CAAC;IAED,OAAO,SAA6C,CAAC;AACvD,CAAC"}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import type { OmitProperties, OptionalKeys, Prettify, RequiredKeys } from 'ts-essentials';
|
|
2
2
|
import type * as supertest from 'supertest';
|
|
3
3
|
import type { AddIfNotNever, OperationsTemplate, PathsTemplate, PickWritable } from '../common/types';
|
|
4
|
+
/**
|
|
5
|
+
* Configuration options for the request sender.
|
|
6
|
+
*
|
|
7
|
+
* @interface RequestSenderOptions
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestSenderOptions {
|
|
10
|
+
/**
|
|
11
|
+
* Base URL to prepend to all request paths.
|
|
12
|
+
* @type {string}
|
|
13
|
+
*/
|
|
14
|
+
baseUrl?: string;
|
|
15
|
+
}
|
|
4
16
|
interface Headers {
|
|
5
17
|
headers?: Record<string, string>;
|
|
6
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@map-colonies/openapi-helpers",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A package that provides utilities for working with openapi files",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./requestSender": {
|
|
@@ -61,25 +61,27 @@
|
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@commitlint/cli": "^19.6.1",
|
|
64
|
-
"@map-colonies/
|
|
64
|
+
"@map-colonies/commitlint-config": "^1.1.0",
|
|
65
|
+
"@map-colonies/eslint-config": "^6.0.0",
|
|
66
|
+
"@map-colonies/infra-copilot-instructions": "^1.0.0",
|
|
67
|
+
"@map-colonies/tsconfig": "^1.0.0",
|
|
68
|
+
"@swc/core": "^1.7.26",
|
|
69
|
+
"@swc/jest": "^0.2.36",
|
|
65
70
|
"@types/jest": "^29.5.12",
|
|
66
71
|
"@types/node": "^22.2.0",
|
|
67
72
|
"@types/supertest": "^6.0.2",
|
|
68
73
|
"body-parser": "^1.20.2",
|
|
69
74
|
"commitlint": "^19.6.1",
|
|
70
75
|
"cz-conventional-changelog": "^3.3.0",
|
|
71
|
-
"eslint": "^
|
|
76
|
+
"eslint": "^9.22.0",
|
|
77
|
+
"eslint-plugin-jest": "^28.11.0",
|
|
72
78
|
"expect-type": "^0.19.0",
|
|
73
79
|
"express": "^4.17.1",
|
|
74
80
|
"husky": "^9.1.7",
|
|
75
81
|
"jest": "^29.7.0",
|
|
76
82
|
"pretty-quick": "^4.0.0",
|
|
77
|
-
"
|
|
78
|
-
"@map-colonies/tsconfig": "^1.0.0",
|
|
79
|
-
"@map-colonies/infra-copilot-instructions": "^1.0.0",
|
|
80
|
-
"@map-colonies/commitlint-config": "^1.1.0",
|
|
83
|
+
"rimraf": "^6.0.1",
|
|
81
84
|
"typedoc": "^0.27.6",
|
|
82
|
-
"
|
|
83
|
-
"@swc/jest": "^0.2.36"
|
|
85
|
+
"typescript": "^5.7.3"
|
|
84
86
|
}
|
|
85
87
|
}
|