phoenixnap / springmvc-raml-plugin

Spring MVC - RAML Spec Synchroniser Plugin. A Maven plugin designed to Generate Server & Client code in Spring from a RAML API descriptor and conversely, a RAML API document from the SpringMVC Server implementation.
Apache License 2.0
136 stars 84 forks source link

Discriminator support #242

Closed stojsavljevic closed 6 years ago

stojsavljevic commented 6 years ago

I would like to add support for discriminator and discriminatorValue attributes of data types. Having data types defined like this:

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
    discriminatorValue: emp
    properties:
      employeeId: integer
  User: # kind can equal `User`; default value for `discriminatorValue`
    type: Person
    discriminatorValue: usr
    properties:
      userId: integer

should generate Person object with following annotations:

@JsonTypeInfo(use = Id.NAME, include = As.EXISTING_PROPERTY, property = "kind", visible = true)
@JsonSubTypes({
    @JsonSubTypes.Type(value = User.class, name = "usr"), 
    @JsonSubTypes.Type(value = Employee.class, name = "emp") 
})
public class Person implements Serializable