Adonis Open Swagger

Components

Generate reusable schema components for openapi-typescript

Components configuration allows you to generate reusable schema definitions in your OpenAPI specification. These schemas are used by openapi-typescript to generate TypeScript types for your API models.

What are Components?

Components are reusable schema definitions that appear in the components.schemas section of your OpenAPI specification. When you run openapi-typescript, these schemas are converted into TypeScript interfaces that you can use throughout your application for type-safe API calls.

Configuration

Define component schema sources in your config/swagger.ts file:

config/swagger.ts
import { defineConfig } from "adonis-open-swagger";

export default defineConfig({
  components: {
    include: ["app/models/*.ts", "app/schemas/index.ts"],
    exclude: ["app/models/internal/*.ts"],
  },
});

Components Properties

The components object supports the following properties:

include (required)

Array of file paths or glob patterns specifying which files contain schema definitions to include in the components schema.

{
  components: {
    include: ["app/models/*.ts", "app/schemas/index.ts"];
  }
}

exclude (optional)

Array of glob patterns to exclude specific files from the components schema.

{
  components: {
    exclude: ["app/models/internal/*.ts"];
  }
}

Last updated on