tsoa.json

Overview

The `tsoa.json` file is a configuration file used by **tsoa**, a TypeScript framework designed to generate OpenAPI-compliant REST API documentation and route handling automatically. This JSON file defines how tsoa should process the source code and generate the API specification and routes for the application.

In this project, `tsoa.json` configures tsoa to:

This file acts as the central configuration that guides tsoa's code analysis and code generation tasks, making it crucial for maintaining the API contract and routing structure.


Detailed Explanation of Configuration Properties

Root Properties

Property

Type

Description

Example

entryFile

`string`

Specifies the main entry point of the application. tsoa uses this file to start analyzing the codebase.

"src/app.ts"

noImplicitAdditionalProperties

`string`

Controls how tsoa treats additional properties not explicitly defined in models for request validation. Options include: ["throw-on-extras"](/projects/291/69124), `"silently-remove-extras"`, or `"ignore"`.

["throw-on-extras"](/projects/291/69124) (throws error if extra properties are present)

controllerPathGlobs

`string[]`

Glob patterns to locate controller files. Controllers define the API endpoint implementations.

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

`spec`

`object`

Configuration for the OpenAPI specification generation.

See below

`routes`

`object`

Configuration for routes generation. Defines where to output the routes files.

See below

ignore

`string[]`

Glob patterns to exclude files or directories from tsoa processing.

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


spec Object

Property

Type

Description

Example

`outputDirectory`

`string`

Directory where the generated OpenAPI spec files will be saved.

`"src"`

specVersion

`number`

OpenAPI version to generate (commonly 3 for OpenAPI 3.x).

3


routes Object

Property

Type

Description

Example

routesDir

`string`

Directory where the generated routing files will be saved.

`"src"`


Usage and Workflow

  1. Entry Point Definition
    The entryFile (src/app.ts) is the starting point for tsoa's static analysis. tsoa scans the imports and dependencies starting from this file to build the API model.

  2. Controller Discovery
    The controllerPathGlobs pattern (src/**/controller.ts) tells tsoa where to find the controller files. Controllers contain decorated TypeScript classes with methods that define API endpoints.

  3. Model Validation Behavior
    The noImplicitAdditionalProperties set to "throw-on-extras" enforces strict validation. If an incoming request body contains any properties that are not explicitly defined in the model, tsoa will generate runtime validation that throws an error, helping maintain API contract integrity.

  4. Spec and Routes Generation

    • The OpenAPI specification files are generated into the directory specified by spec.outputDirectory (here, "src"), enabling tools like Swagger UI or Postman to consume the API documentation.

    • The route handlers needed to connect the API endpoints to the actual controller implementations are generated into routes.routesDir ("src"), integrating with the application server.

  5. Ignoring Files
    The ignore array ensures that generated or external code (e.g., node_modules or build output directories like dist) is excluded from tsoa processing, improving performance and avoiding conflicts.


Important Implementation Details


Interaction with Other Parts of the Project


Example Usage

To generate OpenAPI specs and routes with this configuration, run:

tsoa spec
tsoa routes

These commands use the `tsoa.json` configuration to:


Visual Diagram

This is a **flowchart** showing how `tsoa.json` configures the generation workflow and relates to project components:

flowchart TD
    A[tsoa.json Configuration] --> B[Entry Point: src/app.ts]
    A --> C[Controller Files: src/**/controller.ts]
    A --> D[No Implicit Additional Properties: throw-on-extras]
    A --> E[Ignore Patterns: node_modules, dist]
    B --> F[tsoa Static Analysis]
    C --> F
    E -. Excluded from -.-> F
    F --> G[Generate OpenAPI Spec in src/]
    F --> H[Generate Routes in src/]
    G --> I[API Documentation / Client SDKs]
    H --> J[Application Route Registration]

Summary

This file is essential for maintaining the API contract and automating REST endpoint wiring in the application.