Manweill / swagger-axios-codegen

swagger client to use axios and typescript
MIT License
306 stars 83 forks source link

axios Error: self signed certificate #174

Closed fairking closed 11 months ago

fairking commented 11 months ago

Hi,

I am having an issue with one of my projects:

C:\Code\MyProject>npm run codegen

loaded spec document fail! https://localhost:8050/api/shared/schema.json Error: self signed certificate
    at TLSSocket.onConnectSecure (node:_tls_wrap:1532:34)
    at TLSSocket.emit (node:events:527:28)
    at TLSSocket._finishInit (node:_tls_wrap:946:8)
    at TLSWrap.ssl.onhandshakedone (node:_tls_wrap:727:12) {
  code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
}

As a workaround I have added the following lines in \swagger-axios-codegen\src\index.ts

const https = require('https');

// and then line 54:
const { data: swaggerJson } = await axios({ url: params.remoteUrl, responseType: 'text', httpsAgent: new https.Agent({ rejectUnauthorized: false }) })

see httpsAgent: new https.Agent({ rejectUnauthorized: false })

I am not sure how others solve such issue, but if it would cause any problems we can introduce an option 'ISwaggerOptions.allowSelfSignedCert' which by default would be false. I can create a PR if the change is wanted by others.

Any thoughts?

fairking commented 11 months ago

@Manweill any issues with this one?