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

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

我有以下招摇yaml文件

/tasks/{id}/documents/files/data:
    post:
      tags:
        - task-documents
      summary: Upload document
      description: Upload document
      operationId: uploadDocument
      parameters:
        - name: id
          in: path
          description: ID
          required: true
          schema:
            type: string
      requestBody:
        content:
          multipart/form-data:
            schema:
              required:
                - json
                - upfile
              type: object
              properties:
                upfile:
                  type: string
                  description: Document Content InputStream
                  format: binary
                json:
                  description: Document Metadata
                  $ref: "#/components/schemas/UploadRequest"
        required: true
      responses:
        200:
          description: successful operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Document'
        401:
          description: Unauthorized
          content: {}
        500:
          description: Internal Server Error
          content: {}
components:
  schemas:
     UploadRequest:
      type: object
      properties:
        documentName:
          type: string
          description: File Name of Document
        contentType:
          type: string
          description: Mime type of document file
        description:
          type: string
          description: Description for document
      required:
        - contentType

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

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

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

@POST
    @Path("/{id}/documents/files/data")
    @Consumes({ "multipart/form-data" })
    @Produces({ "application/json" })
    @ApiOperation(value = "Upload document", notes = "Upload document", response = Document.class, authorizations = {
        @Authorization(value = "cut_basic"),
        @Authorization(value = "cut_oauth", scopes = {
        @AuthorizationScope(scope = "", description = "")})}, tags={ "documents", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "successful operation", response = Document.class),
        @ApiResponse(code = 401, message = "Unauthorized", response = Document.class), 
        @ApiResponse(code = 500, message = "Internal Server Error", response = Document.class)})
    public Response uploadDocument(@Context UriInfo uriInfo, @FormDataParam("upfile") InputStream upfileInputStream, @FormDataParam("upfile") FormDataContentDisposition upfileDetail
,@Parameter(description = "", required=true)@FormDataParam("json")  UploadRequest json
,@Parameter(description = "ID",required=true) @PathParam("id") String id, @Context SecurityContext securityContext) throws NotFoundException {

        LOG.debug("Upload document : Upload document");
        LOG.debug( "upfile :" + upfile + ", " +  "json :" + json + ", " +  "id :" + id + ", " +  ";");
        delegate.setProviders(providers);
        Response response = delegate.uploadDocument(uriInfo,upfileInputStream, upfileDetail,json,id,securityContext);

        LOG.debug("Exiting - uploadDocument");
        return response;
    }

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

--Boundary_123456789_123456789
Content_transfer-Encoding: binary
Content-Disposition: form-data; name="upfile"; filename="test.txt"

I am a test file!!!

--Boundary_123456789_123456789
Content-Disposition: form-data; name="json"
Content-Type: application/json
{
  "documentName": "string",
  "contentType": "string",
  "description": "string"
}

--Boundary_123456789_123456789--

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

暂无答案!

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

相关问题