question: can we perform a oneOf validation?
See original GitHub issueDescription
How to perform a oneOf
validation of a nested object i.e., child object is either of TypeA
or TypeB
? This seems like a very common use case, is there an out-of-the-box solution for this? I understand that this problem is concerning class-transformer
more than it is class-validator
…
Is there an example of a generic @OneOf()
decorator? Any ideas on how to work with class-transformer
and class-validator
together to make this happen?
Reproduction
class TypeA {
@IsString()
public foo;
}
class TypeB {
@IsString()
public bar;
}
class Parent {
@IsObject()
@ValidateNested()
@Type((): Function => TypeA) // ???
public child: TypeA | TypeB;
}
Environment
- nodejs: 8.11.2
- browser
- framework/library
class-validator version: 0.12.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:9 (1 by maintainers)
Top Results From Across the Web
validation of json schema having oneOf keyword
The schema in my question was incorrect. The schema meant match oneOf(all three references), email, rememberme_id, buyer_account_number. The data (email and ...
Read more >Multiple JSON Schemas with *oneOf* - M100 - MongoDB
Here oneOf is a keyword construct in the JSON Schema, which is used to provide an array of criteria where, if exactly one...
Read more >Frequently Asked Questions - Ajv JSON schema validator
# Why Ajv validates empty object as valid? ... "properties" keyword does not require the presence of any properties, you need to use...
Read more >It all starts with applicability - JSON Schema Fundamentals ...
"Validation begins by applying the root Schema to the complete instance document. Applicator keywords apply subschemas to the instance ...
Read more >Frequently Asked Questions - Schemathesis - Read the Docs
Input validation is, therefore, more frequently examined than other parts. ... As the first step, you can use schema generators like flasgger for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@mehtamanan can you try this ?
and to use it in your DTO
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.