@@ -119,11 +119,25 @@ export class MetadataStorage {
119119 // filter out duplicate metadatas, prefer original metadatas instead of inherited metadatas
120120 const uniqueInheritedMetadatas = inheritedMetadatas . filter ( inheritedMetadata => {
121121 return ! originalMetadatas . find ( originalMetadata => {
122- // expect validators to be duplicate if they point to the same validator function
123- return (
124- originalMetadata . propertyName === inheritedMetadata . propertyName &&
125- originalMetadata . constraintCls === inheritedMetadata . constraintCls
126- ) ;
122+ // We have no clean way to determine if 2 validators are the same, and thus can't easily determine
123+ // which validators have been overwritten by a subclass
124+ // - Can't use `validatorCls` object/function: it's recreated on a per-usage basis so two decorators will give different instances
125+ // - Can't use `ValidationTypes`: this was useable until 11a7b8bb59c83d55bc723ebb236fdca912f49d88,
126+ // after which 90% of ValidationTypes were removed in favour of type "customValidation". Note that
127+ // some validators, including any custom validators, still had type "customValidation" before this, and therefore
128+ // did not work with inherited validation
129+ // - `name`: can be used to uniquely identify a validator, but is optional to not break backwards compatability
130+ // in a future release, it should be made required
131+ const isSameProperty = originalMetadata . propertyName === inheritedMetadata . propertyName ;
132+ const isSameValidator =
133+ originalMetadata . name && inheritedMetadata . name
134+ ? // TODO: when names becomes required, ONLY compare by name
135+ originalMetadata . name === inheritedMetadata . name
136+ : // 95% of decorators are of type "customValidation", despite being different decorators
137+ // therefore this equality comparison introduces lots of false positives
138+ originalMetadata . type === inheritedMetadata . type ;
139+
140+ return isSameProperty && isSameValidator ;
127141 } ) ;
128142 } ) ;
129143
0 commit comments