如何使 API 蓝图中的枚举变干
How can I make enums in API Blueprint be DRY
我正在使用 API 蓝图记录一个 API,我有几个使用具有相同值的相同枚举类型的端点。我不想在使用此枚举的每个点重复所有值,而是想将其放在“数据结构”部分并仅引用它,从而使其成为 DRY。但是,我无法从文档中弄清楚如何将枚举放入数据结构部分。我可以很好地处理对象,但是当我在数据结构部分声明一个枚举时,它似乎忽略了指定的成员。
这是我现在拥有的(不是 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
我尝试了这种语法的一些变体,但都没有成功。当然,我完全有可能找错树了,有一种完全不同的方法可以让重复的枚举变干。
问题是您正在尝试使用 MSON syntax for URI parameters, but that's not fully supported yet. For historical reasons, the current syntax of the Paramters
section is only aligned with the syntax of the Attributes
section, but there's not a full feature parity. See this RFC。
因此,恐怕您现在无法在 Parameters
部分中使用 MSON 继承和类型。只能使用简单的结构和类型。
我正在使用 API 蓝图记录一个 API,我有几个使用具有相同值的相同枚举类型的端点。我不想在使用此枚举的每个点重复所有值,而是想将其放在“数据结构”部分并仅引用它,从而使其成为 DRY。但是,我无法从文档中弄清楚如何将枚举放入数据结构部分。我可以很好地处理对象,但是当我在数据结构部分声明一个枚举时,它似乎忽略了指定的成员。
这是我现在拥有的(不是 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
我尝试了这种语法的一些变体,但都没有成功。当然,我完全有可能找错树了,有一种完全不同的方法可以让重复的枚举变干。
问题是您正在尝试使用 MSON syntax for URI parameters, but that's not fully supported yet. For historical reasons, the current syntax of the Paramters
section is only aligned with the syntax of the Attributes
section, but there's not a full feature parity. See this RFC。
因此,恐怕您现在无法在 Parameters
部分中使用 MSON 继承和类型。只能使用简单的结构和类型。