openapi-generator: Problems with SSL certificate
Hi,
I try to use this CLI in my project to generate my API typescript client. But my swagger.yaml file is on a https url and I have errors because of SSL certificate.
I added the following script to my package.json :
"swagger": "./node_modules/.bin/openapi-generator generate -i https://myserver/api-docs -g typescript-fetch -o src/services/Api/swagger"
But when I run npm swagger I have the following stack trace :
[main] ERROR i.s.parser.SwaggerCompatConverter - failed to read resource listing javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
at sun.security.ssl.Handshaker.processLoop(Unknown Source)
at sun.security.ssl.Handshaker.process_record(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at sun.net.www.protocol.https.HttpsClient.afterConnect(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.parser.util.RemoteUrl.urlToString(RemoteUrl.java:134)
at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:193)
at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:123)
at io.swagger.parser.SwaggerCompatConverter.readWithInfo(SwaggerCompatConverter.java:94)
at io.swagger.parser.SwaggerParser.readWithInfo(SwaggerParser.java:42)
at io.swagger.v3.parser.converter.SwaggerConverter.readLocation(SwaggerConverter.java:92)
at io.swagger.parser.OpenAPIParser.readLocation(OpenAPIParser.java:19)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:606)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:367)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60) Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.validate(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(Unknown Source)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source) ... 21 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(Unknown Source)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 27 common frames omitted
Exception in thread "main" java.lang.NullPointerException
at java.util.HashSet.(Unknown Source)
at org.openapitools.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:608)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:367)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:60)
--
Any idea how I could solve this ?
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 3
- Comments: 20 (5 by maintainers)
So it looks like another version swagger parser util got referenced else where in the code. I finally got it to work after running with these 2 flags
-Dio.swagger.parser.util.RemoteUrl.trustAll=true-Dio.swagger.v3.parser.util.RemoteUrl.trustAll=trueRunning
Throws this error
Version
When targeting a server with self-signed certificate, this worked for executing using
npxon macOS:Hi Mario, you can define the script like this
If for whatever reason you are trying to do this with Powershell you can do the following:
-Dio.swagger.v3.parser.util.RemoteUrl.trustAll=trueis not working for me as mentioned in here https://github.com/OpenAPITools/openapi-generator/blob/master/docs/faq-extending.mdhow about downloading the api definition before generating e.g. with
curl?I’m having this issue as well. I have an npm script I run from package.json and I don’t know how to disable the ssl check from there:
@StrictlyDPBlaine thanks. I’ve updated the FAQ: https://github.com/OpenAPITools/openapi-generator/wiki/FAQ#is-there-a-way-to-disable-certificate-verification