tsoa.json


Overview

The `tsoa.json` file serves as the primary configuration file for the **tsoa** framework within this project. TSOA is a TypeScript framework used to automatically generate OpenAPI (Swagger) specifications and route handling based on controller source files. This configuration file guides the tsoa CLI tools to locate the entry point of the application, controller files, output directory for generated specs and routes, and other key settings that influence how the API documentation and routing are generated.

In this project, `tsoa.json` ensures that OpenAPI v3 specifications and routing files are generated accurately reflecting the controllers located under `src/**/controller.ts`, providing strict type safety rules and ignoring build or dependency output folders.


Configuration Properties Explained

Property

Type

Description

Example / Notes

entryFile

`string`

The main entry point file of the application. This is where tsoa starts parsing for type information and API metadata.

"src/app.ts"

noImplicitAdditionalProperties

`string` (["throw-on-extras"](/projects/291/69124) / ["silently-remove-extras"](/projects/291/69124) / `"ignore"`)

Controls how tsoa handles extra properties not explicitly defined in models during validation. ["throw-on-extras"](/projects/291/69124) means it throws an error if extra properties are present.

"throw-on-extras"

controllerPathGlobs

`string[]`

Glob patterns describing where tsoa should find controller source files to generate routes and OpenAPI specs from.

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

`spec`

`object`

Configuration for OpenAPI specification generation.

See below

  • outputDirectory

`string`

Directory where the generated OpenAPI spec files will be saved.

`"src"`

`number`

Version of the OpenAPI spec to generate. Supported values are typically [2](/projects/291/69310) or `3`.

`3`

`routes`

`object`

Configuration related to route generation.

See below

`string`

Directory where generated route files will be saved.

`"src"`

ignore

`string[]`

Glob patterns to exclude certain files or directories from tsoa processing (e.g., node_modules, build directories).

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


Detailed Explanation

1. entryFile


2. noImplicitAdditionalProperties


3. controllerPathGlobs


4. spec


5. routes


6. ignore


Usage Example

Given this configuration, a typical workflow would be:

  1. Write your controllers in files matching pattern src/**/controller.ts.

  2. Run the tsoa CLI commands (e.g., tsoa spec and tsoa routes) which will:

    • Parse src/app.ts as the entry point.

    • Scan all matching controller files.

    • Generate OpenAPI v3 spec files in src/.

    • Generate route files in src/.

  3. Use the generated routes in your Express app to wire up the API endpoints.

  4. Use the OpenAPI spec to power documentation, client generation, or validation.


Interaction with Other Parts of the Application


Important Implementation Details


Diagram: Configuration Structure and Workflow

flowchart TD
    A[tsoa.json Configuration]
    A --> B[Entry File: src/app.ts]
    A --> C[Controller Files: src/**/controller.ts]
    A --> D[Spec Generation]
    A --> E[Route Generation]
    A --> F[Ignore Patterns]

    B -->|Provides context and types| C
    C -->|Scanned by tsoa| D
    C -->|Scanned by tsoa| E

    D -->|Outputs OpenAPI v3 spec files| G[Directory: src/]
    E -->|Outputs routes| H[Directory: src/]

    F -.->|Exclude scanning| B
    F -.->|Exclude scanning| C

Summary

The `tsoa.json` file is a central piece in automating the generation of API routes and OpenAPI documentation in this TypeScript project. Its configuration ensures proper file discovery, strict validation settings, and correct output locations, enabling developers to maintain a clean and robust API ecosystem with minimal manual overhead. Adjusting this file tailors tsoa's behavior to fit the project’s architecture and development workflow.