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

ah-oas-plugin

v0.2.2

Published

Generate OpenApi Specification documentation for ActionHero

Downloads

14

Readme

ah-oas-plugin

npm version

Generate OpenApi Specification documentation for ActionHero

screenshot

Install and setup

$ npm install ah-oas-plugin --save

Make sure you add the plugin to config/plugins.js:

'use strict'

const path = require('path')

exports['default'] = {
  plugins: (api) => {
    return {
      'ah-oas-plugin': { path: path.join(__dirname, '../node_modules/ah-oas-plugin') }
    }
  }
}

You can now access your project documentation on: http://127.0.0.1:8080/public/oas

Usage

This plugin will analyse your project's actions, generate a OpenApi Specification file on your public folder and display it with Swagger UI.

Here's an action example:

'use strict'

const { Action, api } = require('actionhero')

module.exports = class Status extends Action {
  constructor () {
    super()

    this.name = 'status'
    this.description = 'I will return some basic information about the API'

    this.middleware = [
      'validateJwtMiddleware'
    ]

    this.headers = {
      'Accept-Language': {
        description: 'Which languages the client is able to understand, and which locale variant is preferred.',
        required: false,
        schema: {
          type: 'string'
        },
        example: 'en-US'
      }
    }

    this.responseSchemas = {
      '200': {
        description: 'OK.',
        schema: {
          type: 'object'
        }
      }
    }

    this.inputs = {
      email: {
        description: 'User type.',
        required: true,
        type: 'string',
        example: '[email protected]'
      },
      age: {
        description: 'User age.',
        required: true,
        type: 'integer',
        example: 30
      }
    }

    this.tags = ['Core']

    this.security = [
      {
        'api_key': []
      }
    ]
  }

  async run (data) {
    // ...
  }
}

Configuration

Edit values on config/oas.js:

'use strict'

exports.default = {
  oas: (api) => {
    return {
      // Directory to render client-side JS.
      // Path should start with "/" and will be built starting from `api.config.general.paths.public`.
      openApiDocumentPath: '/',
      // The name of the OpenAPI document JSON file.
      // Do not include the file exension.
      // Set to `undefined` to not save the OpenAPI document JSON file on boot.
      openApiDocumentName: 'openapi',
      // Should be changed to hit www.yourserver.com.  If this is null, defaults to ip:port from
      // internal values or from hostOverride and portOverride.
      baseUrl: '127.0.0.1:8080',
      // Specify routes that don't need to be displayed
      ignoreRoutes: [],
      // Set true if you want to organize actions by version
      groupByVersionTag: false,
      // In some cases where actionhero network topology needs to point elsewhere.
      // If null, uses api.config.oas.baseUrl
      hostOverride: null,
      // Same as above, if null uses the internal value set in config/server/web.js
      portOverride: null,

      // Extended documentation for the whole API.
      // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#externalDocumentationObject
      // Set to null if not needed.
      apiDocumentation: {
        description: 'Find more info about the API here',
        url: 'https://docs.actionherojs.com'
      },
      // Information about tags, you can add info about any version tag (including version tags).
      // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#tagObject
      // Set to null if not needed.
      tagsInfo: {
        '1': {
          description: 'Version 1 of the API',
          externalDocs: {
            description: 'Find more info here',
            url: 'https://docs.actionherojs.com/'
          }
        },
        'Core': {
          description: 'Core actions'
        }
      },
      // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#serverObject
      servers: null,
      // https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#securityRequirementObject
      security: {
        'api_key': {
          type: 'apiKey',
          name: 'Authorization',
          'in': 'header'
        },
        'petstore_auth': {
          'type': 'oauth2',
          'flows': {
            'implicit': {
              'authorizationUrl': 'http://example.org/api/oauth/dialog',
              'scopes': {
                'write:pets': 'modify pets in your account',
                'read:pets': 'read your pets'
              }
            }
          }
        }
      }
    }
  }
}