gpt4 book ai didi

api - 尝试使用 API 蓝图中的数据结构来描述请求和响应

转载 作者:行者123 更新时间:2023-12-03 05:04:03 25 4
gpt4 key购买 nike

我正在尝试使用规范的新属性和数据结构部分,通过 API 蓝图记录端点。

我的请求负载如下所示:

{
"url": "http://requestb.in/11v7i7e1",
"active": true,
"types": [
{
"name": "sales",
"version": "2.0"
},
{
"name": "products",
"version": "2.0"
}
]
}

我的响应负载看起来像这样:

{
"data": {
"id": "dc85058a-a683-11e4-ef46-e9431a15be8c",
"url": "http://requestb.in/11v7i7e1",
"active": true,
"types": [
{
"name": "products",
"version": "2.0"
},
{
"name": "sales",
"version": "2.0"
}
]
}
}

我尝试了以下 API 蓝图 Markdown :

FORMAT: 1A

# Vend REST API 2.0

# Group Webhooks

## api/2.0/webhooks [/webhooks]

### List all Webhooks [GET]
Returns a list of Webhooks created by the authorised application.

+ Response 200 (application/json)
+ Attributes (Webhook Collection)

### Add a new Webhook [POST]
Creates a new Webhook.

+ Attributes (Webhook Base)

+ Request (application/json)
+ Attributes (Webhook Base)

+ Response 200 (application/json)
+ Attributes (Webhook Response)

# Data Structures

## Webhook Base (object)
+ url: https://example.com/webhook (string, required) - The address where webhooks requests should be submitted.
+ active: true (boolean, required) - This field can be used to inspect or edit state of the webhook.
+ types: array[Webhook Type] (array[Webhook Type], required) - Collection of Webhook types which should trigger Webhook event.

## Webhook Response Base (Webhook Base)
+ id: dc85058a-a683-11e4-ef46-e8b98f1a7ae4 (string, required) - Webhook `id`.

## Webhook Response (object)
+ data: webhook (Webhook Response Base, required)

## Webhook Type (object)
+ name: sales (string, required) - One of: products, sales, customers, taxes
+ version: 2.0 (string, required) - Version of the payload to be delivered. Currently the only supported value is "2.0".

## Webhook Collection (object)
+ data: array[Webhook Response Base] (array[Webhook Response Base], required) - An array of Webhook objects.

现在,当在 Apiary 中查看它时,它告诉我这是一个有效的 API 蓝图文档,但它不告诉我 JSON 预览请求和响应的方式。像这样的结构是否可以在 API 蓝图中表示并能够在 Apiary 中很好地呈现?

最佳答案

这是两个问题的组合:

  1. 语法不正确
  2. 渲染错误

1。语法

问题似乎出在这里:

## Webhook Collection (object)
+ data: array[Webhook Response Base] (array[Webhook Response Base], required) - An array of Webhook objects.

查看+数据:数组[Webhook 响应基础] (数组[Webhook 响应基础])。基本上,当需要一个值时(在 : 之后),应该提供一个值。相反,在本例中,您有一个类型 array[Webhook Response Base]

让我演示一个更简单的示例:

+ data: number (array[number])

不正确

正确的版本是

+ data: 42 (array[number])

+ data (array[number])
+ 42

+ data (array)
+ 42 (number)

2。渲染错误

即使您更正蓝图,它也不会在 Apairy 中渲染。这是我们在 JSON 渲染器中发现的一个错误。这里已经报道了https://github.com/apiaryio/drafter.js/issues/26我们计划尽快修复它。

This has been fixed now

更正蓝图

FORMAT: 1A

# Vend REST API 2.0

# Group Webhooks

## api/2.0/webhooks [/webhooks]

### List all Webhooks [GET]
Returns a list of Webhooks created by the authorised application.

+ Response 200 (application/json)
+ Attributes (Webhook Collection)

### Add a new Webhook [POST]
Creates a new Webhook.

+ Attributes (Webhook Base)

+ Request (application/json)
+ Attributes (Webhook Base)

+ Response 200 (application/json)
+ Attributes (Webhook Response)

# Data Structures

## Webhook Base (object)
+ url: https://example.com/webhook (string, required) - The address where webhooks requests should be submitted.
+ active: true (boolean, required) - This field can be used to inspect or edit state of the webhook.
+ types (array[Webhook Type], required) - Collection of Webhook types which should trigger Webhook event.

## Webhook Response Base (Webhook Base)
+ id: dc85058a-a683-11e4-ef46-e8b98f1a7ae4 (string, required) - Webhook `id`.

## Webhook Response (object)
+ data (Webhook Response Base, required)

## Webhook Type (object)
+ name: sales (string, required) - One of: products, sales, customers, taxes
+ version: 2.0 (string, required) - Version of the payload to be delivered. Currently the only supported value is "2.0".

## Webhook Collection (object)
+ data (array[Webhook Response Base], required) - An array of Webhook objects.
<小时/>

希望这能回答您的问题。如果需要进一步说明,请告诉我。

关于api - 尝试使用 API 蓝图中的数据结构来描述请求和响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29810814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com