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

@kakang/fastify-openapi

v2.0.2

Published

[![Continuous Integration](https://github.com/climba03003/fastify-openapi/actions/workflows/ci.yml/badge.svg)](https://github.com/climba03003/fastify-openapi/actions/workflows/ci.yml) [![Package Manager CI](https://github.com/climba03003/fastify-openapi/a

Downloads

72

Readme

@kakang/fastify-openapi

Continuous Integration Package Manager CI NPM version GitHub package.json version Coverage Status GitHub

This plugin provide automatic API documentation feature.

This project is relative new and the API structure may change rapidly. Please consider it before using in production.

Install

npm install @kakang/fastify-openapi --save

yarn add @kakang/fastify-openapi

Compare with fastify-swagger

Pros

  • Multi documentation support
  • Route constraints support
  • High flexibility on customizing behavior

Cons

  • Do not support $ref
  • Do not support Swagger 2.0
  • Do not support YAML

Usage

import { FastifyOpenAPI, OpenAPIPlugin }  from '@kakang/fastify-openapi'

fastify.register(FastifyOpenAPI, {
  // plugin
  plugins: [ OpenAPIPlugin ],
  // base document shared for multiple document
  // it should follow the format of OpenAPI 3.0
  document: {},
  // multi document customize property
  // it should follow the format of OpenAPI 3.0
  documents: {
    // it use key-value, for the multi document
    default: {}
  },
  // routes options for document and ui
  routes: {
    // prefix shared by all routes
    prefix: '/documentation',
    // config for each document
    documents: {
      // it use key-value, for the multi document
      default: {
        // ui path
        ui: '/',
        // document path
        document: '/openapi.json',
        // ui route option
        uiRouteOptions: {},
        // document route option
        documentRouteOptions: {}
      }
    }
  },
  // function to identify which document the route belong to
  routeBelongTo: function() { 
    return []
  },
})

Routes Options

fastify.get(
  '/',
  {
    // hide this route
    hide: false,
    // array of string
    tags: [''],
    // string
    summary: '',
    // string
    description: '',
    // key-value
    externalDocs: {},
    // string
    operationId: '',
    // json-schema
    params: {},
    // json-schema
    querystring: {},
    // json-schema
    headers: {},
    // json-schema
    cookies: {},
    // json-schema
    body: {},
    // json-schema
    response: {},
    // key-value
    callbacks: {},
    // boolean
    deprecated: false,
    // key-value
    security: {},
    // key-value
    servers: {},
  },
  async function() {}
)

Hooks

onPath

On Path hook is executed for generate OpenAPI OperationObject.

function plugin(instance) {
  /**
   * @param {DocumentGenerator} instance document generator
   * @param {RouteOptions|OperationObject} schema last hook result. If it is the first hook, it is the original schema.
   * @param {RouteOptions} originalSchema original schema
   * @param {object} additionalInformation additional information
   * @returns {OperationObject} operation object
   **/
  instance.addHook('onPath', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
}

onQuery, onParam, onHeader, onCookie

On Query, Param, Header and Cookie hook are executed for generate OpenAPI ParameterObject.

function plugin(instance) {
  /**
   * @param {DocumentGenerator} instance document generator
   * @param {ParameterSchema|ParameterObject} schema last hook result. If it is the first hook, it is the original schema.
   * @param {ParameterSchema} originalSchema original schema
   * @param {object} additionalInformation additional information
   * @returns {ParameterObject} operation object
   **/
  instance.addHook('onQuery', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
  instance.addHook('onParam', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
  instance.addHook('onHeader', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
  instance.addHook('onCookie', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
}

onBody

On Body hook is executed for generate OpenAPI RequestBodyObject.

function plugin(instance) {
  /**
   * @param {DocumentGenerator} instance document generator
   * @param {JSONSchema|RequestBodyObject} schema last hook result. If it is the first hook, it is the original schema.
   * @param {JSONSchema} originalSchema original schema
   * @param {object} additionalInformation additional information
   * @returns {RequestBodyObject} operation object
   **/
  instance.addHook('onPath', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
}

onResponse

On Response hook is executed for generate OpenAPI ResponsesObject.

function plugin(instance) {
  /**
   * @param {DocumentGenerator} instance document generator
   * @param {JSONSchema|RequestBodyObject} schema last hook result. If it is the first hook, it is the original schema.
   * @param {JSONSchema} originalSchema original schema
   * @param {object} additionalInformation additional information
   * @returns {ResponsesObject} operation object
   **/
  instance.addHook('onResponse', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
}

onTransform

On Transform hook is executed for generate valid schema.

function plugin(instance) {
  /**
   * @param {DocumentGenerator} instance document generator
   * @param {unknown} schema last hook result. If it is the first hook, it is the original schema.
   * @param {unknown} originalSchema original schema
   * @param {object} additionalInformation additional information
   * @returns {JSONSchema} operation object
   **/
  instance.addHook('onTransform', function(instance, schema, originalSchema, additionalInformation) {
    return schema
  })
}