Array with multiple types RAML 0.8


#1

Hi

I’m trying to model an array that could have multiple types.

So I have two schema declared schemaA and schemaB and would like to model a response that could have both these objects.

Can I do something like:

"objectives": {
        "type": "array",
        "items": {
            "$ref": "schemaA | schemaB"
        }
    }

#2

In JSON I think you might want to look at http://spacetelescope.github.io/understanding-json-schema/reference/combining.html. That’s the only resource I know off.

In RAML 1.0 you can use RAML Data Types to do that:

types:
  schemaA:
  schemaB:
  objectives:
    type: array
    items: schemaA | schemaB

#3

Once you go black, you’ll never go back. Seriously, 1.0 is sooo much better than 0.8.


#4

Agreed. I am just starting on that path now, and 1.0 is such a huge and beautiful improvement over 0.8! It will truly allow you to design complex APIs using modular pieces and all in YAML!


#5

thanks all for the reply. I guess I’m stuck at RAML 0.8 coz the plugin https://github.com/mulesoft/raml-for-jax-rs is yet to catch up with RAML 1.0. https://github.com/mulesoft/raml-for-jax-rs