【问题标题】:How to specify multiple possible types (type union) for array in MSON?如何为 MSON 中的数组指定多种可能的类型(联合类型)?
【发布时间】:2017-07-03 16:39:37
【问题描述】:

我有点难以准确描述我需要什么,但我花了一些时间浏览 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 中表达它以便验证吗?实际上,我想选择或键入鸟和鱼的联合。我不介意明确写出类。

非常感谢。

【问题讨论】:

    标签: apiblueprint mson


    【解决方案1】:

    既然你可以明确地写出类,我认为这可以通过写出数组接受的类型来完成(这些都是 Animal 的子类)。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      • 2018-11-21
      • 2021-08-14
      • 1970-01-01
      • 2017-11-07
      • 2020-10-29
      相关资源
      最近更新 更多