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

api-annotation

v1.0.2

Published

like java annotation, using comments annotation, generate both router binding script and apidoc

Downloads

1,005

Readme

api-annotation

like java annotation, using comments annotation, generate both router binding script and apidoc

cli usage

api-annotation -o auto_router.js --doc ./document --api-version 1.0.0

programmable

var apiAnn = require('api-annotation');

apiAnn.process(dir, (err, data) => {

  // gen router file
  apiAnn.genRouter(data, {

  }, (err) => {
    /**
     * optional, only if you need custom the output router file
     */
    tpl: function(data) {},
    routerFile: '', // router_file_path
    version: '' // api version
  });

  // gen api document
  apiAnn.genDocument(data, {
    docPath: '',
    version: '',
    hook: () => {} // optional
  }, (err) => {

  });
  // gen api list json
  apiAnn.genApiList(data, {
    apiListPath: '',
    version: ''
  }, (err) => {

  });
});

Syntax

controller file

// controllers/test.js
/**
 * @api {get} /api/user/:id
 * @name User.getUser
 * @desc
 *
 * @params
 *   id
 *
 * @query
 *   limit {Number} maxRow in result
 *   sortBy {String} sort field
 *
 * @body:json
 *   user {Object} D+的用户对象
 *     name {String}
 *     id {Number}
 */
exports.hello = function (req, callback) {

};

@api [required]

define the api path and support method

// full pattern
@api {method} /url

// in short, default method is `GET`
@api /url

@name [optional]

name and group the api, just for display in apidoc

@name groupName.apiName
@name group0.group1.groupXXXX.apiName

@description / @desc

you can either using @desc or @description

@desc
  your desc here

@description
  your desc here

besides, the content before @api will merge into desc for example:

this is a desc too
@api /test

@desc
  this is a test api

the finally desc will be :

this is a test api
this is a desc too

@query [optional]

the query object from url's queryString

@query
  username {String} the target username
  resourceId {Number} the resource id
  • each properties takes a line
  • each line contains: propertyName, propertyType, description

@body [optional]

@body is same as query

take a look at more complicate example

@body:json
  user {Object} Class User
    name {String} user nick
    id {Number} user id
  group
    groupName {String} group name
    groupId {Number} group idins

the code below means:

  • body is a json string, you need add mime content-type when query this api
  • pay attension to the indention, it means sub properties

test

# run test
npm test

# create syntax case
make syntaxCase case=00x

Appendix: all annotation token

@api
@name
@json
@description
@desc
@params
@query
@body
@success
@failure
@error
@private
@internal
@public
@disable