swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.09k stars 6.03k forks source link

Swagger codegen does not run behind company proxy!? #8295

Open JohannesHoppe opened 6 years ago

JohannesHoppe commented 6 years ago
Description

I'm running java -jar swagger-codegen-cli.jar generate -i https://api.angular.schule/swagger.json -l typescript-angular behind an evil company proxy. It does not work. 😢

Swagger-codegen version

2.4.0 SNAPSHOT

Steps to reproduce

Execute swagger codegen behind a company proxy to read the swagger.json of a API in the internet. You get a timeout:

java -jar swagger-codegen-cli.jar generate -i https://api.angular.schule/swagger.json -l typescript-angular
[main] INFO io.swagger.parser.Swagger20Parser - reading from https://api.angular.schule/swagger.json
[main] ERROR io.swagger.parser.util.RemoteUrl - unable to read
java.net.ConnectException: Connection timed out: connect
Suggest a fix/enhancement

Swagger codegen should take the following environment variables into account:

Cheers! 🍺

silkentrance commented 6 years ago

Have you tried https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html and setting these via -D when running the jar?

jpwilhelms commented 5 years ago

swagger-codegen v3.0.5 running mvn install -Dhttps.proxyHost=myproxy -Dhttps.proxyPort=3128 behind a company proxy:

[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] swagger-codegen-project ............................ SUCCESS [ 1.943 s] [INFO] swagger-codegen (core library) ..................... FAILURE [ 55.124 s] [INFO] swagger-codegen (executable) ....................... SKIPPED [INFO] swagger-codegen (maven-plugin) ..................... SKIPPED [INFO] swagger-generator .................................. SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] swagger-codegen-project ............................ SUCCESS [ 1.943 s] [INFO] swagger-codegen (core library) ..................... FAILURE [ 55.124 s] [INFO] swagger-codegen (executable) ....................... SKIPPED [INFO] swagger-codegen (maven-plugin) ..................... SKIPPED [INFO] swagger-generator .................................. SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 57.571 s [INFO] Finished at: 2019-02-28T11:37:01+01:00 [INFO] Final Memory: 28M/148M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.0.1:jar (attach-javadocs) on project swagger-codegen: MavenReportException: Error while generating Javadoc: [ERROR] Exit code: 1 - javadoc: error - Error fetching URL: https://docs.oracle.com/javase/8/docs/api/ [ERROR] [ERROR] Command line was: javadoc.exe -J-Xmx1024m -J-Dhttp.proxySet=true -J-Dhttp.proxyHost=myproxy -J-Dhttp.proxyPort=3128 @options @packages

silkentrance commented 5 years ago

It read https://docs.../. You only have set the proxy for the http scheme.

From the docs:

HTTPS
This is HTTP over SSL, a secure version of HTTP mainly used when confidentiality (like on payment sites) is needed.

The following proxy settings are used by the HTTPS protocol handler.

https.proxyHost(default: <none>)
The hostname, or address, of the proxy server

https.proxyPort (default: 443)
The port number of the proxy server.

The HTTPS protocol handler will use the same nonProxyHosts property as the HTTP protocol.
oleksabor commented 5 years ago

I've tried to use swagger codegen (and maven build) behind the proxy and failed.

I've used https proxy configuration like -Dhttps... and it said that authetification is required. I've used -Dhttp proxy... But swagger-codegen returns an errror that said it can't download yml definition from https url. The same is for maven build - somehow it requires to authenticate or fails to download. However I do not set any login parameter when using this proxy from the web browser.

DaSilva2010 commented 4 years ago

Setting proxy with -Dhttps.proxyHost and -Dhttps.proxyPort was successful in my case.

mgvinuesa commented 4 years ago

And whats happen when the proxy needs authentication? I don't see any kind of default Authenticator proxy to set at least http.user and password.

The error is:

java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
    at sun.net.www.protocol.http.HttpURLConnection.doTunneling (HttpURLConnection.java:2172)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect (AbstractDelegateHttpsURLConnection.java:183)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect (HttpsURLConnectionImpl.java:168)
    at io.swagger.v3.parser.util.RemoteUrl.urlToString (RemoteUrl.java:147)
    at io.swagger.v3.parser.util.RefUtils.readExternalRef (RefUtils.java:204)
    at io.swagger.v3.parser.ResolverCache.loadRef (ResolverCache.java:119)
    at io.swagger.v3.parser.processors.ExternalRefProcessor.processRefToExternalResponse (ExternalRefProcessor.java:231)
    at io.swagger.v3.parser.processors.ResponseProcessor.processReferenceResponse (ResponseProcessor.java:84)
    at io.swagger.v3.parser.processors.ResponseProcessor.processResponse (ResponseProcessor.java:41)
    at io.swagger.v3.parser.processors.OperationProcessor.processOperation (OperationProcessor.java:56)
    at io.swagger.v3.parser.processors.PathsProcessor.processPaths (PathsProcessor.java:83)
    at io.swagger.v3.parser.OpenAPIResolver.resolve (OpenAPIResolver.java:49)
    at io.swagger.v3.parser.OpenAPIV3Parser.readLocation (OpenAPIV3Parser.java:66)
    at io.swagger.parser.OpenAPIParser.readLocation (OpenAPIParser.java:16)
    at org.openapitools.codegen.config.CodegenConfigurator.toContext (CodegenConfigurator.java:400)
    at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput (CodegenConfigurator.java:448)
    at org.openapitools.codegen.plugin.CodeGenMojo.execute (CodeGenMojo.java:673)
DaSilva2010 commented 4 years ago

I used cntlm for authentication against the corporate proxy