swagger 如何在OpenAPI中为POST主体定义位置参数?

emeijp43  于 5个月前  发布在  其他
关注(0)|答案(1)|浏览(56)

我正在尝试为一个现有的API创建一个OpenAPI描述。该API需要在帖子正文中的数组中的位置参数。
举例来说:

POST /example

[
  "first parameter",
  7,
  [1,2,4,5]
]

字符串
正确的定义是什么?我的想法是沿着以下路线:

"requestBody": {
  "required": true,
  "content": {
    "application\/json": {
      "schema": {
        "type": "array",
        "items": [
          {
            "type": "string"
          },
          {
            "type": "integer"
          },
          {
            "type": "array",
            "items": {
              "type": "integer"
            }
          }
        ]
      }
    }
  }
}


但这显然是错误的。正确的方法是什么?

uubf1zoe

uubf1zoe1#

这里是一个OAS 3.1.0版本的位置参数。看起来Swagger editor-next在requestBody $ref上有一些问题,但它似乎也成功地解决了这个问题。不确定,我根本没有使用swagger。我们使用Redocly。

{
    "openapi": "3.1.0",
    "info": {
        "title": "stack",
        "version": "1"
    },
    "servers": [
        {
            "url": "https://www.host.com"
        }
    ],
    "paths": {
        "/thing": {
            "post": {
                "description": "a post request with positional arguments",
                "requestBody": {
                    "$ref": "#/components/requestBodies/post_request"
                },
                "responses": {
                    "201": {
                        "description": "Created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {}
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "requestBodies": {
            "post_request": {
                "description": "a post request with positional arguments",
                "content": {
                    "application/json": {
                        "schema": {
                            "type": "array",
                            "prefixItems": [
                                {
                                    "type": "string"
                                },
                                {
                                    "type": "integer",
                                    "minimum": 0
                                },
                                {
                                    "type": "array",
                                    "items": {
                                        "type": "integer",
                                        "minimum": 0
                                    },
                                    "unevaluatedItems": false
                                }
                            ],
                            "unevaluatedItems": false
                        },
                        "examples": {
                            "post_request": {
                                "summary": "an example of positional arguments",
                                "value": [
                                        "test",
                                         1000,
                                         [123, 456, 789]
                                    ]
                            }
                        }
                    }
                }
            }
        }
    }
}

字符串
x1c 0d1x的数据


相关问题