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

noflo-swagger-client

v0.4.0

Published

Generate NoFlo components from Swagger/OpenAPI definitions

Downloads

9

Readme

noflo-swagger-client

This library can be used for generating NoFlo components for accessing any REST API described by Swagger/OpenAPI. Each API method will get its own component, with the top-level parameters becoming separate inports.

Declarative usage

In Node.js NoFlo projects it is possible to register Swagger files for component generation by declaring them in your package.json. Example:

{
  "version": "...",
  "dependencies": {
    ...
  },
  "noflo": {
    "swagger": {
      "petstore": {
        "url": "https://petstore3.swagger.io/api/v3/openapi.json"
      }
    }
  }
}

This would generate a component for each Swagger pet store method using the petstore namespace. So you'd get components like petstore/FindPetByID.

Usage as a library

It is also possible to use noflo-swagger-client as a library, registering NoFlo components programmatically. This is useful for example when utilizing noflo-nodejs as a library.

const loader = new noflo.ComponentLoader(process.cwd());
const def = {
  url: 'http://petstore.swagger.io/v2/swagger.json',
};
loader.listComponents(() => {
  registerSwaggerComponents(loader, 'petstore', def))
    .then(() => {
      console.log('Components registered!');
    });
});

Assembly line components

This library can also create NoFlo Assembly Line compatible components. Just add assembly: true to the API definition parameters.

In package.json:

{
  "dependencies": {
    ...
  },
  "noflo": {
    "swagger": {
      "petstore": {
        "url": "https://petstore3.swagger.io/api/v3/openapi.json",
        "assembly": true
      }
    }
  }
}

These components will only contain in and out ports. The key parameter of the input message will be used as request parameters, and the API response will be written as the message parameter response. Error handling is handled using the noflo-assembly conventions.

Populating authorization data from environment variables

In addition to registering authorization keys via the API definition passed to NoFlo Swagger Client initially, it can also be done via environment variables. This is especially useful when generating the components in the declarative way.

The environment variables supported are formatted with SWAGGER_<NAMESPACE>_<KEYNAME>. For example to populate the API key to the pet store API used as example above, you'd set it with SWAGGER_PETSTORE_APIKEY. With this, all components needing API key authentication will set the api_key header to the value from the environment variable.

Loading Swagger definitions from the file system

By default the Swagger definitions are requested from their supplied URL. It is however possible to pass a local file instead by giving its path via the file parameter, replacing the normal url parameter.

Component icons

Custom icon can be set for a library by adding an icon key to the definition.

Changes

  • 0.4.0 (2021-01-15)
    • Added support for loading Swagger definitions from local files
  • 0.3.0 (2020-12-11)
    • Updated for the latest noflo-assembly
  • 0.2.3 (2020-09-21)
    • Added safety to Assembly components in case there is no definition for an API route
  • 0.2.2 (2020-09-16)
    • Added custom icon support
  • 0.2.1 (2020-09-16)
    • Added support for populating authorization keys from environment variables
  • 0.2.0 (2020-09-15)
  • 0.1.1 (2020-09-11)
    • Improved test coverage
  • 0.1.0 (2020-09-09)
    • Initial release