我正在努力准确地描述我需要什么,但我花了一些时间浏览MSON规范,但没有找到任何东西。
这个例子有点做作,但希望用意是明确的。
# 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)我想表达的是,Farm可以包含所有种类的动物,但不能包含基类。有没有某种方法可以在MSON/JSON Schema中表达出来,以便进行验证?实际上,我希望有一个鸟和鱼的选择或类型组合。我不介意显式地写出类。
非常感谢。
发布于 2019-04-06 02:11:39
既然你可以显式地写出类,我认为这可以通过写出数组接受的类型来完成(这些类型恰好都是Animal的子类)。
+ animals (array[Fish, Bird], fixed-type)https://stackoverflow.com/questions/44890479
复制相似问题