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

@danceroutine/tango-openapi

v1.10.1

Published

OpenAPI generation for Tango resources

Downloads

1,462

Readme

@danceroutine/tango-openapi

@danceroutine/tango-openapi generates OpenAPI 3.1 documents from Tango resource instances. It works best when an application already expresses its HTTP contract through ModelViewSet, GenericAPIView, or APIView.

Applications usually keep a small openapi.ts module that instantiates the resources they want to document, passes them through the descriptor helpers, and serves the generated document through Express or Next.js.

Install

pnpm add @danceroutine/tango-openapi

Use this package when you want to:

  • generate an OpenAPI 3.1 document from Tango resources
  • derive request and response schemas from Zod-backed resource contracts
  • publish a JSON document to Swagger UI, client generators, or external tooling

Quick start

import { z } from 'zod';
import {
    describeAPIView,
    describeGenericAPIView,
    describeViewSet,
    generateOpenAPISpec,
    type OpenAPISpec,
} from '@danceroutine/tango-openapi';
import { HealthAPIView, PostDetailAPIView, PostViewSet } from './resources';

export function createOpenAPISpec(): OpenAPISpec {
    return generateOpenAPISpec({
        title: 'Blog API',
        version: '1.0.0',
        description: 'OpenAPI document generated from Tango resource instances.',
        resources: [
            describeViewSet({
                basePath: '/api/posts',
                resource: new PostViewSet(),
            }),
            describeGenericAPIView({
                resource: new PostDetailAPIView(),
                detailPath: '/api/posts-generic/{id}',
            }),
            describeAPIView({
                path: '/api/healthz',
                resource: new HealthAPIView(),
                methods: {
                    GET: {
                        summary: 'Health check',
                        responseSchema: z.object({
                            status: z.literal('ok'),
                        }),
                    },
                },
            }),
        ],
    });
}

describeViewSet() documents the standard CRUD surface and any custom actions the viewset exposes. describeGenericAPIView() documents collection and detail routes for a generic resource. describeAPIView() covers fully custom endpoints where application code supplies the operation metadata directly.

The generated object is ready to publish through whichever host framework owns your HTTP layer.

Express:

import { createOpenAPISpec } from './openapi';

app.get('/api/openapi.json', (_req, res) => {
    res.json(createOpenAPISpec());
});

Next.js App Router:

import { createOpenAPISpec } from '@/lib/openapi';

export async function GET(): Promise<Response> {
    return Response.json(createOpenAPISpec());
}

What the generator emits

For a ModelViewSet, generateOpenAPISpec() emits:

  • GET /<path>
  • POST /<path>
  • GET /<path>/{id}
  • PUT /<path>/{id}
  • PATCH /<path>/{id}
  • DELETE /<path>/{id}

When the viewset defines custom actions, the generator also emits those routes using the resolved action paths from the resource itself.

For GenericAPIView, the generator documents whichever collection and detail paths the descriptor supplies. For plain APIView, the generator uses the manual operation metadata passed to describeAPIView().

The package also generates component schemas from Tango model metadata and Zod schemas when those are available through the resource contract.

Current boundary

The package documents Tango resources directly and covers the built-in CRUD surface, generic view routes, and custom action paths. Richer custom action request and response details still come from explicit overrides, and plain APIView routes still need manual method metadata because Tango cannot infer those HTTP contracts from the class alone.

generateSchemaFromModel() and generateSchemaFromZod() remain useful when an application needs schema generation outside full document generation.

Public API

The root export includes:

  • generateOpenAPISpec()
  • describeViewSet()
  • describeGenericAPIView()
  • describeAPIView()
  • generateSchemaFromModel()
  • generateSchemaFromZod()
  • mapTypeToOpenAPI()

The root export is enough for normal application use. The domain, generators, and mappers subpaths are useful when you want a narrower import boundary.

Documentation

Development

pnpm --filter @danceroutine/tango-openapi build
pnpm --filter @danceroutine/tango-openapi typecheck
pnpm --filter @danceroutine/tango-openapi test

For the wider contributor workflow, use:

License

MIT