从swagger codegen v3为多部分表单数据生成的对象为空

iqjalb3h  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(316)

我有以下招摇yaml文件

  1. /tasks/{id}/documents/files/data:
  2. post:
  3. tags:
  4. - task-documents
  5. summary: Upload document
  6. description: Upload document
  7. operationId: uploadDocument
  8. parameters:
  9. - name: id
  10. in: path
  11. description: ID
  12. required: true
  13. schema:
  14. type: string
  15. requestBody:
  16. content:
  17. multipart/form-data:
  18. schema:
  19. required:
  20. - json
  21. - upfile
  22. type: object
  23. properties:
  24. upfile:
  25. type: string
  26. description: Document Content InputStream
  27. format: binary
  28. json:
  29. description: Document Metadata
  30. $ref: "#/components/schemas/UploadRequest"
  31. required: true
  32. responses:
  33. 200:
  34. description: successful operation
  35. content:
  36. application/json:
  37. schema:
  38. $ref: '#/components/schemas/Document'
  39. 401:
  40. description: Unauthorized
  41. content: {}
  42. 500:
  43. description: Internal Server Error
  44. content: {}
  45. components:
  46. schemas:
  47. UploadRequest:
  48. type: object
  49. properties:
  50. documentName:
  51. type: string
  52. description: File Name of Document
  53. contentType:
  54. type: string
  55. description: Mime type of document file
  56. description:
  57. type: string
  58. description: Description for document
  59. required:
  60. - contentType

我的build.gradle文件包含以下生成代码的条目。

  1. // Swagger
  2. compile "io.swagger.codegen.v3:swagger-codegen:${versions.swaggerCodegenVersion}"
  3. swaggerCodegen "io.swagger.codegen.v3:swagger-codegen-cli:${versions.swaggerCodegenVersion}"
  4. implementation "io.swagger:swagger-annotations:${versions.swaggerVersion}"
  5. implementation group: 'io.swagger.codegen.v3', name: 'swagger-codegen-generators', version: '1.0.23'

swagger-codegen-v3正在我的api类中生成以下方法。

  1. @POST
  2. @Path("/{id}/documents/files/data")
  3. @Consumes({ "multipart/form-data" })
  4. @Produces({ "application/json" })
  5. @ApiOperation(value = "Upload document", notes = "Upload document", response = Document.class, authorizations = {
  6. @Authorization(value = "cut_basic"),
  7. @Authorization(value = "cut_oauth", scopes = {
  8. @AuthorizationScope(scope = "", description = "")})}, tags={ "documents", })
  9. @ApiResponses(value = {
  10. @ApiResponse(code = 200, message = "successful operation", response = Document.class),
  11. @ApiResponse(code = 401, message = "Unauthorized", response = Document.class),
  12. @ApiResponse(code = 500, message = "Internal Server Error", response = Document.class)})
  13. public Response uploadDocument(@Context UriInfo uriInfo, @FormDataParam("upfile") InputStream upfileInputStream, @FormDataParam("upfile") FormDataContentDisposition upfileDetail
  14. ,@Parameter(description = "", required=true)@FormDataParam("json") UploadRequest json
  15. ,@Parameter(description = "ID",required=true) @PathParam("id") String id, @Context SecurityContext securityContext) throws NotFoundException {
  16. LOG.debug("Upload document : Upload document");
  17. LOG.debug( "upfile :" + upfile + ", " + "json :" + json + ", " + "id :" + id + ", " + ";");
  18. delegate.setProviders(providers);
  19. Response response = delegate.uploadDocument(uriInfo,upfileInputStream, upfileDetail,json,id,securityContext);
  20. LOG.debug("Exiting - uploadDocument");
  21. return response;
  22. }

当我尝试点击请求时,我总是将uploadrequest对象设为null,尽管我是以下面的格式传递值。但是,我正确地填充了formdatacontentdisposition和inputstream。

  1. --Boundary_123456789_123456789
  2. Content_transfer-Encoding: binary
  3. Content-Disposition: form-data; name="upfile"; filename="test.txt"
  4. I am a test file!!!
  5. --Boundary_123456789_123456789
  6. Content-Disposition: form-data; name="json"
  7. Content-Type: application/json
  8. {
  9. "documentName": "string",
  10. "contentType": "string",
  11. "description": "string"
  12. }
  13. --Boundary_123456789_123456789--

不太清楚里面发生了什么。有人能帮我解释一下为什么json对象是空的吗。我是不是漏了什么?

暂无答案!

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

相关问题