tsoa.json

Overview

`tsoa.json` is a configuration file used by the **tsoa** framework, which automates the generation of OpenAPI-compliant REST API specifications and routes from TypeScript source code. This file defines key settings that control how tsoa scans the project files, generates API specs, creates routing files, and handles validation.

By specifying paths, output directories, and validation policies, `tsoa.json` enables seamless integration of tsoa into a TypeScript backend project. It acts as the central configuration point that guides tsoa in extracting API metadata from annotated controller files and producing corresponding artifacts needed for API documentation and routing.


Configuration Details

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

Property

Type

Description

`entryFile`

`string`

The main entry point of the application that tsoa uses as a starting point for type analysis.

`noImplicitAdditionalProperties`

`"throw-on-extras"` (string)

Validation policy for handling additional properties not defined in models (`throw-on-extras` means throw errors).

`controllerPathGlobs`

`string[]`

Glob patterns to locate controller files from which tsoa extracts API metadata.

`spec`

`object`

Configuration related to OpenAPI specification generation.

`routes`

`object`

Configuration for route generation.

`ignore`

`string[]`

Glob patterns for files/directories to ignore during tsoa processing.


Property: entryFile


Property: noImplicitAdditionalProperties


Property: controllerPathGlobs


Property: spec


Property: routes


Property: ignore


How This File Interacts with the System


Usage Example in a Project Workflow

  1. Define Controllers:
    Create TypeScript files matching src/**/controller.ts with tsoa decorators, e.g.,

    import { Controller, Get, Route } from 'tsoa';
    
    @Route('users')
    export class UsersController extends Controller {
      @Get()
      public async getUsers() {
        return [{ id: 1, name: 'Alice' }];
      }
    }
    
  2. Configure tsoa.json:
    Ensure tsoa.json is set with correct paths and settings (as in this file).

  3. Generate API Spec and Routes:
    Run:

    tsoa spec
    tsoa routes
    

    This generates:

    • OpenAPI spec file in src/

    • Routes file in src/

  4. Integrate Generated Routes:
    Import and use the routes in your main application file (src/app.ts).


Important Implementation Details


Mermaid Diagram: Configuration Structure Flow

The following flowchart illustrates how the main configuration properties relate and drive the tsoa processing workflow.

flowchart TD
    A[tsoa.json Configuration]
    A --> B[entryFile: src/app.ts]
    A --> C[controllerPathGlobs: src/**/controller.ts]
    A --> D[noImplicitAdditionalProperties: throw-on-extras]
    A --> E[spec]
    A --> F[routes]
    A --> G[ignore]

    E --> E1[outputDirectory: src]
    E --> E2[specVersion: 3]

    F --> F1[routesDir: src]

    subgraph Processing Workflow
        C --> H[Scan Controllers]
        H --> I[Extract API Metadata]
        I --> J[Generate OpenAPI Spec]
        J --> E1
        I --> K[Generate Routes]
        K --> F1
        D --> L[Validate Requests Strictly]
    end

    G -.->|Exclude files| H

Summary

`tsoa.json` is a critical configuration file in a tsoa-enabled TypeScript backend project. It defines:

This configuration enables automated generation of OpenAPI specs and routing files, enforcing strict API validation and ensuring seamless integration between TypeScript code and API documentation/services.