tsoa.json


Overview

The `tsoa.json` file serves as the primary configuration file for the [tsoa](https://github.com/lukeautry/tsoa) framework, which is a TypeScript OpenAPI (Swagger) and routing tool that helps generate routes and API documentation automatically based on TypeScript source code annotations. This file defines the conventions and settings for how tsoa scans the project, generates OpenAPI specifications, and produces routing files.

Key functionalities of this file include:

This configuration ensures that tsoa can correctly parse the project structure, generate OpenAPI compliant documentation, and produce route files that integrate seamlessly with the application.


Detailed Explanation

Top-Level Properties

Property

Type

Description

`entryFile`

`string`

Specifies the main entry TypeScript file of the application. tsoa starts analysis here.

noImplicitAdditionalProperties

"throw-on-extras"

Controls validation behavior for additional properties not defined in models. Here, it throws errors if extra properties are passed.

controllerPathGlobs

`string[]`

Array of glob patterns to locate controller files that contain API route definitions.

`spec`

`object`

Configuration object for OpenAPI specification generation.

spec.outputDirectory

`string`

Directory path where the generated OpenAPI spec files will be saved.

spec.specVersion

`number`

OpenAPI specification version (e.g., 3 for OpenAPI 3.x).

`routes`

`object`

Configuration for route generation.

routes.routesDir

`string`

Directory path where generated route files will be output.

`ignore`

`string[]`

Array of glob patterns specifying files/directories to exclude from tsoa scanning.


Property Details and Usage

entryFile: "src/app.ts"

noImplicitAdditionalProperties: "throw-on-extras"

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

spec

routes

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


Important Implementation Details


Interaction with Other Parts of the System

This configuration file is essential for aligning tsoa's behavior with the project structure and ensuring that API documentation and code generation stay consistent with the TypeScript source code.


Visual Diagram

Below is a flowchart summarizing the workflow and components configured in the `tsoa.json` file:

flowchart TD
    A[Start: tsoa CLI] --> B[Reads tsoa.json Configuration]
    B --> C[Uses "entryFile" (src/app.ts) as root]
    C --> D[Scans controller files (src/**/controller.ts)]
    D --> E{Excludes files matching ignore patterns?}
    E -- Yes --> F[Skip files]
    E -- No --> G[Parse Controllers and Models]
    G --> H[Generate OpenAPI Spec (v3) in src/]
    G --> I[Generate Routes in src/]
    H & I --> J[App imports generated routes and spec]
    J --> K[Application runs with validated routes and docs]

Summary

The `tsoa.json` file is a lightweight but critical configuration file that guides tsoa in scanning the TypeScript project, generating OpenAPI documentation, and producing route files that integrate with the app. It specifies:

By configuring these options, developers ensure that tsoa can automate much of the repetitive work of API documentation and routing, keeping the API consistent, validated, and well-documented.