Configuration
Type-safe configuration with tsgonest.config.ts and defineConfig().
tsgonest supports both TypeScript and JSON configuration files. The recommended approach is tsgonest.config.ts with the defineConfig() helper for type safety and autocomplete.
TypeScript config (recommended)
import { defineConfig } from '@tsgonest/runtime';
export default defineConfig({
controllers: {
include: ['src/**/*.controller.ts'],
},
transforms: {
validation: true,
serialization: true,
},
openapi: {
output: 'dist/openapi.json',
},
});The defineConfig() helper provides full IntelliSense — autocomplete, inline documentation, and type checking for every field.
JSON config (alternative)
If you prefer JSON, create tsgonest.config.json in your project root:
{
"controllers": {
"include": ["src/**/*.controller.ts"]
},
"transforms": {
"validation": true,
"serialization": true
},
"openapi": {
"output": "dist/openapi.json"
}
}Config resolution
tsgonest resolves configuration in this order:
--configCLI flag (explicit path)tsgonest.config.tsin the working directorytsgonest.config.jsonin the working directory- Default configuration (sensible defaults)
Full configuration reference
import { defineConfig } from '@tsgonest/runtime';
export default defineConfig({
controllers: {
include: ['src/**/*.controller.ts'],
exclude: ['src/**/*.spec.ts'],
},
transforms: {
validation: true,
serialization: true,
},
openapi: {
output: 'dist/openapi.json',
title: 'My API',
version: '1.0.0',
description: 'My NestJS API documentation',
},
});For the full set of OpenAPI metadata fields (contact, license, servers, security schemes), NestJS settings (global prefix, versioning), and dev/build settings — see the field reference below.
Full Type Reference
Prop
Type
Field reference
controllers
Controls which files are analyzed for NestJS controller routes (used for OpenAPI generation and route mapping).
If an included file contains unsupported dynamic patterns (runtime-generated controllers or dynamic decorator path args), tsgonest emits warnings and excludes those routes from OpenAPI.
| Field | Type | Default | Description |
|---|---|---|---|
include | string[] | ["src/**/*.controller.ts"] | Glob patterns for controller files |
exclude | string[] | [] | Glob patterns to exclude |
import { defineConfig } from '@tsgonest/runtime';
export default defineConfig({
controllers: {
include: ['src/**/*.controller.ts'],
exclude: ['src/**/*.spec.ts', 'src/**/health.controller.ts'],
},
// ...
});transforms
Controls companion file generation (validators and serializers).
| Field | Type | Default | Description |
|---|---|---|---|
validation | boolean | true | Generate validate and assert functions |
serialization | boolean | true | Generate serialize functions |
include | string[] | [] | Glob patterns for source files to generate companions for |
exclude | string[] | [] | Type name patterns to exclude from codegen |
import { defineConfig } from '@tsgonest/runtime';
export default defineConfig({
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.
| Field | Type | Default | Description |
|---|---|---|---|
output | string | "dist/openapi.json" | Output path for the OpenAPI document |
title | string | "API" | API title in the info section |
version | string | "1.0.0" | API version in the info section |
description | string | "" | API description |
For detailed OpenAPI metadata configuration (contact, license, servers, security schemes), see the OpenAPI Config page.
nestjs
NestJS-specific settings that affect how routes are generated in the OpenAPI document.
| Field | Type | Default | Description |
|---|---|---|---|
globalPrefix | string | "" | Global route prefix (e.g., "api") |
versioning | object | API versioning configuration |
nestjs.versioning
| Field | Type | Default | Description |
|---|---|---|---|
type | string | "URI" | Versioning strategy: "URI", "HEADER", "MEDIA_TYPE", or "CUSTOM" |
defaultVersion | string | Default version (e.g., "1") | |
prefix | string | "v" | Version prefix for URI versioning |
import { defineConfig } from '@tsgonest/runtime';
export default defineConfig({
// ...
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. See the Versioning page for details.
sdk
TypeScript SDK generation settings. Run tsgonest sdk after building to generate a typed client from your OpenAPI spec.
| Field | Type | Default | Description |
|---|---|---|---|
output | string | "./sdk" | Output directory for the generated SDK |
input | string | Path to OpenAPI JSON input. Defaults to openapi.output if omitted. |
import { defineConfig } from '@tsgonest/runtime';
export default defineConfig({
// ...
sdk: {
output: './sdk',
input: 'dist/openapi.json', // optional — defaults to openapi.output
},
});See the SDK Generation page for full documentation.
Dev/build settings
These fields mirror NestJS CLI conventions for easy migration:
| Field | Type | Default | Description |
|---|---|---|---|
entryFile | string | "main" | Entry point filename without extension |
sourceRoot | string | "src" | Source root directory for file watching |
deleteOutDir | boolean | false | Delete the output directory before building (same as --clean) |
manualRestart | boolean | false | Enable rs manual restart in dev mode |
Validation rules
tsgonest validates your config file and reports errors for:
controllers.includemust contain at least one glob patternopenapi.outputmust not be emptyopenapi.outputmust have a.jsonextension
Path resolution
- Relative paths in
openapi.outputare resolved relative to the config file's directory - If
--configis not set, tsgonest looks fortsgonest.config.tsfirst, thentsgonest.config.json - If no config file exists and
--configis 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.json | tsgonest.config.ts | Notes |
|---|---|---|
"entryFile": "main" | entryFile: 'main' | Same field name |
"sourceRoot": "src" | sourceRoot: 'src' | Same field name |
"compilerOptions.deleteOutDir" | deleteOutDir: true | Top-level in tsgonest |
"compilerOptions.assets" | --assets flag | CLI 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 |