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

emeijp43  于 2024-01-08  发布在  其他
关注(0)|答案(1)|浏览(286)

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

  1. POST /example
  2. [
  3. "first parameter",
  4. 7,
  5. [1,2,4,5]
  6. ]

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

  1. "requestBody": {
  2. "required": true,
  3. "content": {
  4. "application\/json": {
  5. "schema": {
  6. "type": "array",
  7. "items": [
  8. {
  9. "type": "string"
  10. },
  11. {
  12. "type": "integer"
  13. },
  14. {
  15. "type": "array",
  16. "items": {
  17. "type": "integer"
  18. }
  19. }
  20. ]
  21. }
  22. }
  23. }
  24. }


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

uubf1zoe

uubf1zoe1#

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

  1. {
  2. "openapi": "3.1.0",
  3. "info": {
  4. "title": "stack",
  5. "version": "1"
  6. },
  7. "servers": [
  8. {
  9. "url": "https://www.host.com"
  10. }
  11. ],
  12. "paths": {
  13. "/thing": {
  14. "post": {
  15. "description": "a post request with positional arguments",
  16. "requestBody": {
  17. "$ref": "#/components/requestBodies/post_request"
  18. },
  19. "responses": {
  20. "201": {
  21. "description": "Created",
  22. "content": {
  23. "application/json": {
  24. "schema": {
  25. "type": "object",
  26. "properties": {}
  27. }
  28. }
  29. }
  30. }
  31. }
  32. }
  33. }
  34. },
  35. "components": {
  36. "requestBodies": {
  37. "post_request": {
  38. "description": "a post request with positional arguments",
  39. "content": {
  40. "application/json": {
  41. "schema": {
  42. "type": "array",
  43. "prefixItems": [
  44. {
  45. "type": "string"
  46. },
  47. {
  48. "type": "integer",
  49. "minimum": 0
  50. },
  51. {
  52. "type": "array",
  53. "items": {
  54. "type": "integer",
  55. "minimum": 0
  56. },
  57. "unevaluatedItems": false
  58. }
  59. ],
  60. "unevaluatedItems": false
  61. },
  62. "examples": {
  63. "post_request": {
  64. "summary": "an example of positional arguments",
  65. "value": [
  66. "test",
  67. 1000,
  68. [123, 456, 789]
  69. ]
  70. }
  71. }
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }

字符串
x1c 0d1x的数据


展开查看全部

相关问题