title: NestJs - Validate request body using class-validator having 2 options for body class
body: <p>I have a rest call, which might receive body of type classA or classB.
  I need to keep it as 2 different classes.
  Example -</p>
  <pre><code>// classes -
  class ClassA {
      @IsString()
      @Length(1, 128)
      public readonly name: string;
      @IsString()
      @Length(1, 128)
      public readonly address: string;
  }
  
  class ClassB {
      @IsString()
      @Length(1, 10)
      public readonly id: string;
  }
  
  
  // my request controller - 
  
      @Post('/somecall')
      public async doSomething(
          @Body(new ValidationPipe({transform: true})) bodyDto: (ClassA | ClassB) // &lt; not validating any of them..
      ): Promise&lt;any&gt; {
  // do something
      }
  </code></pre>
  <p>The issue is, that when having more than one class, body is not validated.</p>
  <p>How can I use 2 or more classes and validate them using class-validator?
  <em>I don't want to use same class..</em></p>
  <p>Thank you all :)</p>