openapi-generator-cli: Unable to execute openapi-generator-cli version[BUG]
Using version 2.3.5 of openapi-generator-cli in the Node environment, I am getting the error shown below. Googling, I found bug #130 in this issue database. This issue states that a solution was put in place, but does not provide any guidance on how to implement the solution.
[rflatau@localhost server]$ npx @openapitools/openapi-generator-cli version
Unable to query repository, because of: "Request failed with status code 501"
Response:
server squid/3.4.8
mime-version 1.0
date Tue, 22 Jun 2021 13:39:33 GMT
content-type text/html
content-length 3484
x-squid-error ERR_UNSUP_REQ 0
vary Accept-Language
content-language en
x-cache MISS from intergate2
x-cache-lookup NONE from intergate2:3132
via 1.1 intergate2 (squid/3.4.8)
connection close
(node:35812) UnhandledPromiseRejectionWarning: TypeError: error.response.data.on is not a function
at VersionManagerService.printResponseError (/home/rflatau/devel/learning_center-main/api/node_modules/@openapitools/openapi-generator-cli/main.js:922:33)
at /home/rflatau/devel/learning_center-main/api/node_modules/@openapitools/openapi-generator-cli/main.js:828:18
at /home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/operators/catchError.js:13:46
at OperatorSubscriber._this._error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/operators/OperatorSubscriber.js:38:21)
at OperatorSubscriber.Subscriber.error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/Subscriber.js:80:18)
at OperatorSubscriber.Subscriber._error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/Subscriber.js:104:30)
at OperatorSubscriber.Subscriber.error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/Subscriber.js:80:18)
at OperatorSubscriber.Subscriber._error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/Subscriber.js:104:30)
at OperatorSubscriber.Subscriber.error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/Subscriber.js:80:18)
at OperatorSubscriber.Subscriber._error (/home/rflatau/devel/learning_center-main/api/node_modules/rxjs/dist/cjs/internal/Subscriber.js:104:30)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:35812) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:35812) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
The referenced bug report seems to imply that proxy settings might be the problem. Investigating now how to deal with specifying the proxies. We are behind a corporate proxy. I have tried setting http_proxy and https_proxy environment parameters without success. I believe that there is a way to configure the openapi-generator-cli to deal with proxies, but I have not been able to find this.
I found two configurations within the referenced bug report: here and here. But no details on the structure of the configuration file.
What is the configuration needed to get the command below work? How do I augment the command to use the configuration file:
npx @openapitools/openapi-generator-cli version
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 22 (2 by maintainers)
I was also able to find a workaround for this by manually setting the version in my openapitools.json file. The issue is happening when the npm wrapper tries to query the lastest available version of openapi-generator from maven. If you’ve set your version in openapitools.json, it wont run the query and will just download the jar file corresponding to the version you’ve chosen. So far I haven’t had any issues with downloading the jar. Really only the query seems to be having issues
Example
Meanwhile, I was able to generate the client using below steps. Basically skipping the wrapper and accessing jar directly.
java -jar openapi-generator-cli-5.3.1.jar generate -g csharp-netcore -aditional-properties=targetFramework=net5.0 -i project.swagger.json -o ./Generated --skip-validate-specI am having similar issue. It is most likely that the NO_PROXY environment variable is not respected.
As per yarnpkg/yarn#841 and nodejs/node-gyp#695 setting
NODE_EXTRA_CA_CERTSfixed it for me. I had already setcafilein .npmrc, but it seems this was ignored.I looked a bit at the source code to find out how the proxy settings are used.
This is the place where it happens: https://github.com/OpenAPITools/openapi-generator-cli/blob/0645163a72244dc1d0ec8e07481b527c24439d88/apps/generator-cli/src/app/app.module.ts#L11 (see fix #130 & PR #139)
The environment variables HTTPS_PROXY and HTTP_PROXY are considered. But as @pstanoev already assumed, the NO_PROXY environment variable is not respected. This must be taken into account and, if necessary, the environment variables must be set or removed accordingly.
I got some feedback from IT group monitoring the internet activity. The failed command above got the following error:
1624375550.827 0 10.92.82.143 TAG_NONE/501 3805 GET https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.1.1/openapi-generator-cli-5.1.1.jar?test123 - HIER_NONE/- text/htmlI executed a curl on the above URL:
curl https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/5.1.1/openapi-generator-cli-5.1.1.jar?test123 --output temp.tmpI got the temp.tmp file generated. In addition, the IT guy saw the following messages:
The failed log tried to do a GET on a https URL, while the success logs issued the CONNECT commands.
With the configuration file we are currently using, a maven repository is specified. I removed that from the configuration and got a different URL (https://search.maven.org/solrsearch/select?q=g:org.openapitools+AND+a:openapi-generator-cli&core=gav&start=0&rows=200 ), but still the same problem.
Could not find a way to prevent application from searching maven for updates. It seems like the openapi-generator-cli is trying to establish the “wrong” type of connection for https connection. I saw mention of use a -Dhttps.proxyHost and -Dhttps.proxyPort on the command line - tried that, as well as http.proxy* with no change in the results, as well as the same error messages in internet access logs. The curl command demonstrated that we could get the the firewall (also did a browser download), so this does not seem to be a proxy issue.