user1915201
user1915201

Reputation: 103

How to specify multiple possible types (type union) for array in MSON?

I'm struggling a bit to describe what I need exactly but I spent some time browsing the MSON spec and didn't find anything.

This example is a bit contrived but hopefully the intention is clear.

# Animal (object)

This is a base class for all animals. It provides some common structure.

## Properties
 ... some properties

# Bird (Animal)

## Properties
 ... some properties

# Fish (Animal)

## Properties
 ... some properties

# Farm (Object)

## Properties
 + animals (array[Animal], fixed-type)

I want to express that the Farm can contain all kinds of animals but NOT the base class. Is there some way to express that in MSON/JSON Schema so that it validates? Effectively I want to have a choice or type union of Bird and Fish. I don't mind writing out the classes explicitly.

Thanks so much.

Upvotes: 4

Views: 261

Answers (1)

Holly
Holly

Reputation: 1217

Since you're okay writing out the classes explicitly, I think this can be done by writing out what types the array accepts (which all happen to be subclasses of Animal).

+ animals (array[Fish, Bird], fixed-type)

Upvotes: 1

Related Questions