从swaggerhub生成的spring引导代码无法在其他属性上抛出400

vxqlmq5t  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(218)

我已经登录到swaggerhub并生成了一个示例库存api,它是他们模板的一部分。在 codegen options 挑选出来的 spring 作为服务器。勾选 useBeanValidation 复选框。生成代码,测试代码。验证工作正常,除了一件事。我不想在post负载上允许任何附加属性。
注意:openapi规范没有指定“additionalproperties”标志。在我的理解中默认为“假”。我也试图明确指定相同的。但运气不好。添加additionalproperty时不会引发异常。
openapi规范

  1. openapi: 3.0.0
  2. servers:
  3. # Added by API Auto Mocking Plugin
  4. - description: SwaggerHub API Auto Mocking
  5. url: https://virtserver.swaggerhub.com/xxxx/apionopenApi3/1.0.0
  6. info:
  7. description: This is a simple API
  8. version: "1.0.0"
  9. title: Simple Inventory API
  10. contact:
  11. email: you@your-company.com
  12. license:
  13. name: Apache 2.0
  14. url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
  15. tags:
  16. - name: admins
  17. description: Secured Admin-only calls
  18. - name: developers
  19. description: Operations available to regular developers
  20. paths:
  21. /inventory:
  22. get:
  23. tags:
  24. - developers
  25. summary: searches inventory
  26. operationId: searchInventory
  27. description: |
  28. By passing in the appropriate options, you can search for
  29. available inventory in the system
  30. parameters:
  31. - in: query
  32. name: searchString
  33. description: pass an optional search string for looking up inventory
  34. required: false
  35. schema:
  36. type: string
  37. - in: query
  38. name: skip
  39. description: number of records to skip for pagination
  40. schema:
  41. type: integer
  42. format: int32
  43. minimum: 0
  44. - in: query
  45. name: limit
  46. description: maximum number of records to return
  47. schema:
  48. type: integer
  49. format: int32
  50. minimum: 0
  51. maximum: 50
  52. responses:
  53. '200':
  54. description: search results matching criteria
  55. content:
  56. application/json:
  57. schema:
  58. type: array
  59. items:
  60. $ref: '#/components/schemas/InventoryItem'
  61. '400':
  62. description: bad input parameter
  63. post:
  64. tags:
  65. - admins
  66. summary: adds an inventory item
  67. operationId: addInventory
  68. description: Adds an item to the system
  69. responses:
  70. '201':
  71. description: item created
  72. '400':
  73. description: 'invalid input, object invalid'
  74. '409':
  75. description: an existing item already exists
  76. requestBody:
  77. content:
  78. application/json:
  79. schema:
  80. $ref: '#/components/schemas/InventoryItem'
  81. description: Inventory item to add
  82. components:
  83. schemas:
  84. InventoryItem:
  85. type: object
  86. additionalProperties: False
  87. required:
  88. - id
  89. - name
  90. - manufacturer
  91. - releaseDate
  92. properties:
  93. id:
  94. type: string
  95. format: uuid
  96. example: d290f1ee-6c54-4b01-90e6-d701748f0851
  97. name:
  98. type: string
  99. example: Widget Adapter
  100. releaseDate:
  101. type: string
  102. format: date-time
  103. example: '2016-08-29T09:12:33.001Z'
  104. manufacturer:
  105. $ref: '#/components/schemas/Manufacturer'
  106. Manufacturer:
  107. required:
  108. - name
  109. properties:
  110. name:
  111. type: string
  112. example: ACME Corporation
  113. homePage:
  114. type: string
  115. format: url
  116. example: 'https://www.acme-corp.com'
  117. phone:
  118. type: string
  119. example: 408-867-5309
  120. type: object
  121. additionalProperties: False

在post-api上得到了400。

  1. {
  2. "id": "7f125802-7840-4ff0-8ddb-7c78c0948987",
  3. "name11111": "Widget Adapter",
  4. "releaseDate": "2016-08-29T09:12:33.001Z",
  5. "manufacturer": {
  6. "name": "ACME Corporation",
  7. "homePage": "",
  8. "phone": "408-867-5309"
  9. }
  10. }

预计400,但没有得到这个有效载荷在岗位上

  1. {
  2. "id": "7f125802-7840-4ff0-8ddb-7c78c0948983",
  3. "name": "Widget Adapter",
  4. "releaseDate": "2016-08-29T09:12:33.001Z",
  5. "manufacturer": {
  6. "name": "ACME Corporation",
  7. "homePage": "",
  8. "phone": "408-867-5309"
  9. },
  10. "newkey" : "newValue"
  11. }

有谁能帮忙吗。。我想完全不允许其他属性,并对这些请求抛出400。。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题