Skip to content

KosmoJS can automatically generate OpenAPI 3.1 specifications from your API routes.

The generator analyzes your route structure, type definitions, and validation schemas to produce a complete, standards-compliant OpenAPI spec.

Enable OpenAPI generator in your source folder's vite.config.ts:

typescript
import { join } from "node:path";

import devPlugin from "@kosmojs/dev";
import {
  apiGenerator,
  fetchGenerator,
  typeboxGenerator,
  openapiGenerator, 
} from "@kosmojs/generators";

import defineConfig from "../../vite.base";
import { apiurl, baseurl } from "./config";

const openapiConfig = { 
  // ...
};

export default defineConfig(import.meta.dirname, {
  base: join(baseurl, "/"),
  server: {
    port: 4000,
  },
  plugins: [
    devPlugin(apiurl, {
      generators: [
        apiGenerator(),
        fetchGenerator(),
        typeboxGenerator(),
        openapiGenerator(openapiConfig), 
      ],
    }),
  ],
});

Released under the MIT License.