swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

"[ISSUE] Proxy Authentication fails with openapi-generator-maven-plugin during API spec download"

Open jmakam opened this issue 1 year ago • 0 comments

Description

I am encountering an issue with the openapi-generator-maven-plugin (version 6.2.1) while attempting to generate API stubs from a remote OpenAPI specification file hosted on SwaggerHub. The build process consistently fails due to what appears to be incorrect handling of proxy credentials.

Our build environment is behind a corporate proxy that requires basic authentication. The proxy is configured correctly, and the SwaggerHub URL is whitelisted and accessible from within the build pipeline. However, the openapi-generator-maven-plugin, which relies on the Swagger parser for handling the OpenAPI spec, seems unable to pass the provided proxy credentials when attempting to access external URLs. This results in the failure to download the OpenAPI specification.

From my observations, it seems the Swagger parser is not handling the proxy credentials as expected. Could this be an issue with the way the Swagger parser manages proxy authentication?

Is there a known workaround, or is there any additional configuration that might ensure proper handling of proxy credentials in this scenario?

Environment

openapi-generator-maven-plugin: 6.2.1 Maven: 3.x JDK: OpenJDK 17 Build Environment: Docker (Alpine-based container in AWS CodePipeline)

What I've Tried

Configuring proxy credentials in settings.xml:

<proxies>
  <proxy>
    <id>http-proxy</id>
    <active>true</active>
    <protocol>http</protocol>
    <host>proxy.resources.vwapps.cloud</host>
    <port>8080</port>
    <username>username</username>
    <password>password</password>
    <nonProxyHosts>localhost|127.0.0.1</nonProxyHosts>
  </proxy>
</proxies>

Enabling basic authentication with the following flags:

-Djdk.http.auth.tunneling.disabledSchemes= \
-Djdk.http.auth.proxying.disabledSchemes=

Setting the proxy values within the Maven command:

mvn clean package -DskipTests -Dmaven.javadoc.skip=true \
  -Dhttp.proxyHost=${PROXY_HOST} \
  -Dhttp.proxyPort=${PROXY_HTTP_PORT} \
  -Dhttp.proxyUser=${PROXY_USERNAME} \
  -Dhttp.proxyPassword=${PROXY_PASSWORD} \
  -Dhttps.proxyHost=${PROXY_HOST} \
  -Dhttps.proxyPort=${PROXY_HTTPS_PORT} \
  -Dhttps.proxyUser=${PROXY_USERNAME} \
  -Dhttps.proxyPassword=${PROXY_PASSWORD} \
  -Dhttp.nonProxyHosts="localhost,127.0.0.1" \
  -Dhttps.nonProxyHosts="localhost,127.0.0.1" \
  -Djdk.http.auth.tunneling.disabledSchemes= \
  -Djdk.http.auth.proxying.disabledSchemes=

None of these approaches resolved the issue. I also tried setting the flags within MAVEN_OPTS, JAVA_OPT, and JAVA_TOOL_OPTIONS, with no success.

Error Output

The relevant part of the error message:

[ERROR] unable to read
java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling0 (HttpURLConnection.java:2296)
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling (HttpURLConnection.java:2166)
    at io.swagger.v3.parser.util.RemoteUrl.urlToString (RemoteUrl.java:151)

For full error log see attached error logs. error-log.txt

jmakam avatar Oct 08 '24 13:10 jmakam