How to integrate external npm package

Hello Everyone,
I want to know how to integrate this npm package in my test script.

I tried a couple of solutions but nothing works for me.
Please help me with this.

Thanks

What have you tried?

2 Likes

Hey @thefierycoder :wave:

As I understand it, you want to convert collection file to OpenAPI spec file using this library, correct?

In general, you can download an external library using pm.sendRequest and evaluate it with eval() as shown in an example here.

But you cannot directly access local filesystem from scripts in Postman due to security reasons as mentioned here, so it would be quite challenging to use that library from test scripts in Postman (the only workaround would be to set up a local server that access to your local file system and call the server from Postman).

Hopefully this clarifies a bit. Please do feel free to let me know if anything in my response needs further clarification :slightly_smiling_face:

1 Like

@taehoshino Thanks for your help.

I’ll check the linked resources then let you know.

In the package repo, there is not any min.js file, so, which js file should I call and eval() from the postman?

UPDATE:
I checked all the linked resources.
I have some doubts:

  1. Which js file should I call from the postman because we don’t have a min.js file of that package?

  2. How to access that input collection file and read that file in the postman app?
    I saw this article that tells how to write on a disk using a local server but How should I get the file path so, we can pass that path to the npm package?

This npm package also has some dependencies in order to work.

Hello @vdespa ,

I tried what you told on one of your youtube videos.

But you used the .min.js file to send the request to the package and then you save it to the env but in my case, there is not any .min.js file.

Hey @thefierycoder :wave:

This index.js seems to be the main js file, but looking at it, we can see this file itself is requiring some external libraries like fs. Even if we can import this library, we would then need to import additional libraries that are being required (it’s gonna be very messy if not impossible :slightly_frowning_face: ).

If what you want to achieve here is to trigger the conversion of collection file to OpenAPI schema file from Postman, you can set up a local server using nodeJS and simply requiring the postman-to-openapi library from your nodeJS code like in the blog post.
Then you can send a request to that local server - maybe you can pass the file path to the collection file in the request, which can be passed to postmanToOpenApi.

Hope this helps! Let me know if you have any question :slightly_smiling_face:

@taehoshino Thanks for your help!

That’s what I am planning to do!:slightly_smiling_face:

Will setup a local server and make a post request to.
It’ll be easy for me

I want a suggestion:

If I make a wrapper npm package for this package that takes a collection id instead of a file and then in the script file we’ll make requests to the Postman api to get the particular collection json and then save it to temp folder then pass that file to that package.

Will this wrapper package helpful for the community?

One issue I found in this approach is the postman api key?

Hey @thefierycoder :wave:

I am sure such an implementation would be helpful :slightly_smiling_face:
If you can share in your own GitHub repo, other users will be able to utilize it with ease.

1 Like

For now, I made this npm package to convert a postman collection to openapi via CLI.

1 Like