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

@asenajs/asena-openapi

v1.0.0

Published

OpenAPI 3.1 spec generation for AsenaJS - automatic schema extraction from validators and route decorators

Downloads

62

Readme

@asenajs/asena-openapi

Version License: MIT Bun Version

Automatic OpenAPI 3.1 spec generation for AsenaJS — zero config, uses your existing validators.

Your existing @Controller routes and validator schemas (json(), query(), param(), response()) are automatically converted to a full OpenAPI specification. No extra annotations needed.

Features

  • Zero Config - Extracts schemas from existing validators, no extra annotations needed
  • OpenAPI 3.1 - Generates JSON Schema draft-2020-12 compatible spec
  • Zero Runtime Dependencies - Only peer deps (asena, reflect-metadata, zod)
  • Built-in Swagger UI - CDN-based UI page, no npm install required
  • @Hidden Decorator - Class and method level exclusion from spec
  • Zod v4 Native - Uses z.toJSONSchema() for accurate conversion
  • Pluggable Converters - SchemaConverter interface for custom schema types
  • IoC Integrated - PostProcessor pattern, auto-discovers controllers during bootstrap

Requirements

Installation

bun add @asenajs/asena-openapi

Quick Start

import { OpenApi, OpenApiPostProcessor } from '@asenajs/asena-openapi';

@OpenApi({
  info: { title: 'My API', version: '1.0.0' },
  path: '/api/openapi',
  ui: true, // Swagger UI at /api/openapi/ui
})
export class AppOpenApi extends OpenApiPostProcessor {}

Asena automatically discovers it — that's it.

Now:

  • GET /api/openapi → OpenAPI 3.1 JSON spec
  • GET /api/openapi/ui → Swagger UI page

How It Works

The OpenApiPostProcessor automatically:

  1. Intercepts every @Controller during IoC setup
  2. Extracts route metadata (@Get, @Post, @Put, @Delete)
  3. Resolves validators and converts their Zod schemas to JSON Schema
  4. Generates a complete OpenAPI 3.1 spec
  5. Registers GET endpoints on the adapter for spec and Swagger UI

Your existing validators do double duty — they validate requests AND generate documentation:

@Middleware({ validator: true })
export class CreateUserValidator extends ValidationService {
  // → requestBody (application/json)
  json() {
    return z.object({
      name: z.string().min(1),
      email: z.string().email(),
    });
  }

  // → query parameters
  query() {
    return z.object({
      page: z.coerce.number().optional(),
    });
  }

  // → path parameters
  param() {
    return z.object({
      id: z.string().uuid(),
    });
  }

  // → response schemas by status code
  response() {
    return {
      201: z.object({ id: z.string(), name: z.string() }),
      400: { schema: z.object({ error: z.string() }), description: 'Validation error' },
    };
  }
}

@Hidden

Hide controllers or individual routes from the spec:

// Hide entire controller
@Hidden()
@Controller('/internal')
export class InternalController { ... }

// Hide single route
@Controller('/api')
export class ApiController {
  @Hidden()
  @Get('/health')
  healthCheck() {}

  @Get('/users')  // this route IS in the spec
  listUsers() {}
}

Configuration

OpenApiDecoratorOptions

@OpenApi({
  info: {
    title: 'My API', // Required
    version: '1.0.0', // Required
    description: 'My app', // Optional
  },
  path: '/api/openapi', // Default: '/openapi'
  ui: true, // Default: false — enables Swagger UI at {path}/ui
  servers: [
    // Optional
    { url: 'https://api.example.com', description: 'Production' },
  ],
  converters: [
    // Default: [ZodSchemaConverter]
    new ZodSchemaConverter(),
  ],
})
export class AppOpenApi extends OpenApiPostProcessor {}

Swagger UI

When ui: true, a Swagger UI page is served at {path}/ui. It loads from CDN — zero npm dependencies:

  • Uses swagger-ui-dist@5 from unpkg CDN
  • No build step required
  • Works in development and production

OpenApiGenerator (Legacy)

For manual spec generation without the PostProcessor:

import { OpenApiGenerator, ZodSchemaConverter } from '@asenajs/asena-openapi';

const generator = new OpenApiGenerator({
  info: { title: 'My API', version: '1.0.0' },
  converters: [new ZodSchemaConverter()],
});

const spec = await generator.generate(server.coreContainer.container);

Contributing

Contributions are welcome! Please follow these guidelines:

  1. Maintain test coverage for critical paths
  2. Follow existing code style and linting rules
  3. Test with both Hono and Ergenecore adapters

Submit a Pull Request on GitHub.

License

MIT

Support

Issues or questions? Open an issue on GitHub.