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

volos-swagger

v0.8.0

Published

Middleware for bridging swagger (via swagger-tools) and volos

Downloads

285

Readme

volos-swagger

This module adds support for driving Volos middleware functions entirely though configuration and the Apigee 127 Swagger Tools swagger-metadata middleware.

All Volos modules including Cache, Quota, and OAuth may be configured and tied to Swagger operations using configuration similar to the code that you would use to programmatically drive the Volos middleware.

This can be included in an Apigee-127 project as simply as this:

var a127 = require('a127-magic');
app.use(a127.middleware());

Configuration

The Volos Swagger Configuration is done directly in the Swagger 2.x document:

The following sections discuss examples from this swagger yaml file.

Important: Be sure to include any referenced Volos modules in your package.json and run npm install.

Services

The "x-a127-services" vendors extension section defines how the modules that will be referenced in the other sections of this file will be instantiated and configured. The basic idea is that you simply define the array of parameters that would have been passed in to create the Volos module had you done it programmatically.

For example, volos-cache-memory requires a name and a hash of options. If we want to create and use a cache named "memCache" that has a time-to-live (ttl) of 1000ms, we'd do so like this:

x-a127-services:
  cache:
    provider: "volos-cache-memory"
    options:
      name: "memCache"
      ttl: 10000

Note: The key (name) for this resource is "cache". This is the name that will be used later to refer to this cache, not "memCache" - which the provider's name for the cache.

Similarly, we create a volos-quota-memory ("quota") and volos-oauth-redis ("oauth2") reference in this example:

quota:
  provider: "volos-quota-memory"
  options:
    timeUnit: "minute"
    interval: 1
    allow: 2
oauth2:
  provider: "volos-oauth-apigee"
  options:
    encryptionKey: "This is the key to encrypt/decrypt stored credentials"
  

Paths & Operations

Cache & Quota middleware

Volos modules are applied in a Swagger path or operation with the "x-a127-apply" extension. In the example below, we have examples of applying a cache ("cache") and a quota ("quota"). In each case, we're applying with the Volos defaults.

paths:
  /cached:
    x-a127-apply:
      cache: {}
  /quota:
    x-a127-apply: 
      quota: {}

OAuth authorization

Once you've defined a Volos OAuth provider in x-a127-services, you may use standard Swagger 2.0 authorization constructs to delegate to it. This is done by creating a SecurityDefinition like so:

securityDefinitions:
  oauth2:
    type: oauth2
    scopes: []
    flow: accessCode
    authorizationUrl: ignored
    tokenUrl: ignored

SecurityDefinition Notes:

  • The SecurityDefinition name (in this case, "oauth2") MUST match the name of the x-a127-service name.
  • "type" MUST be "oauth2"
  • The remainder of the fields do not affect operation and are for documentation only.

Once you've defined the SecurityDefinition, you can apply it to your operations. The following will require a valid OAuth token for the scope "scope1" on the "GET /secured" operation using the provider called "oauth2":

/secured:
  get:
  security:
    -
      oauth2:
        - scope1

Deprecated: Volos authorization may also applied in a Swagger path or operation with the "x-a127-authorizations" extension. The example below performs the same function as above: It requires that the request is using an OAuth Token validated by the "oauth2" resource requiring the "scope1" scope. (Additional scopes could be required
by space-delimiting them or using an array.)

/secured:
  x-a127-authorizations: 
    oauth2: 
      scope: "scope1"