tsoa.json

Overview

The `tsoa.json` file is a configuration file used by **tsoa**, a popular TypeScript framework that automatically generates OpenAPI (Swagger) specifications and routes based on TypeScript controllers and models. This file defines key settings for how tsoa scans, processes, and outputs API metadata and routes for the project.

Specifically, it configures:

This configuration is essential for integrating tsoa into the build and development workflow, enabling automatic API documentation generation and route wiring based on TypeScript code annotations.


Detailed Explanation of Configuration Properties

1. entryFile: string


2. noImplicitAdditionalProperties: string


3. controllerPathGlobs: string[]


4. spec: object


5. routes: object


6. ignore: string[]


Usage Example

Given this configuration, when you run tsoa commands like `tsoa spec` or `tsoa routes`, the tool will:

  1. Start from src/app.ts.

  2. Search all files matching src/**/controller.ts.

  3. Generate OpenAPI 3.0 specification JSON files inside the src directory.

  4. Generate routes files inside the src directory.

  5. Throw an error if request/response models contain unexpected extra properties.

  6. Ignore files in node_modules and dist folders.


Important Implementation Details


Interaction with Other Parts of the System


Visual Diagram

Below is a flowchart representing how `tsoa.json` configures the workflow of tsoa tool within the project:

flowchart TD
    A[Start: Run tsoa command] --> B[Read tsoa.json]
    B --> C{Locate Entry File}
    C --> D[src/app.ts]
    B --> E{Find Controllers}
    E --> F[Files matching "src/**/controller.ts"]
    B --> G[Ignore files: node_modules, dist]
    B --> H[Set Validation Mode: throw-on-extras]
    B --> I[Set Spec Output Directory: src]
    B --> J[Set Routes Output Directory: src]
    D --> K[Analyze TypeScript Types]
    F --> K
    K --> L[Generate OpenAPI Spec (v3)]
    K --> M[Generate Routes]
    L --> N[Save spec files in src/]
    M --> O[Save routes files in src/]
    N --> P[Use Spec for Docs, SDKs]
    O --> Q[Import routes in app.ts]

Summary

The `tsoa.json` file is a crucial configuration point for the tsoa framework, specifying how API routes and documentation are generated from TypeScript source code. It defines entry points, file scanning rules, validation strictness, and output locations for specs and routes. Proper configuration ensures seamless integration of automated API documentation and routing into the project, supporting maintainable and type-safe API development.