【问题标题】:API blueprint MSON to define valid Attribute values?API 蓝图 MSON 来定义有效的属性值?
【发布时间】:2016-03-31 22:00:04
【问题描述】:

考虑一下https://github.com/apiaryio/mson#example-1的这段摘录...

示例 1

一个简单的object 结构及其关联的 JSON 表达式。

MSON

- 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 个已知/接受/有效值:CoolThingyAwesomeThingyMLGThingy

我们能否在 MSON 中表示这个资源,这样...

  • Apiary(或其他呈现的)API 文档消费者可以轻松了解 model 的期望值?
  • Dredd 在对此资源的 GET 响应中处理并传递/失败 model 值?

【问题讨论】:

    标签: validation attributes apiblueprint mson


    【解决方案1】:

    在 MSON 中您可以使用枚举,请参见下面的示例。

    • name (枚举[字符串])
      • joe(默认)
      • ben
      • mark

    【讨论】:

    • 谢谢!我得到了同样的答案,正要回答我自己的问题。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多