【问题标题】:How can I make enums in API Blueprint be DRY如何使 API Blueprint 中的枚举变为 DRY
【发布时间】:2017-04-06 00:28:24
【问题描述】:

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

这是我现在拥有的一个(非常做作的)示例(不是 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

我已经尝试了这种语法的一些变体,但都没有运气。当然,我完全有可能只是找错了树,还有一种完全不同的方法可以让重复的枚举变干。

【问题讨论】:

    标签: enums apiblueprint


    【解决方案1】:

    问题是您正在尝试对 URI 参数使用 MSON 语法,但尚未完全支持。由于历史原因,Paramters 部分的当前语法仅与 Attributes 部分的语法对齐,但没有完整的功能奇偶校验。看到这个RFC

    所以恐怕您现在无法在Parameters 部分中使用 MSON 继承和类型。只能使用简单的结构和类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多