@@ -138,11 +138,25 @@ export class MetadataStorage {
138138 // filter out duplicate metadatas, prefer original metadatas instead of inherited metadatas
139139 const uniqueInheritedMetadatas = inheritedMetadatas . filter ( inheritedMetadata => {
140140 return ! originalMetadatas . find ( originalMetadata => {
141- // expect validators to be duplicate if they point to the same validator function
142- return (
143- originalMetadata . propertyName === inheritedMetadata . propertyName &&
144- originalMetadata . constraintCls === inheritedMetadata . constraintCls
145- ) ;
141+ // We have no clean way to determine if 2 validators are the same, and thus can't easily determine
142+ // which validators have been overwritten by a subclass
143+ // - Can't use `validatorCls` object/function: it's recreated on a per-usage basis so two decorators will give different instances
144+ // - Can't use `ValidationTypes`: this was useable until 11a7b8bb59c83d55bc723ebb236fdca912f49d88,
145+ // after which 90% of ValidationTypes were removed in favour of type "customValidation". Note that
146+ // some validators, including any custom validators, still had type "customValidation" before this, and therefore
147+ // did not work with inherited validation
148+ // - `name`: can be used to uniquely identify a validator, but is optional to not break backwards compatability
149+ // in a future release, it should be made required
150+ const isSameProperty = originalMetadata . propertyName === inheritedMetadata . propertyName ;
151+ const isSameValidator =
152+ originalMetadata . name && inheritedMetadata . name
153+ ? // TODO: when names becomes required, ONLY compare by name
154+ originalMetadata . name === inheritedMetadata . name
155+ : // 95% of decorators are of type "customValidation", despite being different decorators
156+ // therefore this equality comparison introduces lots of false positives
157+ originalMetadata . type === inheritedMetadata . type ;
158+
159+ return isSameProperty && isSameValidator ;
146160 } ) ;
147161 } ) ;
148162
0 commit comments