tsoa.json


Overview

The `tsoa.json` file is a configuration file used by the **tsoa** framework, a TypeScript tool that facilitates the automatic generation of OpenAPI (Swagger) specifications and routing for RESTful APIs. This JSON file defines how tsoa should scan the project's source code, identify controllers, and generate both API routes and OpenAPI specification files.

In essence, this file controls the behavior of tsoa’s CLI commands, such as `tsoa spec` and `tsoa routes`, by specifying input files, output directories, and other key options to generate API documentation and routing logic that integrates seamlessly with the project’s architecture.


Detailed Explanation of Configuration Fields

The file is a JSON object with the following top-level properties:

1. entryFile

2. noImplicitAdditionalProperties

3. controllerPathGlobs

4. spec

5. routes

6. ignore


Usage Example

Assuming the project is set up properly:

The configuration ensures tsoa scans the `src/app.ts` entrypoint, loads all controllers matching `src/**/controller.ts`, ignores `node_modules` and `dist`, and performs strict validation by throwing errors on additional unexpected properties.


Important Implementation Details


Interaction with Other Parts of the System


Mermaid Flowchart Diagram

Since this file is a configuration utility file coordinating multiple processes (scanning, spec generation, route generation), a **flowchart** is appropriate to visualize the workflow.

flowchart TD
    A[tsoa.json Configuration] --> B[Start at entryFile (src/app.ts)]
    B --> C{Scan controller files}
    C -->|Match src/**/controller.ts| D[Parse Controllers]
    C -->|Ignore **/node_modules/**, **/dist/**| E[Skip Ignored Paths]
    D --> F[Generate OpenAPI Spec (v3) in src/]
    D --> G[Generate Routes in src/]
    F --> H[Output: openapi.json (or similar)]
    G --> I[Output: routes files]
    H --> J[Used for API docs, validation, client generation]
    I --> K[Used by server to handle HTTP requests]

Summary

Configuration Key

Purpose

Current Setting

`entryFile`

Project entry point for tsoa scanning

`"src/app.ts"`

`noImplicitAdditionalProperties`

Control handling of extra properties in validation

`"throw-on-extras"`

`controllerPathGlobs`

Glob pattern to find controller files

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

spec.outputDirectory

Where to output OpenAPI specs

`"src"`

spec.specVersion

OpenAPI spec version

`3`

routes.routesDir

Where to output generated route files

`"src"`

`ignore`

Files/folders to exclude from scanning

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

This configuration ensures tsoa performs a strict, clean generation of API specs and routes, tightly integrated with the project's folder structure and coding conventions.


If you need further integration guidance or examples for tsoa decorators usage, please let me know!