How to use OpenAPI generator with corporate proxy?
Asked Answered
P

1

8

I am trying to use OpenAPI generator to automatically generate C# client code based on a openapi: "3.0.2" json configuration:

openapi-generator generate -i https://test.com/docs/swagger/openapi.json -g csharp-netcore -c open-api-config.json -o DataLakeOpenApiRestClient.cs

This fails with the following error:

[main] ERROR io.swagger.v3.parser.util.RemoteUrl - unable to read java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.security.ssl.SSLSocketImpl.connect(Unknown Source) at sun.security.ssl.BaseSSLSocketImpl.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.protocol.https.HttpsClient.(Unknown Source) at sun.net.www.protocol.https.HttpsClient.New(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source) at io.swagger.v3.parser.util.RemoteUrl.urlToString(RemoteUrl.java:147) at io.swagger.v3.parser.OpenAPIV3Parser.readWithInfo(OpenAPIV3Parser.java:123) at io.swagger.v3.parser.OpenAPIV3Parser.readLocation(OpenAPIV3Parser.java:45) at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:16) at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:586) at org.openapitools.codegen.cmd.Generate.run(Generate.java:395) at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)

However if I download the json file and run using a local file input, it works fine:

openapi-generator generate -i open-api-offline-file.json -g csharp-netcore -c open-api-config.json -o DataLakeOpenApiRestClient.cs

I have tested this on a computer without a corporate proxy and it works properly, so my main suspect is the proxy.

I have set HTTP_PROXY and `HTTPS_PROXY, but they are not used.

Question: How to use OpenAPI generator with corporate proxy?

Polk answered 7/8, 2019 at 14:24 Comment(0)
T
2

You can try setting the networking properties using -D: https://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html

e.g.

openapi-generator generate -i open-api-offline-file.json -g csharp-netcore -c open-api-config.json -o DataLakeOpenApiRestClient.cs -Dhttps.proxyHost=internal-proxy.mycompany.com -Dhttps.proxyPort=8080
Tabathatabb answered 8/8, 2019 at 6:41 Comment(3)
Unfortunately, it did not work although it makes sense. I have also tried with -Djava.net.useSystemProxies=true. I am wondering if openapi-generator actually reads these options. Anyway, I think I can get the content via another command and use the offline generation.Polk
These options are (or should be) used by Swagger Parser (a dependency of OpenAI Generator) when parsing the OpenAPI/Swagger doc/spec.Tabathatabb
[DEPRECATED] -D arguments after 'generate' are application arguments and not Java System Properties, please consider changing to -p, or apply your options to JAVA_OPTS, or move the -D arguments before the jar option.Nomography

© 2022 - 2024 — McMap. All rights reserved.