npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openapi-url-resolver

v1.0.8

Published

Resolve server URLs and extract hosts from OpenAPI 3.0 and Swagger specifications.

Downloads

13

Readme

openapi-url-resolver is a lightweight NPM package that provides a simple and efficient way to resolve server URLs from OpenAPI specifications. It also removes protocols from the resolved URLs and allows you to easily extract host information from OpenAPI definitions. This package is ideal for developers working with APIs that conform to the OpenAPI 3.x specification and need to extract server information to make API calls. Check out the blog post for more details—How to resolve server URLs containing variables in OpenAPI 3.x definitions?

Features:

  • 🚀 Lightweight module with only 965 bytes in size
  • 🎉 Zero dependencies, making it easy to install and use in your projects
  • 🔍 Efficient and simple way to resolve server URLs from OpenAPI specifications

📦 Installation

You can install openapi-url-resolver via NPM:

npm install openapi-url-resolver

openapi-url-resolver on NPM

💻 Usage

To use openapi-url-resolver, you need to pass an OpenAPI 3.x specification object to the resolve() function. This function will return an array of resolved server URLs:

const openapiUrlResolver = require('openapi-url-resolver')

const spec = {
  openapi: '3.0.0',
  servers: [
    {
      url: 'https://{username}.gigantic-server.com:{port}/{basePath}',
      description: 'The production API server',
      variables: {
        username: {
          default: 'demo',
          description: 'this value is assigned by the service provider, in this example `gigantic-server.com`'
        },
        port: {
          enum: ['8443', '443'],
          default: '8443'
        },
        basePath: {
          default: 'v2'
        }
      }
    }
  ]
}

const hosts = openapiUrlResolver.resolve(spec)

/*

[
  'demo.gigantic-server.com:8443/v2',
  'demo.gigantic-server.com:443/v2'
]

*/
console.log(hosts)

Pass false as second parameter to get the server URLs with protocols.

const serverUrls = openapiUrlResolver.resolve(spec, false)

/*

[
  'https://demo.gigantic-server.com:8443/v2',
  'https://demo.gigantic-server.com:443/v2'
]

*/
console.log(serverUrls)

🧪 Testing

You can test using the below command or write your own tests using the OpenAPI specifications examples.

npm test

🚫 Limitations

The below are the known limitations, and they are not handled to keep it a lightweight and focused module to just extract the server information.

🤝 Contributing

Contributions to openapi-url-resolver are most welcome!

If you find a bug or want to suggest a new feature, please open an issue on the GitHub repository. If you want to contribute code, please fork the repository, make your changes, and submit a pull request. Your contributions and feedback are most welcome!

📝 License

openapi-url-resolver is authored by @vinitshahdeo and released under the MIT License.

❤️ Support

If you find this package useful, please consider starring this repository on GitHub to show your appreciation. You can stay connected with me on Twitter—@vinit_shahdeo.

Thank you for your support! 🙏