maxdome / swagger-combine

Combines multiple Swagger schemas into one dereferenced schema.
MIT License
132 stars 36 forks source link

return error code when error occurs while processing #72

Closed tmack8001 closed 5 years ago

tmack8001 commented 5 years ago

addresses the want to have an error code returned via cli if there is an error while processing the included configuration

example config:

{
  "swagger": "2.0",
  "info": {
    "title": "Swagger Combine CLI - Returning Error Code",
    "version": "1.0.0"
  },
  "apis": [
    {
      "url": "https://awesomeswagger.invaliddomain/swagger.json",
    }
  ]
}

The resulting terminal experience:

./bin/swagger-combine .example.json
{
  "code": "ENOTFOUND",
  "errno": "ENOTFOUND",
  "syscall": "getaddrinfo",
  "hostname": "awesomeswagger.invaliddomain",
  "host": "awesomeswagger.invaliddomain",
  "port": 443,
  "api": "https://awesomeswagger.invaliddomain/swagger.json",
  "name": "Error",
  "message": "Error downloading https://awesomeswagger.invaliddomain/swagger.json
getaddrinfo ENOTFOUND awesomeswagger.invaliddomain awesomeswagger.invaliddomain:443",
  "stack": "Error: Error downloading https://awesomeswagger.invaliddomain/swagger.json
getaddrinfo ENOTFOUND awesomeswagger.invaliddomain awesomeswagger.invaliddomain:443
    at /Users/tmack/dev/private/node/swagger-combine/node_modules/json-schema-ref-parser/lib/resolvers/http.js:126:16
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:169:7)

Error: getaddrinfo ENOTFOUND awesomeswagger.invaliddomain awesomeswagger.invaliddomain:443
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:91:26)"
}

Addresses Issue: https://github.com/maxdome/swagger-combine/issues/67.

fabsrc commented 5 years ago

Hi @tmack8001. Thanks for this pull request. 🙂

Can you please make sure that the tests pass? I think the issue is that there is a test in the cli.spec.js that tests wether an error message is printed. You might need to adjust this test so that it runs in a child process and maybe also check if it returns with error code 1.

tmack8001 commented 5 years ago

ah yes, I was going to come back to the unit tests.

I'll also take your suggestion into consideration and fix that as well.

tmack8001 commented 5 years ago

Instead of doing a child process as spawn would be spawning a whole new node process I decided to just stub with sinon like is already done with console.info and console.error.

Also left the existing test and added a new one about the return code.

tmack8001 commented 5 years ago

new examples error log with a smaller example (bad file reference):

./bin/swagger-combine example.json
Error opening file "~/dev/oss/swagger-combine/1example.1.json"
ENOENT: no such file or directory, open '~/dev/oss/swagger-combine/1example.1.json'
 ✘