Symfony 如何使用OpenAPI和API平台正确描述请求体?

Symfony 如何使用OpenAPI和API平台正确描述请求体?,symfony,swagger,openapi,api-platform.com,Symfony,Swagger,Openapi,Api Platform.com,我正在努力从内部获得请求主体的正确定义: 从上图中,我的端点所期望的是一个包含必需值的JSON。我正在将所需值定义在路径中,但这是非真的,它们甚至不属于:查询,标题或cookies 我尝试了两种定义(并且删除了一些与解决方案无关的行): 第二个定义如下: resources: App\Entity\Cases: collectionOperations: case_assign: swagger_context: summary: '

我正在努力从内部获得请求主体的正确定义:

从上图中,我的端点所期望的是一个包含必需值的JSON。我正在将所需值定义在
路径中,但这是真的,它们甚至不属于:
查询
标题
cookies

我尝试了两种定义(并且删除了一些与解决方案无关的行):

第二个定义如下:

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
结果如下:

他们似乎都没有做我需要或期望的事情,我做错了什么?我能得到一些帮助吗

我也读了几页/帖子,但没有找到一个好的例子或正确的方法(见以下列表):

您可以使用文档中描述的方法覆盖生成的swagger.json,并更改您喜欢的任何内容。您需要编辑v2的定义

"paths": {
  "/todos": {
    "post": {
      "parameters": [
        {
          "name": "todo",
          "in": "body",
          "description": "The new Todo resource",
          "schema": {
            "$ref": "#/definitions/Todo"
          }
        }
      ]
}}}
"definitions": {
  "Todo": {
    "type": "object",
    "description": "",
    "properties": {
      "text": {
        "required": true,
        "description": "This text will be added to the schema as a description",
        "type": "string"
      },...
或Openapi v3中的components.schemas:

"components": {
  "schemas": {
    "Todo": {
      "type": "object",
      "description": "",
      "properties": {  
        "text": {
          "required": true,
          "minLength": 4,
          "example": "some example text",
          "description": "This text will be added to the schema as a description",
          "type": "string"
        },...
您的另一个选择是使用@apirource或@ApiProperty注释的“swagger_上下文”(“openapi_上下文”用于openapi v3)。有效选项应位于中

将导致:

编辑: 我刚刚注意到您的yaml配置中有一个错误。您正在尝试为阵列设置文档。我想你真的想发送一个对象

   parameters:
        - name: body
          in: body
          required: true
          schema:
            type: object
            required:             #only for swagger v2
               - assign_type
            properties:
              assign_type:
                description: 'The assignee type: worker or reviewer'
                required: true    #only for openapi v3
                type: string
              assigned_by:
                ...

您可以检查的语法是否正确。

看看这是否有帮助:。您文章中的最后一个链接也与您的用例类似。@Helen我在几乎所有示例(不是您共享的示例,而是所有示例)中都看到了引用
$ref:'#/definitions/User'
的用法。我应该将这些引用文件放在我的项目中的什么位置?你有什么想法吗?对不起,我不熟悉API平台。上面的例子是生成的OpenAPI YAML/JSON文件(加载到Swagger UI中)应该是什么样子,以便正确呈现和“尝试”工作。想让你的生活变得轻松吗?那是个好主意。否则,只需从有助于构建OpenAPI规范的@BentCoder中提取所需内容即可,问题是我无法找到如何在使用时使其工作:|
  /**
   * This text will be added to the schema as a description
   * @ApiProperty(
   *     swaggerContext={"required"=true},
   *     openapiContext={"required"=true, "minLength"=4, "example"="some example text"})
   * @ORM\Column(type="string", length=255)
   */
  private $text;
   parameters:
        - name: body
          in: body
          required: true
          schema:
            type: object
            required:             #only for swagger v2
               - assign_type
            properties:
              assign_type:
                description: 'The assignee type: worker or reviewer'
                required: true    #only for openapi v3
                type: string
              assigned_by:
                ...