LucyBot-Inc / api-spec-converter

Convert API descriptions between popular formats such as OpenAPI(fka Swagger), RAML, API Blueprint, WADL, etc.
https://lucybot-inc.github.io/api-spec-converter/
MIT License
1.12k stars 181 forks source link

Command line tool : TypeError: Cannot read property 'call' of undefined #148

Open milanbr opened 6 years ago

milanbr commented 6 years ago

When run:

api-spec-converter pisp.apib --from=api_blueprint --to=swagger_2 > swagger.json

I get:

node_modules\api-spec-converter\node_modules\drafter.js\lib\drafter.nomem.js:1
(function (exports, require, module, __filename, __dirname) { ((function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(
typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.drafter=f()}}))((function(){var module;var Module;if(!Module){Module={}}Module["ready"]=f
alse;Module["log"]=(function(text){console.log("drafter.js: "+text)});Module["logErr"]=(function(text){console.error("drafter.js: "+text)});Module["onRuntimeInitialized"]=(function(){this.ready=true});var Module;if(!Module)Module
=(typeof Module!=="undefined"?Module:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false

TypeError: Cannot read property 'call' of undefined
    at CompositeError.get (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\composite-error\lib\compositeError.js:45:50)
    at CompositeError.formatStackTraces (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\composite-error\lib\compositeError.js:56:23)
    at CompositeError.get (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\composite-error\lib\compositeError.js:25:39)
    at Async.fatalError (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\async.js:50:65)
    at Promise._reject (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\promise.js:652:22)
    at Promise._settlePromise (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\promise.js:584:21)
    at Promise._settlePromise0 (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\promise.js:689:18)
    at Async._drainQueue (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\async.js:143:10)
    at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\cen76482\AppData\Roaming\npm\node_modules\api-spec-converter\node_modules\bluebird\js\release\async.js:17:14)
rbren commented 6 years ago

Can you share your apibp file? The command works for me with this one:

https://raw.githubusercontent.com/apiaryio/api-blueprint/master/examples/Polls%20API.md

mieszkomalawski commented 6 years ago

Same here, when converting from openapi_3 to swagger_2

canvural commented 6 years ago

Same happens to me. From api_blueprint to openapi_3

rbren commented 6 years ago

If anyone can share a file that triggers this bug, I'm happy to try and reproduce.

mieszkomalawski commented 6 years ago

Unfortunately I cannot share because definition contains company internal APIs, maybe @milanbr or @canvural can?

janpieper commented 5 years ago

The error occurs in api-spec-converter/node_modules/composite-error/lib/compositeError.js on line 45. I've added console.log(this.originalStackDescriptor); to check what's happening:

{ value: 'CompositeError: Failed to parse spec\n    at Promise.any.catch.err (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/lib/base_format.js:119:13)\n    at tryCatcher (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/util.js:16:23)\n    at /home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/catch_filter.js:17:41\n    at tryCatcher (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/util.js:16:23)\n    at Promise._settlePromiseFromHandler (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/promise.js:512:31)\n    at Promise._settlePromise (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/promise.js:569:18)\n    at Promise._settlePromiseCtx (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/promise.js:606:10)\n    at _drainQueueStep (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/async.js:142:12)\n    at _drainQueue (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/async.js:131:9)\n    at Async._drainQueues (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/async.js:147:5)\n    at Immediate.Async.drainQueues (/home/jan/.asdf/installs/nodejs/8.10.0/.npm/lib/node_modules/api-spec-converter/node_modules/bluebird/js/release/async.js:17:14)\n    at runCallback (timers.js:794:20)\n    at tryOnImmediate (timers.js:752:5)\n    at processImmediate [as _immediateCallback] (timers.js:729:5)',
  writable: true,
  enumerable: false,
  configurable: true }

api-spec-converter tries to call .get on this object, but there is no get-key.

Edit: api_blueprint to openapi_3.

Edit: :arrow_right: We used integer instead of number in some cases. This caused the parser error. :arrow_left:

rbren commented 5 years ago

Thanks for the details!

Unfortunately I wasn't able to trigger the error by setting a query parameter to integer - any more details you can share on how to reproduce?

gunters63 commented 5 years ago

I had the same problem and added another line in bluebirds promise.js (line 658) to track the problem down:

console.log(JSON.stringify(reason, null, 4));

This is the error message I got:

{
    "name": "CompositeError",
    "message": "Failed to parse spec",
    "innerErrors": [
        {
            "result": {
                "_version": "2.2",
                "error": {
                    "code": 2,
                    "message": "the use of carriage return(s) '\\r' in source data isn't currently supported, please contact makers",
                    "location": [
                        {
                            "index": 1087,
                            "length": 1
                        }
                    ]
                },
                "warnings": []
            }
        }
    ],

After a change all line-endings to LF (unix) the converter worked

peterhut commented 5 years ago

Encountered the same issue trying to convert the apibp file downloaded from https://gost1.docs.apiary.io/ Attached: gost1.apib.txt

blazekv commented 5 years ago

I had same problem as @gunters63 . File was saved with CRLF. Saving file as Unix style solves the problem.

@rbren IMHO It will be sufficient to handle error message and raise more specific message. Original error message is really confusing.