openapi-generator-cli
openapi-generator-cli copied to clipboard
[BUG] HTTP_PROXY Support No Longer Works
🐛 Bug Report:
Describe the bug
This commit which swapped to a new HttpModule implementation completely removed the ability to use the CLI behind any kind of proxy.
https://github.com/OpenAPITools/openapi-generator-cli/commit/66b78fff0b24d0a91d90786d3b6f7937ee274cf6
Expected behavior
HttpModule is configured with HTTP_PROXY, HTTPS_PROXY, and NO_PROXY
@mdgilene thanks for reporting the issue.
@keks42 is that something you can take a look when you've time?
@wing328 Thanks for highlighting me, I can try, but unfortunately I could not reproduce the problem :(
@mdgilene Thanks for reporting the issue.
I tried to reproduce it, but for me everything seems to work fine. Here is what I did: I locally started a proxy server [1] that just logs & forwards everything. Then I started some minimum working example, I just checked out some project using this library [2]. The project uses openapi-generator-cli in an older version, so I upgraded it to use 2.7.0. Without configuring any proxy stuff that project worked fine. There were no connections shown in the proxy.
Then I proceeded to set the proxy environment: $ export HTTP_PROXY=http://localhost:1080 $ export HTTPS_PROXY=http://localhost:1080
I removed the node_modules in that project to have a clean start again and executed the generation task again npm run generate:api. It worked fine and on my proxy there were 2 requests shown trying to connect mavencentral to download the openapi jar. I got a 501 because the local proxy forwarded the actual https request as http, but that is an issue of my local proxy configuration - the openapi-generator-cli did use the proxy.
Then I added the downloadUrl to use my companies own maven-repository (which still does accept http calls unlike mavenCentral) and that worked fine. The requests were shown in the proxy logs and the jar was downloaded & executed.
Long story short: What can I do to reproduce your error?
[1] https://www.mock-server.com/mock_server/mockserver_ui.html [2] https://github.com/kevinboosten/angular-openapi-demo
I'm facing the same issue, openapi-generator-cli is not using the proxy, therefore it is unable to download the jar file from maven.
This might be related: https://github.com/axios/axios/issues/2072
EDIT: it might actually be related to the HTTP method used to go through the proxy. If you use a proxy that simply forwards requests it will work (for http, not for https), but if your proxy relies on the CONNECT method and denies other methods (which is usually how corporate proxies work), it won't work.
The workaround seems to be:
const HttpsProxyAgent = require('https-proxy-agent');
const axiosDefaultConfig = {
baseURL: 'https://domain.tld/api',
proxy: false,
httpsAgent: new HttpsProxyAgent('http://127.0.0.1:8080')
};
Of course the HTTPS_PROXY environment variable should be used.
I ran into this issue as well. Based on what @ShellCode33 pointed out ( https://github.com/OpenAPITools/openapi-generator-cli/issues/714#issuecomment-1787054040 ) and the initial implementation https://github.com/OpenAPITools/openapi-generator-cli/commit/66b78fff0b24d0a91d90786d3b6f7937ee274cf6 , I was able to resolve it with the following code:
// apps/generator-cli/src/app/app.module.ts
import { HttpsProxyAgent } from 'https-proxy-agent';
const proxyUrl = process.env.HTTP_PROXY || process.env.HTTPS_PROXY;
const httpModuleConfig: HttpModuleOptions = {};
if (proxyUrl) {
httpModuleConfig.proxy = false;
httpModuleConfig.httpsAgent = new HttpsProxyAgent(proxyUrl);
}
@Module({
imports: [
HttpModule.register({
...httpModuleConfig,
}),
],
// ...
})
export class AppModule implements OnApplicationBootstrap {
// ...
}
However, I just noticed that there's also a draft pull request with a similar approach: https://github.com/OpenAPITools/openapi-generator-cli/pull/752 . I'm thinking about opening another PR, but unfortunately I'm not that deep into proxies and not too sure if my implementation might break things... 😅
please open a PR to start with and we'll start from there.
:tada: This issue has been resolved in version 2.13.2 :tada:
The release is available on:
Your semantic-release bot :package::rocket: