tsoa.json


Overview

The `tsoa.json` file is a configuration file for the **tsoa** framework, a TypeScript OpenAPI (Swagger) tool used to automate the generation of API routes and OpenAPI specification files based on TypeScript decorators in controller files.

This JSON file outlines the key settings and behaviors for the tsoa CLI and runtime tools to:

In short, `tsoa.json` governs how tsoa interprets your TypeScript source code to generate API routes and OpenAPI documentation, acting as a bridge between your source code and runtime API routing and documentation.


Detailed Explanation of Configuration Properties

Property

Type

Description

Example/Notes

`entryFile`

`string`

Path to the main application entry point file where tsoa begins analysis.

"src/app.ts"

`noImplicitAdditionalProperties`

["throw-on-extras" \

"silently-remove-extras" \

"ignore"](/projects/291/69202)

`controllerPathGlobs`

`string[]`

Glob patterns specifying the locations of controller files containing decorated API route handlers.

["src/**/controller.ts"]

`spec`

`object`

Configuration object for OpenAPI specification generation.

See below

spec.outputDirectory

`string`

Directory where the OpenAPI spec JSON/YAML files will be generated.

`"src"`

spec.specVersion

`number`

OpenAPI specification version to generate (usually 2 or 3).

`3`

`routes`

`object`

Configuration for route generation.

See below

routes.routesDir

`string`

Directory where tsoa will generate route files based on controllers.

`"src"`

`ignore`

`string[]`

Glob patterns for files and folders to exclude from tsoa processing.

["**/node_modules/**", "**/dist/**"]


Explanation and Usage

entryFile

noImplicitAdditionalProperties

controllerPathGlobs

spec

routes

ignore


Implementation Details and Algorithms


Interaction with Other Parts of the System

In summary, this file is a central configuration hub that connects source code, build processes, API documentation generation, and routing automation in the overall software architecture.


Example Usage

If your project structure looks like:

src/
  app.ts
  userController.ts
  productController.ts
node_modules/
dist/

Run tsoa CLI commands such as:

tsoa routes
tsoa spec

These commands use this configuration to generate the routing and OpenAPI files accordingly.


Mermaid Diagram

Below is a flowchart representing the main configuration properties in `tsoa.json` and how they influence tsoa's workflow:

flowchart TD
    A[tsoa.json Configuration]
    A --> B[entryFile: src/app.ts]
    A --> C[controllerPathGlobs: src/**/controller.ts]
    A --> D[noImplicitAdditionalProperties: throw-on-extras]
    A --> E[spec Configuration]
    A --> F[routes Configuration]
    A --> G[ignore Patterns]

    E --> E1[outputDirectory: src]
    E --> E2[specVersion: 3]

    F --> F1[routesDir: src]

    B --> H[tsoa CLI]
    C --> H
    D --> H
    E --> H
    F --> H
    G --> H

    H --> I[Scan source files]
    I --> J[Parse controllers]
    J --> K[Generate routes files in routesDir]
    J --> L[Generate OpenAPI spec in outputDirectory]
    L --> M[Swagger UI / API Docs]
    K --> N[Application routing setup]

    style A fill:#f9f,stroke:#333,stroke-width:1px
    style H fill:#bbf,stroke:#333,stroke-width:1px
    style I,J,K,L,M,N fill:#bfb,stroke:#333,stroke-width:1px

Summary

The `tsoa.json` file is critical for configuring the tsoa framework to automate API routing and OpenAPI spec generation by:

It acts as the central point that connects your TypeScript source code to runtime API routing and documentation generation, streamlining API development and maintenance in TypeScript projects.