swagger-api / swagger-api/swagger-codegen
[Spring] Generated server code for multipart/form-data request ignores encoding section.
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
As described in https://swagger.io/docs/specification/describing-request-body/multipart-requests, it is possible in OpenAPI 3.0.0 to specify for a multipart request an encoding section for example to enforce contentType or the presence of a specific header in the MIME part. However the server-side code generation seems to completely ignore this section.
Swagger-codegen version
3.0.26
Swagger declaration file content or url
openapi: 3.0.0
info:
version: "0.1"
title: testbug
paths:
/testbug:
post:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
attachment:
type: string
format: binary
encoding:
attachment:
contentType: application/pdf
headers:
Content-ID:
schema:
type: string
responses:
'201':
description: Successful response.
content:
text/plain:
schema:
type: string
Command line used for generation
java -jar .\swagger-codegen-cli-3.0.26.jar generate -l spring -i testbug.yaml -o testbug
Steps to reproduce
java -jar .\swagger-codegen-cli-3.0.26.jar generate -l spring -i testbug.yaml -o testbug
In the generated server-side code I find nowhere a constraint on contentType = application/pdf and neither on the presence of a header Content-ID nor a way to retrieve the Content-ID using the generated Java code.
The issue was tested with multipart/form-data but also with multipart/related (having a way to retrieve Content-ID would mainly be interesting for us when using multipart/related).
Related issues/PRs
None.
Suggest a fix/enhancement
None.
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 by running the reported Spring generation command with the provided OpenAPI document and inspect the generated server-side code for the multipart request. Trace how the multipart/form-data and multipart/related encoding sections are handled during generation. Done means the generated Java server code reflects the declared part content type and provides a way to access the Content-ID header.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100