joolfe / postman-to-openapi

🛸 Convert postman collection to OpenAPI
MIT License
577 stars 99 forks source link

TypeError: input.trim is not a function #252

Closed bhtw closed 1 year ago

bhtw commented 1 year ago

Error:

Cannot convert Postman collection due to error TypeError: input.trim is not a function.

How to reproduce:

code used

const postmanToOpenApi = require('postman-to-openapi')

const postmanCollection = require("./sampleCollections/responses.json")
const outputFile = './openApi/responses.yml'

const convert = async () => {
  try {
    const result = await postmanToOpenApi(postmanCollection, outputFile, options)
    console.log(`OpenAPI specs: ${result}`)
  } catch (err) {
    console.log(err)
  }
}

convert()

Result

TypeError: input.trim is not a function
    at resolveInput (/home/server/btw/dev/api/postman2openapi/node_modules/postman-to-openapi/lib/index.js:605:13)
    at postmanToOpenApi (/home/server/btw/dev/api/postman2openapi/node_modules/postman-to-openapi/lib/index.js:18:30)
    at convert (/home/server/btw/dev/api/postman2openapi/main.js:12:26)
    at Object.<anonymous> (/home/server/btw/dev/api/postman2openapi/main.js:47:1)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47

Purposed solution

I made this change, and then it worked:

I guess you should do more checks or something, but this fix made it work for me. And if you have more places where you do a trim without checking if the parameter is a String, then this should be impelented too, I guess.

Hope this helps others as well that might have had this issue.

joolfe commented 1 year ago

Hi @bhtw,

That´s not a bug, as you can read in the documentation here the parameter input is defined as String. Path of the Postman collection file or value of the postman collection as String., you are not providing a string so you are breaking the contract ;-), that's all.

If you want a new feature that accept the input as an object just open a feature request please but not a bug.

Best regards.