openapi-generator
openapi-generator copied to clipboard
[BUG] [typescript-angular] Angular 14 is not supported
Description
Specify an Angular version 14.x leads to unresolvable dependencies during "npm install":
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: @proxia-mes/[email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/typescript
npm ERR! dev typescript@">=4.4.2 <4.5.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer typescript@">=4.6.2 <4.8" from @angular/[email protected]
npm ERR! node_modules/@angular/compiler-cli
npm ERR! dev @angular/compiler-cli@"^14.0.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/runner/.npm/eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/runner/.npm/_logs/2022-08-24T11_50_36_035Z-debug-0.log
Error: Process completed with exit code 1.
For me, it looks like the problem is that in the package.json the angular version is specified with "^". So the latest 14.x version is downloaded (in my case 14.1.3) which needs a typescript version ">=4.6.2 <4.8", but in the package.json a version ">=4.4.2 <4.5.0" is generated.
openapi-generator version
Version 6.0.1
Steps to reproduce
As i can see, no build of Angular 14.x generated sources should work.
If you read the error message it says that @proxia-mes/[email protected] have [email protected] but @angular/[email protected] requires typescript@">=4.6.2 <4.8"
Doesn't seem related to anything from here
Maybe my initial description was a little bit too short.
I generate a typescript-angular module from my OpenAPI yaml file with the docker generator:
docker run --rm -v %OUTPUT_DIRECTORY%:/out -v %INTERFACE_DIRECTORY%:/specs openapitools/openapi-generator-cli:v6.0.1 generate -i specs/%INTERFACE_FILE% -o /out -g typescript-angular --additional-properties ngVersion=14.0.5,npmName=%PACKAGE_NAME%,stringEnums=true
I use the 6.0.1 generator and set the "ngVersion=14.0.5" (but the minor- and bugfix-version is not relevant for this bug)
I didn't change any of the generated code.
In the generated node module source code the following package.json is generated:
{
"name": "@proxia-mes/monitoring-dashboard-gui-service-api",
"version": "1.0.108",
"description": "OpenAPI client for @proxia-mes/monitoring-dashboard-gui-service-api",
"author": "OpenAPI-Generator Contributors",
"repository": {
"type": "git",
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
},
"keywords": [
"openapi-client",
"openapi-generator"
],
"license": "Unlicense",
"scripts": {
"build": "ng-packagr -p ng-package.json"
},
"peerDependencies": {
"@angular/core": "^14.0.5",
"rxjs": "^7.4.0"
},
"devDependencies": {
"@angular/common": "^14.0.5",
"@angular/compiler": "^14.0.5",
"@angular/compiler-cli": "^14.0.5",
"@angular/core": "^14.0.5",
"@angular/platform-browser": "^14.0.5",
"ng-packagr": "^13.0.3",
"reflect-metadata": "^0.1.3",
"rxjs": "^7.4.0",
"tsickle": "^0.43.0",
"typescript": ">=4.4.2 <4.5.0",
"zone.js": "^0.11.4"
}}
As you can see the generated module has a hard reference to "typescript": ">=4.4.2 <4.5.0". Also, the generated component has a reference to "@angular/core": "^14.0.5". Because of the ^-flag the latest minor version of the Angular major version 14 is downloaded, which is currently 14.1.3. But Angular version 14.1.3 has a reference to "typescript": ">=4.6.2 <4.8". Which doesn't match the typescript version of the module.
So no build of the module is possible.
Not sure what the issue is but the typescript version seems correct for what's in master (which'll be v6.1.0)
https://github.com/OpenAPITools/openapi-generator/blob/1d8051e85774bb03cf3a4f7e0dafe4e46f1b782c/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java#L282-L283
May I suggest you fill out the bug report form so it can be reproduced
I checked TypeScriptAngularClientCodegen.java and i found out that all references in the package.json are wrong. All references point to Angular version 13.x: e.g. "rxjs": "^7.4.0" and not "rxjs": "^7.5.5" It seems that there is a problem with the SemVer ngVersion=14.x, because all dependencies are set like ngVersion=13.x
There is also another mysterium when i run the code generation, maybe it has to do with this problem: When i run the docker code generator 6.0.1 without the "ngVersion" option then the Angular version is set to 13.0.1: package.json:
{
"name": "@proxia-mes/monitoring-dashboard-gui-service-api",
"version": "1.0.108",
"description": "OpenAPI client for @proxia-mes/monitoring-dashboard-gui-service-api",
"author": "OpenAPI-Generator Contributors",
"repository": {
"type": "git",
"url": "https://github.com/GIT_USER_ID/GIT_REPO_ID.git"
},
"keywords": [
"openapi-client",
"openapi-generator"
],
"license": "Unlicense",
"scripts": {
"build": "ng-packagr -p ng-package.json"
},
"peerDependencies": {
"@angular/core": "^13.0.1",
"rxjs": "^7.4.0"
},
"devDependencies": {
"@angular/common": "^13.0.1",
"@angular/compiler": "^13.0.1",
"@angular/compiler-cli": "^13.0.1",
"@angular/core": "^13.0.1",
"@angular/platform-browser": "^13.0.1",
"ng-packagr": "^13.0.3",
"reflect-metadata": "^0.1.3",
"rxjs": "^7.4.0",
"tsickle": "^0.43.0",
"typescript": ">=4.4.2 <4.5.0",
"zone.js": "^0.11.4"
}}
But the documentation says that the default version should be 14.0.5
I am also having this issue - when specifying angular v14, all dependency versions in the package.json are set to values that are appropriate for angular 13. This issue is continuing on the latest release and on the main branch.
Here's a minimal reproduction: https://github.com/xanderflood/oapi-bug-repro
You'll need to have Docker installed and running, since that's how it invokes the openapi-generator. Otherwise, just pull it down and run make compile
and it should run through the whole process and eventually break trying to npm install
because of incompatible versions.
I'm also having this problem and confirm the outputted module has the dependency issues as mentioned by @flobuc
I believe this can be closed. v6.6.0 is generating for angular 14 and 15 just fine for me now. I'm unsure about angular v16+ though.