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

@tralsejr/dino-docs-api

v0.0.8

Published

DinoDocs API.

Downloads

13

Readme

🦖 DinoDocs API

NPM Version NPM Downloads

Welcome to DinoDocs API – the ultimate tool for combining JSDoc documentation with middleware validation for your Express applications. DinoDocs API makes your APIs clear and reliable, just like a T-Rex’s roar. 🦕

🌟 Features

  • Integrated Documentation and Validation: Seamlessly combine your API documentation with validation rules in one place.
  • Schema Generation: Automatically generate JSON schemas from your DinoDocs documentation.
  • DinoDocs API Kits: Utilize DinoDocs API Kits to transform the generated schema into implemented validation.

📦 Installation

To add DinoDocs API to your project, run:

npm install @tralsejr/dino-docs-api

🚀 Usage

Transform your Express application with DinoDocs API for better documentation and validation.

Step 1: Before DinoDocs API

Here's how a basic Express application looks without DinoDocs API. You have your routes and middleware, but the documentation and validation are separate and not automatically aligned:

import express from "express";
import { validationMiddleware } from "./middleware.mjs";
import rootController from "./controllers/root.mjs";

const app = express();

app.use(express.json());

/**
 * @api {get} / Root route
 * @apiName GetRoot
 * @apiGroup Root
 * @apiSuccess {String} message Success message
 * @apiSuccessExample {json} Success-Response:
 *   HTTP/1.1 200 OK
 *   {
 *     "message": "Root route accessed successfully."
 *   }
 */
app.get("/", validationMiddleware, rootController);

app.listen(3000, () => {
  console.log("Listening on port 3000.");
});

Step 2: Adding DinoDocs API

With DinoDocs API, you can document and validate your routes simultaneously. This integration ensures your documentation is always in sync with your validation logic.

Here’s an enhanced version with DinoDocs API:

import express from "express";
import rootController from "./controllers/root.mjs";

const app = express();

app.use(express.json());

/**
 * @dinoValidator GET / - Root route.
 * @dinoBody {number} foo - This is foo. (range=1-100)
 * @dinoParams {string} bar - This is bar.
 * @dinoQuery {string} [zen] - Optional query parameter.
 */
app.get("/", rootController);

app.listen(3000, () => {
  console.log("Listening on port 3000.");
});

Step 3: Generating Documentation Schema

To generate a JSON schema from your DinoDocs documentation, use the fossilize function. This function converts your documentation into a schema that can be used for further validation.

// test.mjs

import { fossilize } from "@tralsejr/dino-docs-api";

const result = await fossilize("./app.mjs");
console.log(JSON.stringify(result, null, 2));

Example Output

After running the fossilize function, you will get a JSON schema representing your API documentation and validation rules:

[
  {
    "method": "GET",
    "path": "/",
    "description": "Root route.",
    "body": [
      {
        "key": "foo",
        "type": "number",
        "optional": false,
        "description": "This is foo.",
        "constraints": {
          "isInt": {
            "options": {
              "min": 1,
              "max": 100
            }
          }
        }
      }
    ],
    "params": [
      {
        "key": "bar",
        "type": "string",
        "optional": false,
        "description": "This is bar."
      }
    ],
    "query": [
      {
        "key": "zen",
        "type": "string",
        "optional": true,
        "description": "Optional query parameter."
      }
    ]
  }
]

Step 4: Implementing Validation with JSDoc API Kits

Transform the generated schema into actual validation logic in your API with our JSDoc API Kits.

📖 Resources

Documentation for DinoDocs JSDoc Documentation for the fossilize method

🎉 Contribute

Want to help? We welcome contributions! If you have suggestions, bug reports, or improvements, please open an issue or submit a pull request on GitHub.

📝 License

DinoDocs API is licensed under the MIT License.

With DinoDocs API, your API documentation will be as legendary as a dinosaur. 🌟🦖