tsoa.json

Overview

The `tsoa.json` file is a configuration file used by the **tsoa** framework, a TypeScript tool that facilitates building RESTful APIs with automatic OpenAPI (Swagger) specification generation and route generation. This file defines how tsoa should process the source code, generate API documentation, and create routing files.

In this project, `tsoa.json` configures the entry point of the application, routing options, specification generation settings, and file patterns to include or exclude in the tsoa processing pipeline.


Detailed Explanation

Configuration Structure

The file is a JSON object consisting of several key properties that control tsoa's behavior:

Property

Type

Description

`entryFile`

`string`

Path to the main application file that initializes the API server. tsoa uses this as the starting point.

`noImplicitAdditionalProperties`

`string`

Defines how tsoa treats additional properties in models. ["throw-on-extras"](/projects/291/69124) will throw an error if extra properties are found.

`controllerPathGlobs`

`string[]`

Glob patterns specifying where tsoa should look for controller files (files containing API route handlers).

`spec`

`object`

Configuration for OpenAPI specification generation.

spec.outputDirectory

`string`

Directory where the generated OpenAPI spec files will be saved.

spec.specVersion

`number`

Specifies the OpenAPI spec version (e.g., 3 for OpenAPI 3.0).

`routes`

`object`

Configuration for route generation.

routes.routesDir

`string`

Directory where tsoa will output generated route files.

`ignore`

`string[]`

Glob patterns for files/directories that tsoa should ignore during processing (commonly `node_modules` and build output).


Properties Breakdown

entryFile

noImplicitAdditionalProperties

controllerPathGlobs

spec

routes

ignore


Usage Example

Suppose you have a TypeScript REST API project structured as follows:

src/
 ├─ app.ts              # Main app entry point
 ├─ userController.ts   # Controller file
 └─ ...

With the given `tsoa.json`:

After running tsoa commands (e.g., `tsoa spec` or `tsoa routes`), the generated OpenAPI JSON/YAML and route files will appear in the specified directories.


Implementation Details and Algorithms

`tsoa.json` itself does not contain executable code or algorithms but instructs the tsoa CLI and build tools how to:

This configuration enables seamless integration between source code and API documentation and routing, reducing manual boilerplate.


Interaction with Other Parts of the System

Overall, this file acts as the central configuration point for the tsoa toolchain, ensuring consistency between source code, API documentation, and routing logic.


Mermaid Diagram: Configuration Structure Flowchart

flowchart TD
    A[tsoa.json Configuration] --> B[Entry File: src/app.ts]
    A --> C[Controller Globs: src/**/controller.ts]
    A --> D[No Implicit Additional Properties: throw-on-extras]
    A --> E[Spec Generation]
    E --> E1[Output Directory: src]
    E --> E2[Spec Version: 3]
    A --> F[Routes Generation]
    F --> F1[Routes Directory: src]
    A --> G[Ignore Patterns]
    G --> G1["**/node_modules/**"]
    G --> G2["**/dist/**"]

Summary

The `tsoa.json` configuration file is essential for integrating tsoa into a TypeScript REST API project. It defines where tsoa looks for API controllers, how it generates OpenAPI specifications and route files, and how strict the validation on model properties should be. By properly configuring this file, developers automate API documentation and routing generation, improving maintainability and reducing manual coding errors.