feat: add generateErrors script and update dependencies (MAPCO-8468)#47
Conversation
|
🎫 Related Jira Issue: MAPCO-8468 |
There was a problem hiding this comment.
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.mtsscript 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'); |
There was a problem hiding this comment.
The method toArray() does not exist on Set iterators. Use Array.from(errorCodes) instead of errorCodes.values().map(createError).toArray().
| let errorFile = errorCodes.values().map(createError).toArray().join('\n'); | |
| let errorFile = Array.from(errorCodes).map(createError).join('\n'); |
| let errorFile = errorCodes.values().map(createError).toArray().join('\n'); | ||
|
|
||
| if (shouldFormat === true) { | ||
| const prettierOptions = await resolveConfig('./src/index.ts'); |
There was a problem hiding this comment.
The hardcoded path './src/index.ts' for Prettier config resolution is inflexible. Consider using the current working directory or making this configurable.
| const prettierOptions = await resolveConfig('./src/index.ts'); | |
| const prettierOptions = await resolveConfig(destinationPath); |
| const codeProperty = schema.properties.code as SchemaObject; | ||
|
|
||
| // Handle enum values | ||
| if (codeProperty.enum) { | ||
| codeProperty.enum.map(String).forEach((code) => { |
There was a problem hiding this comment.
Type assertion without validation could cause runtime errors. Consider checking if schema.properties.code is actually a SchemaObject before casting.
| 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) => { |
ronenkapelian
left a comment
There was a problem hiding this comment.
Waiting for merge, until jobnik-manager: error codes pr will be ready to integrate
ronenkapelian
left a comment
There was a problem hiding this comment.
- its not working when i provide canonical directory.
- eslint error on generated file :"Export statements should appear at the end of the fileeslintimport-x/exports-last"
No description provided.