Skip to content
This repository was archived by the owner on Jul 15, 2026. It is now read-only.

feat!: unified CLI generating TypeScript types and error classes from OpenAPI specifications (MAPCO-8469)#49

Merged
CptSchnitz merged 12 commits into
masterfrom
unified-generators-cli
Aug 24, 2025
Merged

feat!: unified CLI generating TypeScript types and error classes from OpenAPI specifications (MAPCO-8469)#49
CptSchnitz merged 12 commits into
masterfrom
unified-generators-cli

Conversation

@ronenkapelian

Copy link
Copy Markdown
Contributor

Introduce a unified command-line interface that generates TypeScript types and error classes based on OpenAPI specifications, enhancing usability and functionality.

@ronenkapelian ronenkapelian self-assigned this Aug 20, 2025
@ronenkapelian ronenkapelian changed the title feat: unified CLI generating TypeScript types and error classes from OpenAPI specifications feat!: unified CLI generating TypeScript types and error classes from OpenAPI specifications (MAPCO-8469) Aug 20, 2025
@github-actions

github-actions Bot commented Aug 20, 2025

Copy link
Copy Markdown

🎫 Related Jira Issue: MAPCO-8469

@ronenkapelian
ronenkapelian requested a review from Copilot August 21, 2025 10:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 types and errors generation
  • 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.

Comment thread src/cli/entrypoint.mts
try {
const spinner = ora('Generating types').start();
await generateTypes(openapiPath, destinationPath, options.format === true, options.addTypedRequestHandler === true);
await sleep(SECOND);

Copilot AI Aug 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
await sleep(SECOND);

Copilot uses AI. Check for mistakes.
Comment thread src/cli/entrypoint.mts
try {
const spinner = ora('Generating errors').start();
await generateErrors(openapiPath, destinationPath, options.format === true, options.mapping, options.errorClasses);
await sleep(SECOND);

Copilot AI Aug 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
await sleep(SECOND);

Copilot uses AI. Check for mistakes.
Comment thread src/generator/generateErrors.mts
}

if (includeMapping === true) {
errorFile += ` export const API_ERRORS_MAP = { ${buildErrorMapping(errorCodes)} } as const;\n`;

Copilot AI Aug 21, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the bug in buildErrorMapping, this will generate invalid TypeScript syntax with a leading comma in the object literal, causing compilation errors.

Copilot uses AI. Check for mistakes.
Comment thread README.md
```


Options:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the positional arguments

Comment thread README.md Outdated



## Functional Programming Support

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not really functional programming. just programmatic

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment thread src/cli/entrypoint.mts Outdated
}

const SECOND = 1000;
program.name('openapi-helpers').description('Generate TypeScript types and error classes from OpenAPI specifications').version('3.1.0');

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not hardcode version
https://github.com/MapColonies/read-pkg

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you right. added

@CptSchnitz
CptSchnitz merged commit effbcca into master Aug 24, 2025
4 checks passed
@CptSchnitz
CptSchnitz deleted the unified-generators-cli branch August 24, 2025 10:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants