All skills
antfu avatar

/nitro

@d02c484 official
by Anthony Fuantfu/skills5.9k stars
335

Nitro is the framework-agnostic server toolkit (powering Nuxt) for building and deploying web servers anywhere. Use when working with nitro.config, server routes/event handlers, route rules, caching, storage, tasks, websockets, or deploying to Node/Bun/Deno/Cloudflare/Vercel.

Use this Skill: https://skilld.dev/gh/antfu/skills/nitro

This session only. Nothing lands on disk.

referencesfeatures-openapi.md

≈886 tokens on demand. Your agent reads this file only when SKILL.md points to it.

OpenAPI

Nitro scans route handlers, reads metadata from defineRouteMeta, and generates an OpenAPI 3.1.0 spec plus interactive UIs (Scalar and Swagger UI). Experimental — enable the flag.

import { defineConfig } from "nitro";

export default defineConfig({
  experimental: { openAPI: true },
});

Dev endpoints once enabled:

Endpoint Description
/_openapi.json OpenAPI 3.1.0 JSON spec
/_scalar Scalar API reference UI
/_swagger Swagger UI

Route metadata

defineRouteMeta is a build-time macro (no runtime overhead). Its openAPI field accepts a standard OpenAPI Operation Object.

import { defineRouteMeta, defineHandler } from "nitro";

defineRouteMeta({
  openAPI: {
    tags: ["users"],
    description: "Get a user by ID",
    parameters: [
      { in: "query", name: "include", schema: { type: "string" } },
    ],
    responses: {
      200: {
        description: "User found",
        content: {
          "application/json": {
            schema: { $ref: "#/components/schemas/User" },
          },
        },
      },
      404: { description: "Not found" },
    },
    // Hoist reusable schemas into the top-level components section
    $global: {
      components: {
        schemas: {
          User: {
            type: "object",
            properties: {
              id: { type: "string" },
              name: { type: "string" },
              email: { type: "string", format: "email" },
            },
          },
        },
      },
    },
  },
});

export default defineHandler((event) => {
  const { id } = event.context.params!;
  return { id, name: "Alice", email: "alice@example.com" };
});
  • Route params ([id]/:id) become OpenAPI path parameters automatically — only declare extra query/header params.
  • Auto-tagging by prefix: /api/ → API Routes, /_ → Internal, others → App Routes. Override with tags.
  • Define a schema once under $global.components.schemas, reference it elsewhere with $ref.

Configuration

import { defineConfig } from "nitro";

export default defineConfig({
  experimental: { openAPI: true },
  openAPI: {
    meta: { title: "My API", description: "...", version: "2.0.0" },
    route: "/_docs/openapi.json",          // override JSON path
    ui: {
      scalar: { route: "/_docs/scalar", theme: "purple" },
      swagger: false,                       // disable a UI
    },
    production: "runtime",                   // expose in production
  },
});

production values:

Value Behavior
false (default) Disabled in production.
"runtime" Generated per request (allows middleware/dynamic info).
"prerender" Generated at build time, served as a static file (most efficient).

If exposed in production, protect these endpoints with authentication.

Key Points

  • Requires experimental.openAPI: true; configure via the top-level openAPI option.
  • defineRouteMeta (from nitro) is a build-time macro — zero runtime cost.
  • Path params are inferred from the route; declare only additional parameters.
  • OpenAPI is dev-only by default; opt into "runtime"/"prerender" for production and secure the routes.
<!-- Source references: - https://nitro.build/docs/openapi - https://nitro.build/config -->

Source: SKILL.md on GitHub

No alerts3d3 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The skill provides comprehensive documentation and guidelines for Nitro v3, a server toolkit for building web applications. It includes security best practices like using parameterized queries to prevent SQL injection and authenticating task execution. No security issues were detected.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: LOW · No issues

Signed by skilld at d02c484. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 days ago.

Activeupdated 4 days ago
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.9.25",
  "source": "Generated from https://github.com/nitrojs/nitro, scripts located at https://github.com/antfu/skills"
}

README badge

README badge for antfu/skills/nitro