【发布时间】:2016-03-31 22:00:04
【问题描述】:
考虑一下https://github.com/apiaryio/mson#example-1的这段摘录...
示例 1
一个简单的object 结构及其关联的 JSON 表达式。
- id: 1
- name: A green door
- price: 12.50
- tags: home, green
假设我想为name 属性定义有效值。考虑使用 Dredd 等工具进行 API 测试的上下文。我们可能需要定义什么是预期/有效的name 值以响应获取此资源,否则某些东西可能已损坏并且此测试步骤应该失败。
并且/或者,如果创建/更新这种类型的资源,我们可能需要定义哪些name 值是有效/接受的。这目前可以在 MSON 中定义吗?
(我相信这可以在 JSON 模式中完成,这让我对 MSON 支持充满希望。)
以下是一个示例 API 蓝图资源,用于说明如何使用它...
# Thing ID [/api/thing/id]
# List Thing ID attributes [GET]
+ Response 200
+ Attributes
+ href (string)
+ make (string)
+ model (string)
+ version (string)
+ Body
{"href":"/api/thing/id","make":"BrandX","model":"SuperThingy","version":"10.1"}
在上面的示例中,model 属性有 3 个已知/接受/有效值:CoolThingy、AwesomeThingy 和 MLGThingy
我们能否在 MSON 中表示这个资源,这样...
- Apiary(或其他呈现的)API 文档消费者可以轻松了解
model的期望值? - Dredd 在对此资源的 GET 响应中处理并传递/失败
model值?
【问题讨论】:
标签: validation attributes apiblueprint mson