【问题标题】:defining json post parameters in apiary在 apiary 中定义 json post 参数
【发布时间】:2015-07-14 14:14:53
【问题描述】:

我正在尝试使用 json 发布请求为项目创建文档。
现在对于 get 请求,我可以轻松定义 uri 参数。

但是我想对 json 和其他 post 请求做同样的事情。
我试过并希望它可以像下面那样工作,它显示示例中的参数,但它似乎不是这样做的方法......
有没有办法正确地做到这一点?

## Post Inbound [/ws/3/inbound]
### Post Inbound [POST]


+ Request

        {
            "authentication":
                {
                    "location":"{location}",
                    "customer_id":{customer_id},
                    "context":"{context}"
                },
            "date":"",
            "reference":"",
            "details":
            [
                {
                    "article_code":"",
                    "qty_expected":
                },
                {
                    "article_code":"",
                    "qty_expected":
                }
            ]
        }

+ Parameters
    + location (required, string) - Target url of the wics server 
    + customer_id (required, int) - Customer ID
    + context (required, string) - Authentication context gotten from login
    + date (required, date) - Date format as yyyy-mm-dd
    + reference (required, string) - Reference
    + article_code (required, string) - Article code
    + qty_expected (required, int) - Quantity expected.

【问题讨论】:

    标签: apiblueprint apiary.io apiary


    【解决方案1】:

    Parameters 关键字用于指示 API 蓝图中的 URI parameters,而Attributes 关键字用于指示属性,例如在请求或响应正文中给出的属性。

    根据您的请求,这将类似于以下内容:

    ## Post Inbound [/ws/3/inbound]
    ### Post Inbound [POST]
    
    + Request (application/json)
    
        + Attributes
            + authentication (required, object)
                + location (required, string) - Target url of the wics server 
                + customer_id (required, number) - Customer ID
                + context (required, string) - Authentication context gotten from login
            + date: `2015-12-30` (required, string) - Date format as yyyy-mm-dd
            + reference (required, string) - Reference
            + details (required, array)
                + (object)
                    + article_code (required, string) - Article code
                    + qty_expected (required, number) - Quantity expected.
    
    + Response 204
    

    并在 Apiary 中呈现:

    可以在https://github.com/apiaryio/mson 找到 MSON 的完整规范(API 蓝图中使用的对象表示法的语法)。

    【讨论】:

      猜你喜欢
      • 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
      相关资源
      最近更新 更多