Skip to content

Type-safe Express.js routes with automatic OpenAPI documentation generation.

License

Notifications You must be signed in to change notification settings

casantosmu/tyex

Repository files navigation

tyex 🚀

Type-safe Express.js routes with automatic OpenAPI documentation generation. Zero config, zero hassle.

npm license codecov

Why tyex?

  • Full Type Safety: Leverage TypeScript's type system for your Express routes
  • 📚 Automatic OpenAPI: Generate OpenAPI documentation directly from your route definitions
  • 🛡️ Runtime Validation: Uses AJV for runtime type checking
  • 🔌 Express Compatible: Drop-in replacement for Express Router
  • 🪶 Lightweight: Minimal overhead, maximum value

Quick Start

import { Type } from "@sinclair/typebox";
import express from "express";
import tyex from "tyex";

const app = express();
const t = tyex(app);

// Define your route with types and documentation in one place
t.get(
  "/hello",
  {
    summary: "Say hello",
    responses: {
      200: {
        description: "Success",
        content: {
          "application/json": {
            schema: Type.Object({
              message: Type.String(),
            }),
          },
        },
      },
    },
  },
  (req, res) => {
    res.json({ message: "Hello, World!" });
  },
);

// Get OpenAPI documentation
const docs = t.openapi({
  info: {
    title: "My API",
    version: "1.0.0",
  },
});

Installation

npm install express @sinclair/typebox ajv tyex

Examples

Check out our example project for a complete CRUD API implementation.

Contributing

PRs are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

MIT