[BUG] Failed to add required=false
Created by: lzmthscarvalho
Description: There is not required=false in in RequestPart from generated API source code.
We call API without file (possibly by specification of API), then we receive:
2019-01-31 13:18:52.506 WARN 13343 --- [nio-2004-exec-5] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]
When replace RequestPart("file") to @RequestPart(value="file", required=false), I do not receive this error, how previous expected. In this way, we add to pom.xml:
<replacement> <token>RequestPart\(\"file\"\)</token> <value>RequestPart\(value=\"file\"\, required=false\)</value> </replacement>
openapi-generator version: 3.3.4
OpenAPI declaration file content:
` summary: 'Create a marker'
description: 'Create a new Marker with a optional media, that can be audio or image'
requestBody:
content:
multipart/form-data:
schema:
type: object
required:
- marker
properties:
marker:
type: object
$ref: '#/components/schemas/Marker'
file:
type: string
format: binary
` link: https://github.com/lztcf/bug-openapi3/blob/master/src/main/resources/api.yaml
Command line used for generation: mvn generate-sources Part of generated code:
default ResponseEntity<Marker> markerPost(@ApiParam(value = "", required=true, defaultValue="null") @RequestParam(value="marker", required=true) Marker marker,@ApiParam(value = "file detail") @Valid @RequestPart("file") MultipartFile file) {
Steps to reproduce:
I made a little project that reproduce the bug: https://github.com/lztcf/bug-openapi3
Related issues/PRs:
Like described in https://github.com/OpenAPITools/openapi-generator/issues/1646, we replaced RequestParam to RequestPart: @RequestParam(value="marker", required=true) to @RequestPart(value="marker", required=true).