@map-colonies/openapi-helpers 3.1.0 → 5.0.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.
Files changed (38) hide show
  1. package/README.md +118 -8
  2. package/dist/cli/entrypoint.d.mts +3 -0
  3. package/dist/cli/entrypoint.d.mts.map +1 -0
  4. package/dist/cli/entrypoint.mjs +83 -0
  5. package/dist/cli/entrypoint.mjs.map +1 -0
  6. package/dist/common/constants.d.ts +3 -0
  7. package/dist/common/constants.d.ts.map +1 -0
  8. package/dist/common/constants.js +8 -0
  9. package/dist/common/constants.js.map +1 -0
  10. package/dist/common/types.d.ts +1 -0
  11. package/dist/common/types.d.ts.map +1 -0
  12. package/dist/generator/generateErrors.d.ts +10 -0
  13. package/dist/generator/generateErrors.d.ts.map +1 -0
  14. package/dist/generator/generateErrors.js +147 -0
  15. package/dist/generator/generateErrors.js.map +1 -0
  16. package/dist/generator/generateTypes.d.ts +14 -0
  17. package/dist/generator/generateTypes.d.ts.map +1 -0
  18. package/dist/generator/generateTypes.js +66 -0
  19. package/dist/generator/generateTypes.js.map +1 -0
  20. package/dist/generator/index.d.ts +3 -0
  21. package/dist/generator/index.d.ts.map +1 -0
  22. package/dist/generator/index.js +19 -0
  23. package/dist/generator/index.js.map +1 -0
  24. package/dist/requestSender/requestSender.d.ts +6 -4
  25. package/dist/requestSender/requestSender.d.ts.map +1 -0
  26. package/dist/requestSender/requestSender.js +5 -4
  27. package/dist/requestSender/requestSender.js.map +1 -1
  28. package/dist/requestSender/types.d.ts +5 -0
  29. package/dist/requestSender/types.d.ts.map +1 -0
  30. package/dist/typedRequestHandler/typedRequestHandler.d.ts +2 -0
  31. package/dist/typedRequestHandler/typedRequestHandler.d.ts.map +1 -0
  32. package/package.json +52 -58
  33. package/dist/generator/generateErrors.d.mts +0 -1
  34. package/dist/generator/generateErrors.mjs +0 -102
  35. package/dist/generator/generateErrors.mjs.map +0 -1
  36. package/dist/generator/generateTypes.d.mts +0 -2
  37. package/dist/generator/generateTypes.mjs +0 -35
  38. package/dist/generator/generateTypes.mjs.map +0 -1
package/README.md CHANGED
@@ -9,22 +9,132 @@ Run the following commands:
9
9
  npm install --save-dev @map-colonies/openapi-helpers supertest prettier openapi-typescript @types/express
10
10
  ```
11
11
 
12
- ## types-generator
13
- The package contains a script that wraps the `openapi-typescript` package and generates types for the OpenAPI schema. The script also formats the generated types using `prettier`.
14
12
 
15
- The command structure is as follows:
13
+ ## CLI Usage
14
+
15
+ The package provides a unified CLI for generating TypeScript types and error classes from OpenAPI specifications. All code generation is now performed using the `generate` command, which supports subcommands for types and errors.
16
+
17
+ #### CLI Arguments Reference
18
+
19
+ **Positional Arguments:**
20
+ For both `generate types` and `generate errors` commands, the positional arguments are:
21
+
22
+ - `<openapi-file>`: Path to the OpenAPI YAML or JSON file to use as the source schema.
23
+ - `<output-file>`: Path to the file where the generated code will be written.
24
+
25
+ These arguments are required and must be provided in the order shown.
26
+
27
+ **Optional Arguments:**
28
+
29
+ For `generate types`:
30
+ - `-f, --format`: Format the generated types using Prettier
31
+ - `-t, --add-typed-request-handler`: Add the TypedRequestHandler type to the generated types
32
+
33
+ For `generate errors`:
34
+ - `-f, --format`: Format the generated code using Prettier
35
+ - `-e, --errors-output <all|map|classes>`: Specify what to generate (default: all)
36
+ - `all`: generate both error classes and error code mapping
37
+ - `map`: generate only the error code mapping
38
+ - `classes`: generate only the error classes
39
+
40
+ ### Generate Types
41
+
42
+ Generate TypeScript types from an OpenAPI schema:
16
43
  ```bash
17
- npx @map-colonies/openapi-helpers <input-file> <output-file> --format --add-typed-request-handler
44
+ npx @map-colonies/openapi-helpers generate types <openapi-file> <output-file> [options]
18
45
  ```
19
46
 
20
47
  For example:
21
48
  ```bash
22
- npx @map-colonies/openapi-helpers ./openapi3.yaml ./src/openapi.d.ts --format --add-typed-request-handler
49
+ npx @map-colonies/openapi-helpers generate types ./openapi3.yaml ./src/openapi.d.ts --format --add-typed-request-handler
50
+ ```
51
+
52
+ Options:
53
+ - `-f, --format` - Format the generated types using `prettier`.
54
+ - `-t, --add-typed-request-handler` - Add the `TypedRequestHandler` type to the generated types.
55
+
56
+ ### Generate Errors
57
+
58
+ Generate error classes and error code mappings from an OpenAPI schema:
59
+ ```bash
60
+ npx @map-colonies/openapi-helpers generate errors <openapi-file> <output-file> [options]
61
+ ```
62
+
63
+ For example:
64
+ ```bash
65
+ npx @map-colonies/openapi-helpers generate errors ./openapi3.yaml ./src/errors.ts --format
66
+ ```
67
+
68
+
69
+ Options:
70
+ - `-f, --format` - Format the generated code using `prettier`.
71
+ - `-e, --errors-output <all|map|classes>` - Specify what to generate:
72
+ - `all` (default): generate both error classes and error code mapping
73
+ - `map`: generate only the error code mapping
74
+ - `classes`: generate only the error classes
75
+
76
+ ### Help and Examples
77
+
78
+ To see all available commands and options:
79
+ ```bash
80
+ npx @map-colonies/openapi-helpers --help
81
+ npx @map-colonies/openapi-helpers generate --help
82
+ npx @map-colonies/openapi-helpers generate types --help
83
+ npx @map-colonies/openapi-helpers generate errors --help
84
+ ```
85
+
86
+
87
+ #### Example: Run all generations
88
+
89
+ You can run both types and errors generation in sequence:
90
+ ```bash
91
+ npx @map-colonies/openapi-helpers generate types ./openapi3.yaml ./src/openapi.d.ts --format --add-typed-request-handler
92
+ npx @map-colonies/openapi-helpers generate errors ./openapi3.yaml ./src/errors.ts --format --errors-output all
93
+ ```
94
+
95
+
96
+
97
+ ## Programmatic Support
98
+
99
+
100
+ > [!NOTE]
101
+ > **Programmatic usage of the CLI (importing and using the generators directly) is only supported in ECMAScript modules (ESM).** CommonJS is not supported for direct imports.
102
+
103
+ The code generators (`generateTypes.mts` and `generateErrors.mts`) now support functional programming patterns. You can inject custom transformation logic or AST manipulation by providing functional arguments, making the generators more flexible and composable for advanced use cases.
104
+
105
+
106
+ ### API Usage
107
+
108
+ You can import and use the generators directly in your own scripts for full functional programming flexibility:
109
+
110
+ ```typescript
111
+ import { generateTypes, generateErrors } from '@map-colonies/openapi-helpers/generators';
112
+
113
+ // Generate types
114
+ await generateTypes(
115
+ 'openapi3.yaml',
116
+ 'src/openapi.d.ts',
117
+ {
118
+ shouldFormat: true,
119
+ addTypedRequestHandler: true,
120
+ // inject?: string,
121
+ // transform?: (schemaObject, metadata) => ...
122
+ }
123
+ );
124
+
125
+ // Generate errors
126
+ await generateErrors(
127
+ 'openapi3.yaml',
128
+ 'src/errors.ts',
129
+ {
130
+ shouldFormat: true,
131
+ includeMapping: true,
132
+ includeErrorClasses: true
133
+ }
134
+ );
23
135
  ```
24
136
 
25
- ### options
26
- - `--format` - format the generated types using `prettier`.
27
- - `--add-typed-request-handler` - add the `TypedRequestHandler` type to the generated types.
137
+ You can pass custom `inject` or `transform` functions to `generateTypes` for advanced AST/code manipulation, enabling highly composable and functional workflows.
28
138
 
29
139
  ## TypedRequestHandler
30
140
  The package contains a wrapper for the `express` types package that provides autocomplete for all the request handlers to the API based on the OpenAPI schema. The TypedRequestHandler is initialized with the types generated by `openapi-typescript`, and is configured based on operation name or method and path.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=entrypoint.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint.d.mts","sourceRoot":"","sources":["../../src/cli/entrypoint.mts"],"names":[],"mappings":""}
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env node
2
+ import { setTimeout as sleep } from 'node:timers/promises';
3
+ import { program } from '@commander-js/extra-typings';
4
+ import { generateTypes } from '../generator/generateTypes.js';
5
+ import { generateErrors } from '../generator/generateErrors.js';
6
+ import ora from 'ora';
7
+ import { PACKAGE_VERSION } from '../common/constants.js';
8
+ const errorOutput = ['all', 'map', 'classes'];
9
+ function isErrorsOutput(value) {
10
+ return errorOutput.includes(value);
11
+ }
12
+ const SECOND = 1000;
13
+ program.name('openapi-helpers').description('Generate TypeScript types and error classes from OpenAPI specifications').version(PACKAGE_VERSION);
14
+ const command = program.command('generate').description('Generate code artifacts (types, error classes) from OpenAPI specifications');
15
+ command
16
+ .command('types')
17
+ .description('Generate TypeScript types from OpenAPI spec')
18
+ .argument('<openapiPath>', 'Path to the OpenAPI specification file')
19
+ .argument('<destinationPath>', 'Path where the generated types will be saved')
20
+ .option('-f, --format', 'Format the generated code using Prettier')
21
+ .option('-t, --add-typed-request-handler', 'Add typed request handler types to the generated output')
22
+ .action(async (openapiPath, destinationPath, options) => {
23
+ try {
24
+ const spinner = ora('Generating types').start();
25
+ await generateTypes(openapiPath, destinationPath, { shouldFormat: options.format, addTypedRequestHandler: options.addTypedRequestHandler });
26
+ await sleep(SECOND);
27
+ spinner.stop();
28
+ console.log('Types generated successfully');
29
+ }
30
+ catch (error) {
31
+ console.error('Error generating types:', error);
32
+ process.exit(1);
33
+ }
34
+ });
35
+ command
36
+ .command('errors')
37
+ .description('Generate error classes from OpenAPI spec')
38
+ .argument('<openapiPath>', 'Path to the OpenAPI specification file')
39
+ .argument('<destinationPath>', 'Path where the generated error classes will be saved')
40
+ .option('-f, --format', 'Format the generated code using Prettier')
41
+ .option('-e, --errors-output <all|map|classes>', 'Specify the errors output type', 'all')
42
+ .action(async (openapiPath, destinationPath, options) => {
43
+ try {
44
+ if (!isErrorsOutput(options.errorsOutput)) {
45
+ console.error(`Invalid errors output type: ${options.errorsOutput}`);
46
+ process.exit(1);
47
+ }
48
+ const includeMapping = options.errorsOutput === 'map' || options.errorsOutput === 'all';
49
+ const includeErrorClasses = options.errorsOutput === 'classes' || options.errorsOutput === 'all';
50
+ const spinner = ora('Generating errors').start();
51
+ await generateErrors(openapiPath, destinationPath, {
52
+ shouldFormat: options.format,
53
+ includeMapping,
54
+ includeErrorClasses,
55
+ });
56
+ await sleep(SECOND);
57
+ spinner.stop();
58
+ console.log('Errors generated successfully');
59
+ }
60
+ catch (error) {
61
+ console.error('Error generating errors:', error);
62
+ process.exit(1);
63
+ }
64
+ });
65
+ // Add examples to the help
66
+ program.addHelpText('after', `
67
+ Examples:
68
+ $ openapi-helpers generate types api.yaml types.ts
69
+ $ openapi-helpers generate types api.yaml types.ts --format
70
+ $ openapi-helpers generate types api.yaml types.ts --add-typed-request-handler
71
+ $ openapi-helpers generate types api.yaml types.ts --add-typed-request-handler --format
72
+ $ openapi-helpers generate errors api.yaml errors.ts
73
+ $ openapi-helpers generate errors api.yaml errors.ts --format
74
+ $ openapi-helpers generate errors api.yaml errors.ts --no-mapping
75
+ $ openapi-helpers generate errors api.yaml errors.ts --no-error-classes
76
+ $ openapi-helpers generate errors api.yaml errors.ts --no-mapping --no-error-classes
77
+ $ openapi-helpers --help
78
+ $ openapi-helpers generate --help
79
+ $ openapi-helpers generate types --help
80
+ $ openapi-helpers generate errors --help
81
+ `);
82
+ program.parse();
83
+ //# sourceMappingURL=entrypoint.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entrypoint.mjs","sourceRoot":"","sources":["../../src/cli/entrypoint.mts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,WAAW,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,CAAU,CAAC;AAGvD,SAAS,cAAc,CAAC,KAAa;IACnC,OAAO,WAAW,CAAC,QAAQ,CAAC,KAAqB,CAAC,CAAC;AACrD,CAAC;AAED,MAAM,MAAM,GAAG,IAAI,CAAC;AACpB,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,WAAW,CAAC,yEAAyE,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;AAEhJ,MAAM,OAAO,GAAG,OAAO,CAAC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,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":"AAGA,QAAA,MAAM,eAAe,QAAmC,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PACKAGE_VERSION = void 0;
4
+ const read_pkg_1 = require("@map-colonies/read-pkg");
5
+ const packageJson = (0, read_pkg_1.readPackageJsonSync)();
6
+ const PACKAGE_VERSION = packageJson.version ?? 'unknown';
7
+ exports.PACKAGE_VERSION = PACKAGE_VERSION;
8
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/common/constants.ts"],"names":[],"mappings":";;;AAAA,qDAA6D;AAE7D,MAAM,WAAW,GAAG,IAAA,8BAAmB,GAAE,CAAC;AAC1C,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC;AAChD,0CAAe"}
@@ -13,3 +13,4 @@ export type PathsTemplate = Record<string, {
13
13
  } & {
14
14
  [key in Methods]?: OperationsTemplate;
15
15
  }>;
16
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAClE,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,WAAW,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpF,MAAM,MAAM,OAAO,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAEjG,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG,MAAM,CAChC,MAAM,EACN;IACE,UAAU,EAAE;QACV,KAAK,CAAC,EAAE,GAAG,CAAC;QACZ,MAAM,CAAC,EAAE,GAAG,CAAC;QACb,IAAI,CAAC,EAAE,GAAG,CAAC;QACX,MAAM,CAAC,EAAE,GAAG,CAAC;KACd,CAAC;CACH,GAAG;KACD,GAAG,IAAI,OAAO,CAAC,CAAC,EAAE,kBAAkB;CACtC,CACF,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Generates TypeScript error classes and an optional error mapping from an OpenAPI specification file and writes them to the specified destination path.
3
+ * @public
4
+ */
5
+ export declare function generateErrors(openapiPath: string, destinationPath: string, options: {
6
+ shouldFormat?: boolean;
7
+ includeMapping?: boolean;
8
+ includeErrorClasses?: boolean;
9
+ }): Promise<void>;
10
+ //# sourceMappingURL=generateErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateErrors.d.ts","sourceRoot":"","sources":["../../src/generator/generateErrors.ts"],"names":[],"mappings":"AAsCA;;;GAGG;AACH,wBAAsB,cAAc,CAClC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE;IACP,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B,GACA,OAAO,CAAC,IAAI,CAAC,CAuFf"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.generateErrors = generateErrors;
40
+ const promises_1 = __importDefault(require("node:fs/promises"));
41
+ const node_path_1 = __importDefault(require("node:path"));
42
+ const json_schema_ref_parser_1 = require("@apidevtools/json-schema-ref-parser");
43
+ const prettier_1 = require("prettier");
44
+ const changeCase = __importStar(require("change-case"));
45
+ const ESLINT_DISABLE = '/* eslint-disable */\n';
46
+ const FILE_HEADER = `${ESLINT_DISABLE}// This file was auto-generated. Do not edit manually.
47
+ // To update, run the error generation script again.\n\n`;
48
+ function createError(code) {
49
+ let className = changeCase.pascalCase(code);
50
+ if (!className.endsWith('Error')) {
51
+ className += 'Error';
52
+ }
53
+ return `export class ${className} extends Error {
54
+ public readonly code = '${code}';
55
+ /**
56
+ * Creates an instance of ${className}.
57
+ * @param message - The error message.
58
+ * @param cause - Optional original error or server response data.
59
+ */
60
+ public constructor(message: string, cause?: unknown) {
61
+ super(message, { cause });
62
+ Object.setPrototypeOf(this, new.target.prototype);
63
+ }
64
+ };\n`;
65
+ }
66
+ function buildErrorMapping(errorCodes) {
67
+ return Array.from(errorCodes)
68
+ .map((code) => `'${code}': '${code}'`)
69
+ .join(', ');
70
+ }
71
+ /**
72
+ * Generates TypeScript error classes and an optional error mapping from an OpenAPI specification file and writes them to the specified destination path.
73
+ * @public
74
+ */
75
+ async function generateErrors(openapiPath, destinationPath, options) {
76
+ const openapi = await (0, json_schema_ref_parser_1.dereference)(openapiPath);
77
+ if (openapi.paths === undefined) {
78
+ console.error('No paths found in the OpenAPI document.');
79
+ process.exit(1);
80
+ }
81
+ const errorCodes = new Set();
82
+ function extractCodeFromSchema(schema) {
83
+ // Handle direct code property
84
+ if (schema.type === 'object' && schema.properties?.code) {
85
+ const codeProperty = schema.properties.code;
86
+ // Handle enum values
87
+ if (codeProperty.enum) {
88
+ codeProperty.enum.map(String).forEach((code) => {
89
+ errorCodes.add(code);
90
+ });
91
+ }
92
+ }
93
+ // Handle allOf combinations
94
+ if (schema.allOf) {
95
+ for (const subSchema of schema.allOf) {
96
+ extractCodeFromSchema(subSchema);
97
+ }
98
+ }
99
+ // Handle oneOf combinations
100
+ if (schema.oneOf) {
101
+ for (const subSchema of schema.oneOf) {
102
+ extractCodeFromSchema(subSchema);
103
+ }
104
+ }
105
+ // Handle anyOf combinations
106
+ if (schema.anyOf) {
107
+ for (const subSchema of schema.anyOf) {
108
+ extractCodeFromSchema(subSchema);
109
+ }
110
+ }
111
+ }
112
+ for (const [, methods] of Object.entries(openapi.paths)) {
113
+ for (const [key, operation] of Object.entries(methods)) {
114
+ if (['servers', 'parameters'].includes(key)) {
115
+ continue;
116
+ }
117
+ for (const [statusCode, response] of Object.entries(operation.responses ?? {})) {
118
+ if (statusCode.startsWith('2') || statusCode.startsWith('3')) {
119
+ continue; // Skip successful and redirection responses
120
+ }
121
+ const schema = response.content?.['application/json']?.schema;
122
+ if (schema) {
123
+ extractCodeFromSchema(schema);
124
+ }
125
+ }
126
+ }
127
+ }
128
+ if (errorCodes.size === 0) {
129
+ console.warn('No error codes found in the OpenAPI document.');
130
+ process.exit(0);
131
+ }
132
+ let errorFile = FILE_HEADER;
133
+ if (options.includeErrorClasses === true) {
134
+ errorFile += errorCodes.values().map(createError).toArray().join('\n');
135
+ }
136
+ if (options.includeMapping === true) {
137
+ errorFile += ` export const API_ERRORS_MAP = { ${buildErrorMapping(errorCodes)} } as const;\n`;
138
+ }
139
+ if (options.shouldFormat === true) {
140
+ const prettierOptions = await (0, prettier_1.resolveConfig)('./src/index.ts');
141
+ errorFile = await (0, prettier_1.format)(errorFile, { ...prettierOptions, parser: 'typescript' });
142
+ }
143
+ const directory = node_path_1.default.dirname(destinationPath);
144
+ await promises_1.default.mkdir(directory, { recursive: true });
145
+ await promises_1.default.writeFile(destinationPath, errorFile);
146
+ }
147
+ //# sourceMappingURL=generateErrors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateErrors.js","sourceRoot":"","sources":["../../src/generator/generateErrors.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,wCA+FC;AAzID,gEAAkC;AAClC,0DAA6B;AAC7B,gFAAkE;AAClE,uCAAiD;AACjD,wDAA0C;AAG1C,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAChD,MAAM,WAAW,GAAG,GAAG,cAAc;yDACoB,CAAC;AAE1D,SAAS,WAAW,CAAC,IAAY;IAC/B,IAAI,SAAS,GAAG,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAE5C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QACjC,SAAS,IAAI,OAAO,CAAC;IACvB,CAAC;IAED,OAAO,gBAAg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C,IAAI,KAAK,CAAC,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC,+CAA+C,CAAC,CAAC;QAC9D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IACD,IAAI,SAAS,GAAG,WAAW,CAAC;IAE5B,IAAI,OAAO,CAAC,mBAAmB,KAAK,IAAI,EAAE,CAAC;QACzC,SAAS,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzE,CAAC;IAED,IAAI,OAAO,CAAC,cAAc,KAAK,IAAI,EAAE,CAAC;QACpC,SAAS,IAAI,oCAAoC,iBAAiB,CAAC,UAAU,CAAC,gBAAgB,CAAC;IACjG,CAAC;IAED,IAAI,OAAO,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;QAClC,MAAM,eAAe,GAAG,MAAM,IAAA,wBAAa,EAAC,gBAAgB,CAAC,CAAC;QAC9D,SAAS,GAAG,MAAM,IAAA,iBAAM,EAAC,SAAS,EAAE,EAAE,GAAG,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,MAAM,SAAS,GAAG,mBAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAChD,MAAM,kBAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE/C,MAAM,kBAAE,CAAC,SAAS,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ import { SchemaObject, TransformNodeOptions, TransformObject } from 'openapi-typescript';
3
+ import { TypeNode } from 'typescript';
4
+ /**
5
+ * Generates TypeScript types from an OpenAPI specification file and writes them to the specified destination path.
6
+ * @public
7
+ */
8
+ export declare function generateTypes(openapiPath: string, destinationPath: string, options: {
9
+ shouldFormat?: boolean;
10
+ addTypedRequestHandler?: boolean;
11
+ inject?: string;
12
+ transform?: (schemaObject: SchemaObject, metadata: TransformNodeOptions) => TypeNode | TransformObject | undefined;
13
+ }): Promise<void>;
14
+ //# sourceMappingURL=generateTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTypes.d.ts","sourceRoot":"","sources":["../../src/generator/generateTypes.ts"],"names":[],"mappings":";AAGA,OAAkB,EAAe,YAAY,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACjH,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAUtC;;;GAGG;AACH,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE;IACP,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,oBAAoB,KAAK,QAAQ,GAAG,eAAe,GAAG,SAAS,CAAC;CACpH,GACA,OAAO,CAAC,IAAI,CAAC,CAkBf"}
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ var __importDefault = (this && this.__importDefault) || function (mod) {
37
+ return (mod && mod.__esModule) ? mod : { "default": mod };
38
+ };
39
+ Object.defineProperty(exports, "__esModule", { value: true });
40
+ exports.generateTypes = generateTypes;
41
+ const promises_1 = __importDefault(require("node:fs/promises"));
42
+ const prettier_1 = require("prettier");
43
+ const openapi_typescript_1 = __importStar(require("openapi-typescript"));
44
+ const ESLINT_DISABLE = '/* eslint-disable */\n';
45
+ const FILE_HEADER = `${ESLINT_DISABLE}// This file was auto-generated. Do not edit manually.
46
+ // To update, run the error generation script again.\n\n`;
47
+ const typedRequestHandlerImport = "import type { TypedRequestHandlers as ImportedTypedRequestHandlers } from '@map-colonies/openapi-helpers/typedRequestHandler';\n";
48
+ const exportTypedRequestHandlers = 'export type TypedRequestHandlers = ImportedTypedRequestHandlers<paths, operations>;\n';
49
+ /**
50
+ * Generates TypeScript types from an OpenAPI specification file and writes them to the specified destination path.
51
+ * @public
52
+ */
53
+ async function generateTypes(openapiPath, destinationPath, options) {
54
+ const ast = await (0, openapi_typescript_1.default)(await promises_1.default.readFile(openapiPath, 'utf-8'), { exportType: true, inject: options.inject, transform: options.transform });
55
+ let content = (0, openapi_typescript_1.astToString)(ast);
56
+ if (options.addTypedRequestHandler === true) {
57
+ content = typedRequestHandlerImport + content + exportTypedRequestHandlers;
58
+ }
59
+ content = FILE_HEADER + content;
60
+ if (options.shouldFormat === true) {
61
+ const prettierOptions = await (0, prettier_1.resolveConfig)('./src/index.ts');
62
+ content = await (0, prettier_1.format)(content, { ...prettierOptions, parser: 'typescript' });
63
+ }
64
+ await promises_1.default.writeFile(destinationPath, content);
65
+ }
66
+ //# sourceMappingURL=generateTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTypes.js","sourceRoot":"","sources":["../../src/generator/generateTypes.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,sCA2BC;AA5CD,gEAAkC;AAClC,uCAAiD;AACjD,yEAAiH;AAGjH,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAChD,MAAM,WAAW,GAAG,GAAG,cAAc;yDACoB,CAAC;AAE1D,MAAM,yBAAyB,GAC7B,kIAAkI,CAAC;AACrI,MAAM,0BAA0B,GAAG,uFAAuF,CAAC;AAE3H;;;GAGG;AACI,KAAK,UAAU,aAAa,CACjC,WAAmB,EACnB,eAAuB,EACvB,OAKC;IAED,MAAM,GAAG,GAAG,MAAM,IAAA,4BAAS,EAAC,MAAM,kBAAE,CAAC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC;IAEjJ,IAAI,OAAO,GAAG,IAAA,gCAAW,EAAC,GAAG,CAAC,CAAC;IAE/B,IAAI,OAAO,CAAC,sBAAsB,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,GAAG,yBAAyB,GAAG,OAAO,GAAG,0BAA0B,CAAC;IAC7E,CAAC;IAED,OAAO,GAAG,WAAW,GAAG,OAAO,CAAC;IAEhC,IAAI,OAAO,CAAC,YAAY,KAAK,IAAI,EAAE,CAAC;QAClC,MAAM,eAAe,GAAG,MAAM,IAAA,wBAAa,EAAC,gBAAgB,CAAC,CAAC;QAE9D,OAAO,GAAG,MAAM,IAAA,iBAAM,EAAC,OAAO,EAAE,EAAE,GAAG,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC,CAAC;IAChF,CAAC;IAED,MAAM,kBAAE,CAAC,SAAS,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './generateTypes.js';
2
+ export * from './generateErrors.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./generateTypes.js"), exports);
18
+ __exportStar(require("./generateErrors.js"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generator/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,sDAAoC"}
@@ -8,10 +8,10 @@ export { RequestSender };
8
8
  *
9
9
  * @template Paths - The type representing the paths defined in the OpenAPI specification.
10
10
  * @template Operations - The type representing the operations defined in the OpenAPI specification.
11
- * @param {string} openapiFilePath - The file path to the OpenAPI specification file.
12
- * @param {express.Application} app - The Express application instance.
13
- * @param {RequestSenderOptions} [options] - Optional configuration options for the request sender.
14
- * @returns {Promise<RequestSender<Paths, Operations>>} A promise that resolves to a RequestSender object.
11
+ * @param openapiFilePath - The file path to the OpenAPI specification file.
12
+ * @param app - The Express application instance.
13
+ * @param options - Optional configuration options for the request sender.
14
+ * @returns A promise that resolves to a RequestSender object.
15
15
  *
16
16
  * @example
17
17
  * ```typescript
@@ -33,5 +33,7 @@ export { RequestSender };
33
33
  * path: '/simple-request'
34
34
  * });
35
35
  * ```
36
+ * @public
36
37
  */
37
38
  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>>;
39
+ //# sourceMappingURL=requestSender.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestSender.d.ts","sourceRoot":"","sources":["../../src/requestSender/requestSender.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAInC,OAAO,EAAE,aAAa,EAAW,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC7E,OAAO,KAAK,EAAuD,aAAa,EAAiB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAsFvI,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,SAAS,aAAa,GAAG,KAAK,EAAE,UAAU,SAAS,kBAAkB,GAAG,KAAK,EAC1H,eAAe,EAAE,UAAU,SAAS,KAAK,GAAG,KAAK,GAAG,MAAM,EAC1D,GAAG,EAAE,OAAO,CAAC,WAAW,EACxB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC,CAsB3C"}
@@ -73,10 +73,10 @@ function getOperationsPathAndMethod(openapi) {
73
73
  *
74
74
  * @template Paths - The type representing the paths defined in the OpenAPI specification.
75
75
  * @template Operations - The type representing the operations defined in the OpenAPI specification.
76
- * @param {string} openapiFilePath - The file path to the OpenAPI specification file.
77
- * @param {express.Application} app - The Express application instance.
78
- * @param {RequestSenderOptions} [options] - Optional configuration options for the request sender.
79
- * @returns {Promise<RequestSender<Paths, Operations>>} A promise that resolves to a RequestSender object.
76
+ * @param openapiFilePath - The file path to the OpenAPI specification file.
77
+ * @param app - The Express application instance.
78
+ * @param options - Optional configuration options for the request sender.
79
+ * @returns A promise that resolves to a RequestSender object.
80
80
  *
81
81
  * @example
82
82
  * ```typescript
@@ -98,6 +98,7 @@ function getOperationsPathAndMethod(openapi) {
98
98
  * path: '/simple-request'
99
99
  * });
100
100
  * ```
101
+ * @public
101
102
  */
102
103
  async function createRequestSender(openapiFilePath, app, options = {}) {
103
104
  const fileContent = (0, node_fs_1.readFileSync)(openapiFilePath, 'utf-8');
@@ -1 +1 @@
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,IAAI,OAAO,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QAChE,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,MAAM,CAAC,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AAW,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"}
@@ -86,9 +86,14 @@ export type OperationsNames<Operations extends OperationsTemplate> = keyof Opera
86
86
  type OperationRequestOptional<Operations extends OperationsTemplate, Operation extends OperationsNames<Operations>> = (options?: RequestOptions<Operations[Operation]>) => RequestReturn<Operations[Operation]>;
87
87
  type OperationRequestRequired<Operations extends OperationsTemplate, Operation extends OperationsNames<Operations>> = (options: RequestOptions<Operations[Operation]>) => RequestReturn<Operations[Operation]>;
88
88
  type SendRequest<Paths extends PathsTemplate> = <Path extends keyof Paths, Method extends keyof OmitProperties<Omit<Paths[Path], 'parameters'>, undefined>>(options: PathRequestOptions<Paths, Path, Method>) => RequestReturn<Paths[Path][Method]>;
89
+ /**
90
+ * Represents a request sender that can send requests to an Express application
91
+ * @public
92
+ */
89
93
  export type RequestSender<Paths extends PathsTemplate, Operations extends OperationsTemplate> = Prettify<{
90
94
  sendRequest: SendRequest<Paths>;
91
95
  } & {
92
96
  [operation in OperationsNames<Operations>]: RequiredKeys<RequestOptions<Operations[operation]>> extends OptionalKeys<RequestOptions<Operations[operation]>> ? OperationRequestOptional<Operations, operation> : OperationRequestRequired<Operations, operation>;
93
97
  }>;
94
98
  export {};
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/requestSender/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC1F,OAAO,KAAK,KAAK,SAAS,MAAM,WAAW,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEtG;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,OAAO;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAAE,OAAO,EAAE,GAAG,CAAA;CAAE,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,GAAG,KAAK,CAAC;AAE/F,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAAE,SAAS,EAAE,GAAG,CAAA;CAAE,CAAC,GAClE;KACG,GAAG,IAAI,MAAM,CAAC,CAAC,WAAW,CAAC,GAAG;QAAE,MAAM,EAAE,GAAG,CAAC;QAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;KAAE;CACtF,CAAC,MAAM,CA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C,KAAK,CAAC,CAAC;CACjC,GAAG;KACD,SAAS,IAAI,eAAe,CAAC,UAAU,CAAC,GAAG,YAAY,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,YAAY,CAClH,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CACtC,GACG,wBAAwB,CAAC,UAAU,EAAE,SAAS,CAAC,GAC/C,wBAAwB,CAAC,UAAU,EAAE,SAAS,CAAC;CACpD,CACF,CAAC"}
@@ -64,6 +64,8 @@ type PathHandlers<Paths extends PathsTemplate> = {
64
64
  * app.get('/example', handlers['GET /example']);
65
65
  * app.post('/exampleOperation', handlers.exampleOperation);
66
66
  * ```
67
+ * @public
67
68
  */
68
69
  export type TypedRequestHandlers<Paths extends PathsTemplate, Operations extends OperationsTemplate> = OperationHandlers<Operations> & PathHandlers<Paths>;
69
70
  export {};
71
+ //# sourceMappingURL=typedRequestHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typedRequestHandler.d.ts","sourceRoot":"","sources":["../../src/typedRequestHandler/typedRequestHandler.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAKzE,KAAK,aAAa,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,UAAU,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC,GAAG,CAAC,CAAA;KAAE,CAAA;CAAE,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AAEnH,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS;IAAE,WAAW,EAAE,GAAG,CAAA;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MAAM,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;CACrC,CAAC,MAAM,KAAK,CAAC,CAAC;AAEf,KAAK,YAAY,CAAC,KAAK,SAAS,aAAa,IAAI;KAC9C,CAAC,IAAI,uBAAuB,CAAC,KAAK,CAAC,IAAI,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,GAAG,qBAAqB,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;CAC3I,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,MAAM,oBAAoB,CAAC,KAAK,SAAS,aAAa,EAAE,UAAU,SAAS,kBAAkB,IAAI,iBAAiB,CAAC,UAAU,CAAC,GAClI,YAAY,CAAC,KAAK,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,43 +1,24 @@
1
1
  {
2
2
  "name": "@map-colonies/openapi-helpers",
3
- "version": "3.1.0",
3
+ "version": "5.0.0",
4
4
  "description": "A package that provides utilities for working with openapi files",
5
+ "type": "commonjs",
5
6
  "exports": {
6
7
  "./requestSender": {
7
- "default": "./dist/requestSender/requestSender.js",
8
- "types": "./dist/requestSender/requestSender.d.ts"
8
+ "types": "./dist/requestSender/requestSender.d.ts",
9
+ "default": "./dist/requestSender/requestSender.js"
9
10
  },
10
11
  "./typedRequestHandler": {
11
- "default": "./dist/typedRequestHandler/typedRequestHandler.js",
12
- "types": "./dist/typedRequestHandler/typedRequestHandler.d.ts"
12
+ "types": "./dist/typedRequestHandler/typedRequestHandler.d.ts",
13
+ "default": "./dist/typedRequestHandler/typedRequestHandler.js"
14
+ },
15
+ "./generators": {
16
+ "types": "./dist/generator/index.d.ts",
17
+ "default": "./dist/generator/index.js"
13
18
  }
14
19
  },
15
- "bin": "./dist/generator/generateTypes.mjs",
16
- "scripts": {
17
- "format": "prettier --check .",
18
- "format:fix": "prettier --write .",
19
- "prelint:fix": "npm run format:fix",
20
- "prelint": "npm run format",
21
- "lint": "eslint .",
22
- "lint:fix": "eslint --fix .",
23
- "test": "tsc --project tsconfig.test.json && jest --config=./tests/configurations/jest.config.js",
24
- "prebuild": "npm run clean",
25
- "build": "tsc --project tsconfig.build.json",
26
- "generate:test:types": "npm run build && node dist/generator/generateTypes.mjs tests/openapi3.yaml tests/types.d.ts",
27
- "clean": "rimraf dist",
28
- "prepublish": "npm run build",
29
- "prepare": "husky",
30
- "docs": "typedoc"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "git+https://github.com/MapColonies/openapi-helpers.git"
35
- },
36
- "author": "MapColonies",
37
- "license": "ISC",
38
- "bugs": {
39
- "url": "https://github.com/MapColonies/openapi-helpers/issues"
40
- },
20
+ "bin": "./dist/cli/entrypoint.mjs",
21
+ "repository": "github:MapColonies/infra-packages",
41
22
  "files": [
42
23
  "dist/**/*"
43
24
  ],
@@ -45,15 +26,18 @@
45
26
  "access": "public"
46
27
  },
47
28
  "engines": {
48
- "node": ">=22"
29
+ "node": ">=24"
49
30
  },
50
- "homepage": "https://github.com/MapColonies/openapi-helpers#readme",
51
31
  "dependencies": {
52
32
  "@apidevtools/json-schema-ref-parser": "^14.1.1",
33
+ "@commander-js/extra-typings": "^14.0.0",
53
34
  "change-case": "^5.4.4",
54
- "oas-normalize": "^14.1.2",
35
+ "commander": "^14.0.0",
36
+ "oas-normalize": "^15.0.0",
37
+ "ora": "^8.2.0",
55
38
  "ts-essentials": "^10.1.1",
56
- "yaml": "^2.8.0"
39
+ "yaml": "^2.8.0",
40
+ "@map-colonies/read-pkg": "^1.0.0"
57
41
  },
58
42
  "peerDependencies": {
59
43
  "@types/express": "^4.17.21",
@@ -62,27 +46,37 @@
62
46
  "supertest": "^7.0.0"
63
47
  },
64
48
  "devDependencies": {
65
- "@commitlint/cli": "^19.8.1",
66
- "@map-colonies/commitlint-config": "^1.1.1",
67
- "@map-colonies/eslint-config": "^6.0.0",
68
- "@map-colonies/infra-copilot-instructions": "^1.2.0",
69
- "@map-colonies/tsconfig": "^1.0.1",
70
- "@swc/core": "^1.13.2",
71
- "@swc/jest": "^0.2.39",
72
- "@types/jest": "^30.0.0",
73
- "@types/node": "^24.1.0",
74
- "@types/supertest": "^6.0.3",
75
- "body-parser": "^2.2.0",
76
- "commitlint": "^19.8.1",
77
- "eslint": "^9.22.0",
78
- "eslint-plugin-jest": "^28.14.0",
79
- "expect-type": "^1.2.2",
80
- "express": "^5.1.0",
81
- "husky": "^9.1.7",
82
- "jest": "^30.0.5",
83
- "pretty-quick": "^4.2.2",
84
- "rimraf": "^6.0.1",
85
- "typedoc": "^0.28.7",
86
- "typescript": "^5.8.3"
49
+ "@types/supertest": "6.0.2",
50
+ "@types/node": "24.0.0",
51
+ "@types/body-parser": "1.19.6",
52
+ "openapi-types": "12.1.3",
53
+ "body-parser": "2.2.1",
54
+ "eslint": "^9.39.1",
55
+ "express": "5.2.1",
56
+ "rimraf": "^6.1.2",
57
+ "typescript": "5.9.3",
58
+ "vitest": "^4.0.15",
59
+ "@microsoft/api-extractor": "^7.55.2",
60
+ "@map-colonies/eslint-config": "^7.0.0",
61
+ "@map-colonies/tsconfig": "^2.0.0",
62
+ "vitest-config": "^0.0.0"
63
+ },
64
+ "scripts": {
65
+ "test": "vitest run",
66
+ "lint": "eslint .",
67
+ "lint:fix": "eslint --fix .",
68
+ "prebuild": "pnpm run clean",
69
+ "build": "tsc --project tsconfig.build.json",
70
+ "clean": "rimraf dist",
71
+ "check-dist": "publint && attw --profile node16 --pack .",
72
+ "knip": "knip --directory ../.. --workspace packages/openapi-helpers",
73
+ "api:check": "pnpm run handler:api:check && pnpm run sender:api:check && pnpm run generators:api:check",
74
+ "handler:api": "api-extractor run --local --verbose --config ./api-extractor.handler.json",
75
+ "handler:api:check": "api-extractor run --verbose --config ./api-extractor.handler.json",
76
+ "sender:api": "api-extractor run --local --verbose --config ./api-extractor.sender.json",
77
+ "sender:api:check": "api-extractor run --verbose --config ./api-extractor.sender.json",
78
+ "generators:api": "api-extractor run --local --verbose --config ./api-extractor.generators.json",
79
+ "generators:api:check": "api-extractor run --verbose --config ./api-extractor.generators.json",
80
+ "generate:test:types": "pnpm run build && node dist/generator/generateTypes.mjs tests/openapi3.yaml tests/types.d.ts"
87
81
  }
88
- }
82
+ }
@@ -1 +0,0 @@
1
- export {};
@@ -1,102 +0,0 @@
1
- import fs from 'node:fs/promises';
2
- import { parseArgs } from 'node:util';
3
- import path from 'node:path';
4
- import { dereference } from '@apidevtools/json-schema-ref-parser';
5
- import { format, resolveConfig } from 'prettier';
6
- import * as changeCase from 'change-case';
7
- const ARGS_SLICE = 2;
8
- const { values: { format: shouldFormat }, positionals, } = parseArgs({
9
- args: process.argv.slice(ARGS_SLICE),
10
- options: {
11
- format: { type: 'boolean', alias: 'f' },
12
- },
13
- allowPositionals: true,
14
- });
15
- const [openapiPath, destinationPath] = positionals;
16
- if (openapiPath === undefined || destinationPath === undefined) {
17
- console.error('Usage: generateErrors <openapiPath> <destinationPath>');
18
- process.exit(1);
19
- }
20
- const openapi = await dereference(openapiPath);
21
- if (openapi.paths === undefined) {
22
- console.error('No paths found in the OpenAPI document.');
23
- process.exit(1);
24
- }
25
- const errorCodes = new Set();
26
- function extractCodeFromSchema(schema) {
27
- // Handle direct code property
28
- if (schema.type === 'object' && schema.properties?.code) {
29
- const codeProperty = schema.properties.code;
30
- // Handle enum values
31
- if (codeProperty.enum) {
32
- codeProperty.enum.map(String).forEach((code) => {
33
- errorCodes.add(code);
34
- });
35
- }
36
- }
37
- // Handle allOf combinations
38
- if (schema.allOf) {
39
- for (const subSchema of schema.allOf) {
40
- extractCodeFromSchema(subSchema);
41
- }
42
- }
43
- // Handle oneOf combinations
44
- if (schema.oneOf) {
45
- for (const subSchema of schema.oneOf) {
46
- extractCodeFromSchema(subSchema);
47
- }
48
- }
49
- // Handle anyOf combinations
50
- if (schema.anyOf) {
51
- for (const subSchema of schema.anyOf) {
52
- extractCodeFromSchema(subSchema);
53
- }
54
- }
55
- }
56
- function createError(code) {
57
- let className = changeCase.pascalCase(code);
58
- if (!className.endsWith('Error')) {
59
- className += 'Error';
60
- }
61
- return `export class ${className} extends Error {
62
- public readonly code = '${code}';
63
- /**
64
- * Creates an instance of ${className}.
65
- * @param message - The error message.
66
- * @param cause - Optional original error or server response data.
67
- */
68
- public constructor(message: string, cause?: unknown) {
69
- super(message, { cause });
70
- Object.setPrototypeOf(this, new.target.prototype);
71
- }
72
- };\n`;
73
- }
74
- for (const [, methods] of Object.entries(openapi.paths)) {
75
- for (const [key, operation] of Object.entries(methods)) {
76
- if (['servers', 'parameters'].includes(key)) {
77
- continue;
78
- }
79
- for (const [statusCode, response] of Object.entries(operation.responses ?? {})) {
80
- if (statusCode.startsWith('2') || statusCode.startsWith('3')) {
81
- continue; // Skip successful and redirection responses
82
- }
83
- const schema = response.content?.['application/json']?.schema;
84
- if (schema) {
85
- extractCodeFromSchema(schema);
86
- }
87
- }
88
- }
89
- }
90
- if (errorCodes.size === 0) {
91
- console.warn('No error codes found in the OpenAPI document.');
92
- process.exit(0);
93
- }
94
- let errorFile = errorCodes.values().map(createError).toArray().join('\n');
95
- if (shouldFormat === true) {
96
- const prettierOptions = await resolveConfig('./src/index.ts');
97
- errorFile = await format(errorFile, { ...prettierOptions, parser: 'typescript' });
98
- }
99
- const directory = path.dirname(destinationPath);
100
- await fs.mkdir(directory, { recursive: true });
101
- await fs.writeFile(destinationPath, errorFile);
102
- //# sourceMappingURL=generateErrors.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateErrors.mjs","sourceRoot":"","sources":["../../src/generator/generateErrors.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE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,MAAM,EAAE,CAAC,SAAS,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC"}
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,35 +0,0 @@
1
- #!/usr/bin/env node
2
- import fs from 'node:fs/promises';
3
- import { parseArgs } from 'node:util';
4
- import { format, resolveConfig } from 'prettier';
5
- import openapiTS, { astToString } from 'openapi-typescript';
6
- const ARGS_SLICE = 2;
7
- const { values: { format: shouldFormat, 'add-typed-request-handler': addTypedRequestHandler }, positionals, } = parseArgs({
8
- args: process.argv.slice(ARGS_SLICE),
9
- options: {
10
- format: { type: 'boolean', alias: 'f' },
11
- 'add-typed-request-handler': { type: 'boolean', alias: 't' },
12
- },
13
- allowPositionals: true,
14
- });
15
- const [openapiPath, destinationPath] = positionals;
16
- if (openapiPath === undefined || destinationPath === undefined) {
17
- console.error('Usage: generateTypes <openapiPath> <destinationPath>');
18
- process.exit(1);
19
- }
20
- const ESLINT_DISABLE = '/* eslint-disable */\n';
21
- const typedRequestHandlerImport = "import type { TypedRequestHandlers as ImportedTypedRequestHandlers } from '@map-colonies/openapi-helpers/typedRequestHandler';\n";
22
- const exportTypedRequestHandlers = 'export type TypedRequestHandlers = ImportedTypedRequestHandlers<paths, operations>;\n';
23
- const ast = await openapiTS(await fs.readFile(openapiPath, 'utf-8'), { exportType: true });
24
- let content = astToString(ast);
25
- if (addTypedRequestHandler === true) {
26
- content = typedRequestHandlerImport + content + exportTypedRequestHandlers;
27
- }
28
- content = ESLINT_DISABLE + content;
29
- if (shouldFormat === true) {
30
- const prettierOptions = await resolveConfig('./src/index.ts');
31
- content = await format(content, { ...prettierOptions, parser: 'typescript' });
32
- }
33
- await fs.writeFile(destinationPath, content);
34
- console.log('Types generated successfully');
35
- //# sourceMappingURL=generateTypes.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateTypes.mjs","sourceRoot":"","sources":["../../src/generator/generateTypes.mts"],"names":[],"mappings":";AACA,OAAO,EAAE,MA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