【问题标题】:API Blueprint - Use Data Strucutres in response, without AttributesAPI 蓝图 - 使用数据结构作为响应,没有属性
【发布时间】:2016-09-16 05:14:37
【问题描述】:

我正在使用 Apiary 来模拟一个新的 API。

我试图避免一遍又一遍地写出所有 JSON 响应。如果我使用+ Attributes(user) 这样做,那么它将在机器面板中自动生成一堆属性块,这在我看来非常令人困惑(尤其是当您有多个响应时)。

如果您手动写出 JSON 请求/响应块,生成的文档看起来会更好。

有没有办法将请求/响应对象存储为数据结构?也许是模特?

我希望能够做这样的事情:

## Users [/auth]
A user object contains the these attributes.

+ Attributes (user) <!-- I like this here -->

### Refresh a token for a user [POST /auth/refresh]

+ Request (application/json)
    + Headers

            Authorization: Bearer jsonWebToken


+ Response 200 (application/json)          
    + Body

            {
                "data": [
                    (user) <!-- I wish this was the user data structure as JSON -->
                ],
                "meta": {
                    "access_token": "jsonWebToken",
                    "token_type": "Bearer",
                    "expires_in": 3600
                }
            }



# Data Structures

## user (object)
+ id: 123 (number)
+ email: drew@funkhaus.us

注意:user 对象在现实生活中有 30 个属性。

【问题讨论】:

    标签: apiblueprint apiary.io apiary mson


    【解决方案1】:

    不幸的是,这不是受支持的方案,您不能将数据结构添加到您的 JSON 有效负载中。

    所以,如果我理解正确 - 使用属性很好,但您希望将它们隐藏在文档中。你能确认一下吗?

    【讨论】:

    • 是的,我可以使用属性,只要它没有在机器面板(最右边蓝色的那个)中生成块。
    • 你可能想在 Apiary 本身中打开一个问题。只需使用您的帐户连接到该网站并使用内部聊天来提出问题 - 我们会尽力解决它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多