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

feat: add generateErrors script and update dependencies (MAPCO-8468)#47

Merged
ronenkapelian merged 3 commits into
masterfrom
generateErrors
Aug 7, 2025
Merged

feat: add generateErrors script and update dependencies (MAPCO-8468)#47
ronenkapelian merged 3 commits into
masterfrom
generateErrors

Conversation

@CptSchnitz

Copy link
Copy Markdown
Collaborator

No description provided.

@ronenkapelian ronenkapelian changed the title feat: add generateErrors script and update dependencies feat: add generateErrors script and update dependencies (MAPCO-8468) Aug 4, 2025
@github-actions

github-actions Bot commented Aug 4, 2025

Copy link
Copy Markdown

🎫 Related Jira Issue: MAPCO-8468

@ronenkapelian
ronenkapelian requested a review from Copilot August 4, 2025 08:01

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 adds a script to generate TypeScript error classes from OpenAPI specifications and updates dependencies to support this functionality. The script extracts error codes from OpenAPI response schemas and creates corresponding error classes with proper typing and documentation.

Key changes:

  • Adds a new generateErrors.mts script that parses OpenAPI documents and generates TypeScript error classes
  • Updates dependencies to include required packages for JSON schema parsing and string case conversion

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/generator/generateErrors.mts New script that extracts error codes from OpenAPI specs and generates TypeScript error classes with proper inheritance and documentation
package.json Adds dependencies for @apidevtools/json-schema-ref-parser and change-case packages

process.exit(0);
}

let errorFile = errorCodes.values().map(createError).toArray().join('\n');

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

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

The method toArray() does not exist on Set iterators. Use Array.from(errorCodes) instead of errorCodes.values().map(createError).toArray().

Suggested change
let errorFile = errorCodes.values().map(createError).toArray().join('\n');
let errorFile = Array.from(errorCodes).map(createError).join('\n');

Copilot uses AI. Check for mistakes.
let errorFile = errorCodes.values().map(createError).toArray().join('\n');

if (shouldFormat === true) {
const prettierOptions = await resolveConfig('./src/index.ts');

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded path './src/index.ts' for Prettier config resolution is inflexible. Consider using the current working directory or making this configurable.

Suggested change
const prettierOptions = await resolveConfig('./src/index.ts');
const prettierOptions = await resolveConfig(destinationPath);

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +44
const codeProperty = schema.properties.code as SchemaObject;

// Handle enum values
if (codeProperty.enum) {
codeProperty.enum.map(String).forEach((code) => {

Copilot AI Aug 4, 2025

Copy link

Choose a reason for hiding this comment

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

Type assertion without validation could cause runtime errors. Consider checking if schema.properties.code is actually a SchemaObject before casting.

Suggested change
const codeProperty = schema.properties.code as SchemaObject;
// Handle enum values
if (codeProperty.enum) {
codeProperty.enum.map(String).forEach((code) => {
const codeProperty = schema.properties.code;
// Validate that codeProperty is a SchemaObject-like object with enum
if (
typeof codeProperty === 'object' &&
codeProperty !== null &&
Array.isArray((codeProperty as SchemaObject).enum)
) {
// Handle enum values
(codeProperty as SchemaObject).enum.map(String).forEach((code) => {

Copilot uses AI. Check for mistakes.

@ronenkapelian ronenkapelian 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.

Waiting for merge, until jobnik-manager: error codes pr will be ready to integrate

@ronenkapelian ronenkapelian 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.

  1. its not working when i provide canonical directory.
  2. eslint error on generated file :"Export statements should appear at the end of the fileeslintimport-x/exports-last"

@ronenkapelian
ronenkapelian merged commit 00855d2 into master Aug 7, 2025
4 checks passed
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