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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@triadjs/openapi

v0.2.10

Published

OpenAPI 3.1 document generator for Triad routers

Readme

@triadjs/openapi

Generates OpenAPI 3.1 documents from a Triad router. Named models become $ref entries in components/schemas, bounded contexts become documented tags, and the output serializes to both YAML and JSON.

Install

npm install @triadjs/openapi

Quick Start

import { t, endpoint, createRouter } from '@triadjs/core';
import { generateOpenAPI, toYaml, toJson } from '@triadjs/openapi';

const Pet = t.model('Pet', {
  id:   t.string().format('uuid'),
  name: t.string(),
});

const createPet = endpoint({
  name: 'createPet',
  method: 'POST',
  path: '/pets',
  summary: 'Create a pet',
  request: { body: Pet.omit('id') },
  responses: {
    201: { schema: Pet, description: 'Created' },
  },
  handler: async (ctx) => ctx.respond[201]({ id: '1', name: 'Buddy' }),
});

const router = createRouter({ title: 'Petstore', version: '1.0.0' });
router.add(createPet);

const doc = generateOpenAPI(router);

console.log(toYaml(doc));
// or
console.log(toJson(doc));

The generated document includes the full paths, components/schemas, info, servers, and tags sections expected by any OpenAPI 3.1 consumer.

Features

Named models become $ref

Any schema created with t.model() is emitted once under components/schemas and referenced via $ref everywhere it appears. Inline shapes (anonymous objects passed to request.params, request.query, etc.) are expanded in place.

Bounded contexts become tags

When endpoints are registered inside a router.context(), the context name is added as an OpenAPI tag with its description. Endpoints inside a context are auto-tagged.

router.context('Adoption', {
  description: 'Manages the pet adoption lifecycle',
  models: [Pet],
}, (ctx) => {
  ctx.add(createPet, getPet);
});

Produces:

tags:
  - name: Adoption
    description: Manages the pet adoption lifecycle

File uploads

Endpoints with t.file() fields in the request body automatically use multipart/form-data as the content type.

Empty responses

Responses declared with t.empty() (e.g. 204 No Content) omit the content key, matching the HTTP and OpenAPI specification for bodyless responses.

Path conversion

Express-style :param paths are converted to OpenAPI {param} format automatically.

YAML and JSON serialization

import { toYaml, toJson } from '@triadjs/openapi';

toYaml(doc);          // OpenAPI-compatible YAML string
toJson(doc);          // pretty-printed JSON (default indent: 2)
toJson(doc, 0);       // compact JSON

CLI

The Triad CLI provides a docs command that loads your router and generates the OpenAPI document:

npx triad docs --format yaml
npx triad docs --format json

API Reference

generateOpenAPI(router, options?)

Returns an OpenAPIDocument object (OpenAPI 3.1.0).

| Parameter | Type | Description | |-----------|------|-------------| | router | Router | A Triad router with registered endpoints | | options.includeUntagged | boolean | Include endpoints with empty tags (default: true) |

toYaml(doc)

Serializes an OpenAPIDocument to a YAML string.

toJson(doc, indent?)

Serializes an OpenAPIDocument to a JSON string. indent defaults to 2.

convertPath(path)

Converts Express-style :param path segments to OpenAPI {param} format.

Links