javaramlwolfram-languageraml-java-parser

Does RAML support multiple response schemas for the same content type?


In my project all POJO class are extending parent class.As my controller has one method whose return type is parent class but actually it is returning child class here I am using a concept of polymorphism i.e. I am typecasting the child class to parent class.

In the RAML generation code: The RAML generator code basically it uses the method signature of the controller as the signature contains parent class so it will generate the schema of Parent but actually we need schema of actual response.

Is there any to add two schemas in API response of RAML? Or Is there any way to get the schema of actual response of API where polymorphism concept is used ?


Solution

  • Consider using Union Type and Discriminator. An instance of a union type must meet all restrictions of at least one of the associated type. So an instance of the union type defined as Phone|Notebook must be either an instance of Phone or Notebook (or both of them). Discriminator allows to infer the concrete type of an individual object at runtime, so it's similar to the concept of polymorphism.