api2swagger - TypeError: Cannot read property 'headers' of undefined

I am using the api2swagger tool. I am new to the tool. I was able to successfully generate the example (Google Books) with the tool. However, when I run it against an API on my local machine I receive the following error. The API call is a GET with multiple query parameters and multiple headers. It seems to fail before reaching the API. Has anyone seen this error and can you tell me what the issue might be? Thanks in advance.

Making an API Call & fetching more details...Please stay tuned..


C:\Users\skarlovic\AppData\Roaming\npm\node_modules\api2swagger\lib\execute\api.js:286
    swaggerSpec.paths[apiPath][pathMethod]["produces"].push(response.headers['
                                                                    ^
TypeError: Cannot read property 'headers' of undefined
    at Request._callback (C:\Users\skarlovic\AppData\Roaming\npm\node_modules\api2swagger\lib\execute\api.js:286:69)
    at self.callback (C:\Users\skarlovic\AppData\Roaming\npm\node_modules\api2swagger\node_modules\request\request.js:186:22)
    at Request.emit (events.js:95:17)
    at Request.onRequestError (C:\Users\skarlovic\AppData\Roaming\npm\node_modules\api2swagger\node_modules\request\request.js:845:8)
    at ClientRequest.emit (events.js:95:17)
    at CleartextStream.socketErrorListener (http.js:1552:9)
    at CleartextStream.emit (events.js:95:17)
    at SecurePair.<anonymous> (tls.js:1400:19)
    at SecurePair.emit (events.js:92:17)
    at SecurePair.maybeInitFinished (tls.js:980:10)

0 4 2,089
4 REPLIES 4

Hi @skarlovic ,

Probably you are doing a POST or PUT call. api2swagger checks for "Content-Type" header in these cases. Try sending a "Content-Type" header with some value. This will solve the error.

Cheers!

Thanks for the suggestion, still getting the same error. I'm specifying -X GET and tried with -H "Content-Type: application/json" even though it shouldn't be necessary. For now I'm able to use the web version, which seems to be working from me. But there are cases where I'd like to use the command-line version to access internal APIs. Thanks again for your time.

Note: the api2swagger project was renamed to apigee2openapi to better reflect its purpose. You may want to use the newer project, as it is more likely to receive updates. See https://www.npmjs.com/package/apigee2openapi

Thanks, this looks promising! I'll definitely try it out. Are there any guidelines to follow which will help ensure the Open API specification is generated to accurately reflect the proxy? For example how will the tool know if an API takes a query parameter or path parameter, or a specific header etc. Or how will it know to generate a schema for both the successful response as well as the errors. I'm trying to get a sense of how much manual editing of the Open API spec I will have to be doing in order for it to be complete.