Configuration

Complete reference for tsgonest.config.json — all fields, defaults, and validation rules.

tsgonest is configured via a tsgonest.config.json file in your project root. The CLI auto-detects this file, or you can specify a path with --config.

Minimal configuration

Most NestJS projects only need:

tsgonest.config.json
{
  "controllers": {
    "include": ["src/**/*.controller.ts"]
  },
  "transforms": {
    "validation": true,
    "serialization": true
  },
  "openapi": {
    "output": "dist/openapi.json"
  }
}

These are also the default values — if you omit any of these fields, tsgonest uses the defaults shown above.

Full configuration reference

tsgonest.config.json
{
  "controllers": {
    "include": ["src/**/*.controller.ts"],
    "exclude": ["src/**/*.spec.ts"]
  },
  "transforms": {
    "validation": true,
    "serialization": true,
    "include": ["src/**/*.dto.ts", "src/**/*.entity.ts"],
    "exclude": ["LegacyDto", "InternalResponse"]
  },
  "openapi": {
    "output": "dist/openapi.json",
    "title": "My API",
    "version": "1.0.0",
    "description": "My NestJS API documentation",
    "contact": {
      "name": "API Support",
      "url": "https://example.com/support",
      "email": "support@example.com"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    },
    "servers": [
      {
        "url": "https://api.example.com",
        "description": "Production"
      },
      {
        "url": "https://staging-api.example.com",
        "description": "Staging"
      }
    ],
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT Bearer token"
      },
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key authentication"
      }
    }
  },
  "nestjs": {
    "globalPrefix": "api",
    "versioning": {
      "type": "URI",
      "defaultVersion": "1",
      "prefix": "v"
    }
  },
  "entryFile": "main",
  "sourceRoot": "src",
  "deleteOutDir": false,
  "manualRestart": false
}

Field reference

controllers

Controls which files are analyzed for NestJS controller routes (used for OpenAPI generation and route mapping).

FieldTypeDefaultDescription
includestring[]["src/**/*.controller.ts"]Glob patterns for controller files
excludestring[][]Glob patterns to exclude
{
  "controllers": {
    "include": ["src/**/*.controller.ts"],
    "exclude": ["src/**/*.spec.ts", "src/**/health.controller.ts"]
  }
}

transforms

Controls companion file generation (validators and serializers).

FieldTypeDefaultDescription
validationbooleantrueGenerate validate and assert functions
serializationbooleantrueGenerate serialize functions
includestring[][]Glob patterns for source files to generate companions for
excludestring[][]Type name patterns to exclude from codegen
{
  "transforms": {
    "validation": true,
    "serialization": true,
    "include": ["src/**/*.dto.ts"],
    "exclude": ["LegacyUserDto", "Internal*"]
  }
}

The exclude field in transforms accepts type name patterns (not file paths). Use * as a wildcard. For example, "Internal*" skips any type whose name starts with "Internal".

openapi

Controls OpenAPI document generation.

FieldTypeDefaultDescription
outputstring"dist/openapi.json"Output path for the OpenAPI document
titlestring"API"API title in the info section
versionstring"1.0.0"API version in the info section
descriptionstring""API description
contactobjectContact information
licenseobjectLicense information
serversobject[][]Server URLs
securitySchemesobject{}Security scheme definitions

openapi.contact

FieldTypeDescription
namestringContact name
urlstringContact URL
emailstringContact email

openapi.license

FieldTypeDescription
namestringLicense name (required if license is set)
urlstringLicense URL

openapi.servers[]

FieldTypeDescription
urlstringServer URL
descriptionstringServer description

openapi.securitySchemes

Each key in securitySchemes is the scheme name. Supported fields:

FieldTypeDescription
typestring"http", "apiKey", "oauth2", or "openIdConnect"
schemestringHTTP auth scheme (e.g., "bearer")
bearerFormatstringBearer token format (e.g., "JWT")
instringLocation of API key: "header", "query", or "cookie"
namestringName of the header, query, or cookie parameter
descriptionstringDescription of the security scheme

nestjs

NestJS-specific settings that affect how routes are generated in the OpenAPI document.

FieldTypeDefaultDescription
globalPrefixstring""Global route prefix (e.g., "api")
versioningobjectAPI versioning configuration

nestjs.versioning

FieldTypeDefaultDescription
typestring"URI"Versioning strategy: "URI", "HEADER", "MEDIA_TYPE", or "CUSTOM"
defaultVersionstringDefault version (e.g., "1")
prefixstring"v"Version prefix for URI versioning
{
  "nestjs": {
    "globalPrefix": "api",
    "versioning": {
      "type": "URI",
      "defaultVersion": "1",
      "prefix": "v"
    }
  }
}

With this config, a @Controller('users') with a @Get() method produces the path /api/v1/users in the OpenAPI document.

Dev/build settings

These fields mirror NestJS CLI conventions for easy migration:

FieldTypeDefaultDescription
entryFilestring"main"Entry point filename without extension
sourceRootstring"src"Source root directory for file watching
deleteOutDirbooleanfalseDelete the output directory before building (same as --clean)
manualRestartbooleanfalseEnable rs manual restart in dev mode

Validation rules

tsgonest validates your config file and reports errors for:

  • controllers.include must contain at least one glob pattern
  • openapi.output must not be empty
  • openapi.output must have a .json extension

Path resolution

  • Relative paths in openapi.output are resolved relative to the config file's directory
  • If --config is not set, tsgonest looks for ./tsgonest.config.json in the working directory
  • If the config file does not exist and --config is not set, tsgonest uses sensible defaults

Migration from nest-cli.json

If you're migrating from nest-cli.json, here's a mapping of common fields:

nest-cli.jsontsgonest.config.jsonNotes
"entryFile": "main""entryFile": "main"Same field name
"sourceRoot": "src""sourceRoot": "src"Same field name
"compilerOptions.deleteOutDir""deleteOutDir"Top-level in tsgonest
"compilerOptions.assets"--assets flagCLI flag, not in config
N/A"controllers"New — for OpenAPI route analysis
N/A"transforms"New — for companion generation
N/A"openapi"New — replaces @nestjs/swagger config

On this page