Skip to content

[BUG] [JAVA] Optional multipart/form-data 'file' parameter #6677

@nikhilr57

Description

@nikhilr57
Description

Not able to set multipart/form-data 'Multipart' file parameter as optional

openapi-generator version

OpenAPI version used: 4.3.1

OpenAPI declaration file content or url

openAPI YAML snippet:

  /v1/example/{exampleId}:
    post:
      parameters:
      - name: exampleId
        in: path
        required: true
        schema:
          type: string
          format: uuid
          example: '7dcf6a62-3039-40fc-b93d-d4b0d89885e6'
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  description: Source file to be uploaded
                  format: binary
                jsonObject:
                  type: string
                  description: JSON object
                fileTags1:
                  type: string
              required:
              - fileTags1
      responses:
        200:
          description: OK
      deprecated: false

openAPI generated Java snippet:

    /**
     * POST /v1/example/{exampleId}
     *
     * @param exampleId  (required)
     * @param file Source file to be uploaded (optional)
     * @param jsonObject JSON object (optional)
     * @param fileTags1  (required)
     * @return OK (status code 200)
     */
    @ApiOperation(value = "", nickname = "v1ExampleExampleIdPost", notes = "", authorizations = {
        @Authorization(value = "bearerAuth")
    }, tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "OK") })
    @RequestMapping(value = "/v1/example/{exampleId}",
        consumes = { "multipart/form-data" },
        method = RequestMethod.POST)
    default ResponseEntity<Void> v1ExampleExampleIdPost(
      @ApiParam(value = "",required=true) @PathVariable("exampleId") UUID exampleId,
      @ApiParam(value = "Source file to be uploaded") @Valid @RequestPart(value = "file") MultipartFile file,
      @ApiParam(value = "JSON object") @RequestPart(value="jsonObject", required=false)  String jsonObject,
      @ApiParam(value = "") @RequestPart(value="fileTags1", required=true)  String fileTags1) {
        return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

    }

Please suggest any way to make this file optional or is it possible to update the RequestPart tag
with "required=false"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions