Skip to content

Commit

Permalink
feat: add warning when no metadata is found during validation
Browse files Browse the repository at this point in the history
  • Loading branch information
NoNameProvided committed May 1, 2018
1 parent 423de4a commit 3b7c79a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/metadata/MetadataStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class MetadataStorage {
private validationMetadatas: ValidationMetadata[] = [];
private constraintMetadatas: ConstraintMetadata[] = [];

get hasValidationMetaData() {
return !!this.validationMetadatas.length;
}

// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
Expand Down
10 changes: 10 additions & 0 deletions src/validation/ValidationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ export class ValidationExecutor {
// -------------------------------------------------------------------------

execute(object: Object, targetSchema: string, validationErrors: ValidationError[]) {
/**
* If there is no metadata registered it means possibly the dependencies are not flatterned and
* more than one instance is used.
*
* TODO: This needs proper handling, forcing to use the same container or some other proper solution.
*/
if (!this.metadataStorage.hasValidationMetaData) {
console.warn(`No metadata found. There is more than once class-validator version installed probably. You need to flatten your dependencies.`);
}

const groups = this.validatorOptions ? this.validatorOptions.groups : undefined;
const targetMetadatas = this.metadataStorage.getTargetValidationMetadatas(object.constructor, targetSchema, groups);
const groupedMetadatas = this.metadataStorage.groupByPropertyName(targetMetadatas);
Expand Down

0 comments on commit 3b7c79a

Please sign in to comment.