feat!: unified CLI generating TypeScript types and error classes from OpenAPI specifications (MAPCO-8469)#49
Conversation
…OpenAPI specifications
|
🎫 Related Jira Issue: MAPCO-8469 |
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a unified command-line interface that generates TypeScript types and error classes from OpenAPI specifications, replacing separate scripts with a single CLI tool that supports both type generation and error class generation functionalities.
- Unified CLI with subcommands for
typesanderrorsgeneration - Refactored existing generators into reusable functions with enhanced configurability
- Added programmatic API support with functional programming patterns
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/cli/entrypoint.mts | New unified CLI entry point with commander.js for handling types and errors generation commands |
| src/generator/generateTypes.mts | Refactored from script to exportable function with additional parameters for inject/transform support |
| src/generator/generateErrors.mts | Refactored from script to exportable function with configurable mapping and error class generation |
| src/generator/index.mts | New barrel export file for generator functions |
| package.json | Updated bin entry point, added new dependencies, and new export path for generators |
| README.md | Updated documentation to reflect new CLI usage and programmatic API |
| tests/test-with-errors.yaml | Test OpenAPI spec with error response definitions |
| tests/errors.ts | Generated TypeScript types from test OpenAPI spec |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| try { | ||
| const spinner = ora('Generating types').start(); | ||
| await generateTypes(openapiPath, destinationPath, options.format === true, options.addTypedRequestHandler === true); | ||
| await sleep(SECOND); |
There was a problem hiding this comment.
The artificial 1-second delay using sleep(SECOND) serves no functional purpose and unnecessarily slows down the CLI. This should be removed to improve performance.
| await sleep(SECOND); |
| try { | ||
| const spinner = ora('Generating errors').start(); | ||
| await generateErrors(openapiPath, destinationPath, options.format === true, options.mapping, options.errorClasses); | ||
| await sleep(SECOND); |
There was a problem hiding this comment.
The artificial 1-second delay using sleep(SECOND) serves no functional purpose and unnecessarily slows down the CLI. This should be removed to improve performance.
| await sleep(SECOND); |
| } | ||
|
|
||
| if (includeMapping === true) { | ||
| errorFile += ` export const API_ERRORS_MAP = { ${buildErrorMapping(errorCodes)} } as const;\n`; |
There was a problem hiding this comment.
Due to the bug in buildErrorMapping, this will generate invalid TypeScript syntax with a leading comma in the object literal, causing compilation errors.
… programming patterns
| ``` | ||
|
|
||
|
|
||
| Options: |
There was a problem hiding this comment.
add the positional arguments
|
|
||
|
|
||
|
|
||
| ## Functional Programming Support |
There was a problem hiding this comment.
its not really functional programming. just programmatic
| } | ||
|
|
||
| const SECOND = 1000; | ||
| program.name('openapi-helpers').description('Generate TypeScript types and error classes from OpenAPI specifications').version('3.1.0'); |
There was a problem hiding this comment.
do not hardcode version
https://github.com/MapColonies/read-pkg
There was a problem hiding this comment.
you right. added
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Introduce a unified command-line interface that generates TypeScript types and error classes based on OpenAPI specifications, enhancing usability and functionality.