title: NestJS - Validating body conditionally, based on one property
body: <p>I'm trying to find a nice way to validate a body using DTO (using the brilliant <code>class-validator</code> and <code>class-transformer</code> libraries). It works really well, even for nested structures but in my case I'd like to have the body property based on some conditions.</p>
  
  <p>Example that will probably help to understand:</p>
  
  <p>Let's imagine my body should always have <code>selectedCategory</code>.
  Based on that field, the content could either be from category 1, which contains <code>prop1</code> OR from category 2, which contains <code>prop2</code>.</p>
  
  <p>I do not want to allow a null for both of them, I really want to have to either have <code>prop1</code> defined or <code>prop2</code> based on the <code>selectedCategory</code>.</p>
  
  <p>I think that I could use a pipe, but then how can I specify the correct DTO to use? </p>
  
  <p>I've built a "base" class with all the common properties and few other classes that inherit from it.</p>
  
  <p>I could instantiate the pipe manually based on the property <code>selectedCategory</code>, that'd be ideal but I have no clue what to pass as a second argument of the pipe (metadata).</p>
  
  <p>Thanks for your help.</p>