Skip to content

Commit f1da80d

Browse files
authored
Remove 'Non leaf-type cannot be used here' rule (#2648)
1 parent a9e5787 commit f1da80d

File tree

2 files changed

+35
-670
lines changed

2 files changed

+35
-670
lines changed

compiler/src/steps/validate-model.ts

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,6 @@ import { JsonSpec } from '../model/json-spec'
2323
import assert from 'assert'
2424
import { TypeName } from '../model/metamodel'
2525

26-
// Superclasses (i.e. non-leaf types, who are inherited or implemented) that are ok to be used as field types because
27-
// they're used as definition reuse and not as polymorphic types.
28-
// See also validateIsLeafType() below.
29-
const allowedSuperclasses = new Set([
30-
'_types:ErrorCause'
31-
])
32-
3326
enum TypeDefKind {
3427
type,
3528
behavior
@@ -231,7 +224,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
231224
modelError(`Type ${fqn(endpoint.request)} is not a request definition`)
232225
} else {
233226
validateTypeDef(reqType)
234-
validateIsLeafType(endpoint.request)
235227

236228
// Request path properties and url template properties should be the same
237229
const reqProperties = new Set(reqType.path.map(p => p.name))
@@ -276,7 +268,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
276268
modelError(`Type ${fqn(endpoint.response)} not found`)
277269
} else {
278270
validateTypeDef(respType)
279-
validateIsLeafType(endpoint.response)
280271
}
281272
}
282273
}
@@ -731,44 +722,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
731722
}
732723
}
733724

734-
// Validates that use of non-leaf types (i.e. those who are inherited or implemented) are used either
735-
// in contexts that are distinct from that of their children, or are abstract parent classes providing a way
736-
// way to identify actual concrete implementations in strongly typed languages.
737-
function validateIsLeafType (type: model.TypeName): void {
738-
if (parentTypes.has(fqn(type))) {
739-
// Aggregations are disambiguated with the 'typed_keys' parameter
740-
if (type.namespace === 'aggregations') return
741-
742-
const fqName = fqn(type)
743-
744-
switch (fqName) {
745-
// Base type also used as property, no polymorphic usage
746-
case '_builtins:ErrorCause':
747-
case 'x_pack.enrich:EnrichPolicy':
748-
case 'x_pack.info.x_pack_usage:XPackUsage':
749-
case 'x_pack.info.x_pack_usage:SecurityFeatureToggle':
750-
case 'x_pack.watcher.watcher_stats:WatchRecordQueuedStats':
751-
case 'x_pack.security.user.get_user:XPackUser':
752-
case 'cluster.nodes_stats:MemoryStats':
753-
case 'search.search:SearchResponse':
754-
return
755-
756-
// Have a "type" attribute that identifies the variant
757-
case 'mapping.types:PropertyBase':
758-
case 'analysis.token_filters:TokenFilterBase':
759-
return
760-
761-
// Single subclass with no additional properties, can probably be removed
762-
case 'x_pack.watcher.input:HttpInputRequestDefinition':
763-
return
764-
}
765-
766-
if (!allowedSuperclasses.has(fqName)) {
767-
modelError(`Non-leaf type cannot be used here: '${fqName}'`)
768-
}
769-
}
770-
}
771-
772725
// -----------------------------------------------------------------------------------------------
773726
// Value_Of validations
774727

@@ -777,7 +730,6 @@ export default async function validateModel (apiModel: model.Model, restSpec: Ma
777730
switch (valueOf.kind) {
778731
case 'instance_of':
779732
validateTypeRef(valueOf.type, valueOf.generics, openGenerics)
780-
validateIsLeafType(valueOf.type)
781733
break
782734

783735
case 'array_of':

0 commit comments

Comments
 (0)