Polymorphism on types


Hi guys,

I am working on an API specs, whose response is an array of objects.
Each object exposes three fields:

  • field1
  • field2
  • field3

they are all string, but field3 should contain either typeA or typeB.

I have tried:
type: typeA | typeB

but apparently it doesnt work / it is not supported.

The API spec is RAML 1.0 compliant.

Any suggestion ?

Thanks in advance,


@gianluca: what do you mean by “it doesnt work / it is not supported”? are you referring to a specific tool?

For reference, this is where to find the section on “Union Types” in the RAML 1.0 docs: https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md#union-type


The API spec is implemented in a RAML 1.0 file.
It defines a GET method “/components”.
The /components method returns a JSON response.
The response is an array of objects of type “Component”, which is defined in a separate RAML 1.0 DataType file.
“Component” contains a “Data” field, which could be either TYPE_A or TYPE_B

data: { }

It looks like if I am not allowed to define Union Types inside a DataType file.

The API response is defined in this way:
type: !include types/component.raml

marketingBanner: !include marketingBanners/marketingBanner.raml
contextualMessage: !include contextualMessages/contextualMessage.raml
union: marketingBanner | contextualMessage

And component is defined in a separate RAML 1.0 DataType file as showed below:

description: Represent a Component, and relative metadata.
type: string
schema: type_a | type_b

This works but it doesnt produce the result I wish.
I have also tried to define a union type on the field type, but it gives me an error.

Any suggestion?



Hi @gianluca. I don’t see problems with your definition of the union type, but I wonder what tool you are using that gives you a different intention. Can you clarify precisely what you are using and the error that you see in that tool?


Hi @christian_vogel,

I am using the API Designer in Anypoint Mulesoft.
I don’t think the issue is with the union type at all.
As far as I can see the issue is with the “types:” snippet.
When present, the API Designer in Mulesoft renders a blank box where the method definition normally appears. In the console it is possible to see some Javascript error, not meaningful to me honestly.

Any help is much appreciated.



I agree - its probably a problem with the following component https://github.com/mulesoft/api-console. May I asked to raise an issue with a clear description, a RAML, and an image of the problem?