如何在API蓝图中使枚举变为干

时间:2017-04-06 00:28:24

标签: enums apiblueprint

我正在使用API​​ Blueprint记录API,并且我有几个端点使用具有相同值的相同枚举类型。而不是在使用此枚举的每个点重复所有值,我想将它放在数据结构部分中,只是引用它,从而使它变干。但是,我无法从文档中弄清楚如何将枚举放入数据结构部分。我可以很好地做对象,但是当我在Data Structures部分声明一个枚举时,似乎忽略了指定的成员。

这是一个(非常人为的)我现在拥有的例子(不是DRY):

### Some Request [GET]
+ Parameters
    + name: `sample` (string) - the name
    + type: `A` (enum[string]) - the type
        + Members
            + A
            + B
            + C

### Another Request [GET]
+ Parameters
    + address: `123 St.` (string) - the address
    + type: `B` (enum[string]) - the same type as above
        + Members
            + A
            + B
            + C

以下是我希望能够做到的事情:

### Some Request [GET]
+ Parameters
    + name: `sample` (string) - the name
    + type: `A` (The Type) - the type

### Another Request [GET]
+ Parameters
    + address: `123 St.` (string) - the address
    + type: `A` (The Type) - the type

# Data Structures
## The Type (enum[string])
    + Members
        + A
        + B
        + C

我在这种语法上尝试了一些变体,都没有运气。当然,完全有可能我只是在咆哮错误的树,并且有一种完全不同的方式让重复的枚举成为DRY。

1 个答案:

答案 0 :(得分:2)

问题是你正在尝试使用MSON语法来获取URI参数,但这还没有得到完全支持。由于历史原因,Paramters部分的当前语法仅与Attributes部分的语法对齐,但没有完整的功能奇偶校验。请参阅此RFC

所以我担心你现在无法在Parameters部分使用MSON继承和类型。只能使用简单的结构和类型。