Currently, it seems like every JSON schema registered is validated against.
registerSchema(SchemaOne);
registerSchema(SchemaTwo);
app.get('/validate-one/', (req, res, next) => {
validate(SchemaOne.name, req.params).then(console.log);
});
The above will log all errors including those for SchemaOne & SchemaTwo.
I can confirm this bug. As a workaround you should set a unique group name in each schema.
Confirmed. Minimal reproduction:
import { registerSchema, ValidationSchema, validate } from "class-validator";
const customSchemaOne: ValidationSchema = {
name: 'customSchemaOne',
properties: {
isDeleted: [
{ type: 'isBoolean', constraints: [], options: undefined }
]
}
};
const customSchemaTwo: ValidationSchema = {
name: 'customSchemaTwo',
properties: {
isVisible: [
{ type: 'isBoolean', constraints: [], options: undefined }
]
}
};
export async function main() {
const shouldPass = { isDeleted: true }
registerSchema(customSchemaOne);
registerSchema(customSchemaTwo);
console.log(await validate(customSchemaOne.name, shouldPass));
}
I encountered the problem too. wish resolve this.
@zender Can you be more specific, provide sample, I have added a unique group name and am still receiving the error. Thanks
Same issue for me, @NoNameProvided any updates with #204?
When will the fix be released?
This will be included in the next release.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
204 I sent a pull request which will fix the problem