Class-validator: All Schemas are validated against

Created on 26 Apr 2017  路  9Comments  路  Source: typestack/class-validator

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.

high fix

Most helpful comment

204 I sent a pull request which will fix the problem

All 9 comments

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

204 I sent a pull request which will fix the problem

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

btd1337 picture btd1337  路  5Comments

ibox4real picture ibox4real  路  4Comments

twittwer picture twittwer  路  6Comments

jerradpatch picture jerradpatch  路  5Comments

MistyKuu picture MistyKuu  路  3Comments