raml-java-parser
raml-java-parser copied to clipboard
Resolving of discriminatorValues doesn't respect inheritance
Following RAML definition:
#%RAML 1.0
---
title: Test
types:
Reference:
properties:
typeId: string
id: string
FieldType:
discriminator: name
properties:
name:
type: string
ReferenceFieldType:
type: FieldType
discriminatorValue: Reference
properties:
referenceTypeId:
type: string
/type:
get:
responses:
200:
body:
application/json:
example: {
"name": "Reference",
"referenceTypeId": "channel"
}
type: FieldType
Results in following errors:
Missing required field "typeId"
Missing required field "id"
By just reordering the type definition a little bit like this:
#%RAML 1.0
---
title: Test
types:
FieldType:
discriminator: name
properties:
name:
type: string
ReferenceFieldType:
type: FieldType
discriminatorValue: Reference
properties:
referenceTypeId:
type: string
Reference:
properties:
typeId: string
id: string
/type:
get:
responses:
200:
body:
application/json:
example: {
"name": "Reference",
"referenceTypeId": "channel"
}
type: FieldType
There are no validation errors anymore.
The reason for that is, that the parser first tries the first type either with a name or a discriminatorValue of Reference.
Also it's not directly specified that only discriminator values of inherited types should be considered. It makes a lot of sense for polymorph types to only take them into consideration as polymorph types should always be a subclass of the class defining the discriminator. This would resolve such issues like the above examples.
Aha! Link: https://mulesoft-roadmap.aha.io/features/APIRAML-78