【发布时间】:2020-01-13 11:09:00
【问题描述】:
我正在努力为 Symfony Api Platform 中使用的请求正文获得正确的定义:
从上图中,我的端点期望的是一个包含所需值的 JSON。我将要求的值定义在 path 中,但这是 NOT 正确的,它们甚至不属于:query、header 或 cookies。
我尝试了两个定义(并且我删除了一些与分辨率无关的行):
// the definition result is on the first image on this post
resources:
App\Entity\Cases:
collectionOperations:
case_assign:
swagger_context:
parameters:
- name: assign_type
in: path
description: 'The assignee type: worker or reviewer'
required: true
type: string
// ....
- in: body
name: body
description: 'Object needed to perform a case assignment'
required: true
example: {
"assign_type": "worker",
"assigned_by": 1,
"assigned_to": 1,
"cases": {
"0": 109855,
"1": 109849,
"2": 109845
}
}
第二个定义如下:
resources:
App\Entity\Cases:
collectionOperations:
case_assign:
swagger_context:
summary: 'Assign a worker or a reviewer to a case'
parameters:
- name: body
in: body
required: true
schema:
type: array
items:
assign_type:
name: assign_type
description: 'The assignee type: worker or reviewer'
required: true
type: string
结果如下:
他们似乎都没有做我需要或期望的事情,我做错了什么?我能得到一些帮助吗?
我也阅读了几页/帖子,但没有找到一个很好的例子或正确的方法(请参阅以下列表):
- https://github.com/api-platform/api-platform/issues/1019
- https://api-platform.com/docs/core/swagger/
- https://idratherbewriting.com/learnapidoc/pubapis_swagger_intro.html
- https://swagger.io/docs/specification/describing-parameters/
- https://swagger.io/docs/specification/describing-request-body/
- How to describe this POST JSON request body in OpenAPI (Swagger)?
【问题讨论】:
-
看看这是否有帮助:Describing Request Body in OpenAPI/Swagger 2.0,POST a JSON body with Swagger。您帖子中的最后一个链接也与您的用例类似。
-
@Helen 我在几乎所有示例(不是您共享的示例,而是所有示例)中都看到了引用
$ref: '#/definitions/User'的使用,假设我应该将这些引用文件放在我的项目中吗?你有什么想法吗? -
我对 API 平台不熟悉,抱歉。上面的示例是生成的 OpenAPI YAML/JSON 文件(加载到 Swagger UI 中的文件)的外观,以便正确呈现和“试用”工作。
-
@BentCoder 帮助构建 OpenAPI 规范,这很好,问题是我在使用 API Platform 时找不到如何让它工作:|
标签: symfony swagger openapi api-platform.com