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

openapi-express-server-gen

v1.0.4

Published

Generate a typed Express server skeleton from an OpenAPI 3.x spec

Downloads

814

Readme

openapi-express-server-gen

Generates a typed Express server skeleton from an OpenAPI 3.x spec. Given a spec, it writes five files into an output directory:

| File | Description | |------|-------------| | models.ts | TypeScript types for all schemas | | decoders.ts | Runtime validators for all schemas | | types.ts | AuthHandlers and Application interfaces | | index.ts | registerRoutes function wiring routes to the Application interface | | utils/ | Fixed infrastructure: requestHandler, appError, bearerAuthWrapper |

types.ts and index.ts are regenerated on every run and should not be edited manually. utils/ is also overwritten on every run. models.ts and decoders.ts are produced by openapi-typescript-validator.

Requirements

  • Node.js >= 18

Installation

npm install --save-dev openapi-express-server-gen
npm install ajv
npm install ajv-formats  # only required if addFormats is true (the default); v2 and v3 are both supported

ajv and ajv-formats are runtime dependencies of the generated decoders.ts and must be installed in the consuming project.

Usage

CLI

npx openapi-express-server-gen --spec ./openapi.yaml --out ./src/_generated/server

Both flags are optional:

| Flag | Default | |------|---------| | --spec | ./openapi.yaml | | --out | ./src/_generated/server |

Programmatic

const { generate } = require('openapi-express-server-gen');

await generate({
  schemaFile: './openapi.yaml',
  directory: './src/_generated/server',
});

Options:

| Option | Type | Default | Description | |--------|------|---------|-------------| | schemaFile | string | — | Path to the OpenAPI YAML or JSON spec | | directory | string | — | Output directory | | schemaType | 'yaml' \| 'json' | auto-detected | Override file type detection | | addFormats | boolean | true | Pass AJV format validators to the generated decoders |

Config file

Options can also be set in openapi-server-gen.config.json at the project root, or under an "openapi-server-gen" key in package.json. CLI flags take precedence over config file values.

{
  "spec": "./openapi.yaml",
  "out": "./src/_generated/server"
}

What gets generated

Given a spec with a BearerAuth security scheme and the following operations:

POST /transactions   # query param + request body → 201 response
POST /fileUpload     # request body only → 200 response
GET  /fileUpload/{fileId}   # path param only → 200 response
GET  /documents/{documentId}  # integer path param → 200 response

types.ts

export type AuthHandlers<TBearerAuth> = {
    BearerAuth: (req: Request, scopes: string[]) => Promise<TBearerAuth>;
};

export type Application<TBearerAuth> = {
    createTransaction: (auth: TBearerAuth, parameters: { mode?: CreationMode }, payload: TransactionInput) => Promise<{status: 201, body: TransactionCreatedResponse}>;
    uploadFile: (auth: TBearerAuth, payload: FileUploadRequest) => Promise<{status: 200, body: FileUploadResponse}>;
    getFileUploadStatus: (auth: TBearerAuth, parameters: { fileId: string }) => Promise<{status: 200, body: FileUploadStatusResponse}>;
    getDocument: (auth: TBearerAuth, parameters: { documentId: number }) => Promise<{status: 200, body: DocumentInfo}>;
};

index.ts

export function registerRoutes<TBearerAuth>(
    app: Express,
    authHandler: AuthHandlers<TBearerAuth>,
    application: Application<TBearerAuth>
): void { ... }

Consuming the generated code

Implement the Application interface with your business logic, wrap your auth with bearerAuth from utils, then pass both to registerRoutes:

import express from 'express';
import { registerRoutes } from './_generated/server';
import { bearerAuth } from './_generated/server/utils';

const app = express();
app.use(express.json());

registerRoutes(app, {
    BearerAuth: bearerAuth(async (token) => {
        // validate token, return your auth object
    }),
}, application);

Limitations

  • Only application/json request and response bodies are supported
  • Request and response body schemas must be named $refs — inline schemas are not supported
  • Path and query parameters with object or array schemas are skipped
  • Operations without a security requirement are not yet supported and will be omitted from index.ts
  • Only OpenAPI 3.x is supported