OpenAPITools / OpenAPITools/openapi-generator
[BUG] Failed to add required=false
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OpenAPI declaration's multipart/form-data requestBody and the generated Spring method containing @RequestPart("file"). Run mvn generate-sources against the linked reproducer and compare the generated annotation with the optional file property in the specification. Done means optional multipart files generate required=false without breaking the required marker parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100