title: NestJS - How to use @ValidateNested in DTOs for parameter validation
body: <p>I'm using NestJS to build an API for my application and am completely new to this framework. Amongst others, I am trying to setup endpoints for the <code>config</code> resource. First thing I did was creating the resource using Nest's CLI command <code>nest g resource config</code>, which correctly created all controllers and services needed.<br>
  Now, I would like to perform some validation on the parameters sent to the endpoint, which is why I added <code>app.useGlobalPipes(new ValidationPipe())</code> in the main. The parameter should come in the following form</p>
  <pre><code>{
    &quot;entryConfig&quot;: {
      &quot;mode&quot;: &quot;foo&quot;
    }
  }
  </code></pre>
  <p>So I wrote DTOs for the create config</p>
  <pre><code>import { IsNotEmpty, ValidateNested } from 'class-validator';
  
  import { EntryConfigDto } from './entry-config.dto';
  
  export class CreateConfigDto {
    @IsNotEmpty()
    @ValidateNested()
    entryConfig: EntryConfigDto;
  }
  </code></pre>
  <p>and the <code>entryConfig</code> parameter</p>
  <pre><code>import { IsNotEmpty } from 'class-validator';
  
  export class EntryConfigDto {
    @IsNotEmpty()
    mode: string;
  }
  </code></pre>
  <p>After reading <a href="https://github.com/typestack/class-validator#validating-nested-objects" rel="nofollow noreferrer">the docs</a>, I would expect the endpoint to validate the content of <code>entryConfig</code> against the <code>EntryConfigDto</code>. The problem is that I am indeed getting a validation error when <code>entryConfig</code> is empty or not an object/array, but when I send an invalid object it is not filtered. For example, feeding it with</p>
  <pre><code>{
    &quot;entryConfig&quot;: { &quot;mode&quot;: 1 }
  }
  </code></pre>
  <p>works, although I'm expecting an error as <code>mode</code> must be a string. Tried to look around for answers but could not find any. Pretty sure I completely misunderstood the meaning of <code>ValidateNested</code>. Any ideas? Thanks!</p>