Open katmatt opened 6 years ago
That is not always true. Consider the following:
types:
Person:
type: object
discriminator: kind # refers to the `kind` property of object `Person`
properties:
kind: string # contains name of the kind of a `Person` instance
name: string
Employee: # kind can equal `Employee`; default value for `discriminatorValue`
type: Person
properties:
employeeId: integer
User: # kind can equal `User`; default value for `discriminatorValue`
type: Person
properties:
userId: integer
annotationTypes:
Roles: Person[]
This is fully valid. Yes, defining an inline annotation type it does not make sense, but it makes more sense through the ability to reuse types as annotation types.
Hope that gives you what you need :)
Now I"m confused. I thought that annotation types don't support inheritance?
Only through the RAML types system. You can't create one annotation type and use it as a type in another. That is not possible.
If I get you correctly this allows sth. like:
/example:
(Roles):
- kind: Employee
name: Jane Doe
employeeId: 1
- kind: User
name: John Doe
userId: 1
Right?
Yes. An annotation type can inherit its properties from a type definition. That is why you can use anything defined in types
in as a base, but not something defined in annotationTypes
.
I see. Coming back to my initial question: Do you have another example showing an annotation type that defines a discriminator
or at least a discriminatorValue
? I'm still not convinced that it makes sense to have them for annotation types too 😉
The specification is unclear about annotation types with type
object
and their support for discriminators. According to the spec annotation types have the same facets as types, but why should they support discriminators? Annotations always have a specific type and don't support inheritance. That means that it doesn't make sense that they allow to specify discriminators.