OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][SPRING] @RequestBody & application/x-www-form-urlencoded give 415 Unsupported Media Type
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
It's seems that Spring doesn't understand it as a RequestBody when using application/x-www-form-urlencoded
A quick workaround is to override the bodyParams.mustache and remove the @RequestBody in it, for my case it was enough
(by the way, this override possibility is just a fantastic idea)
There is no specific generation problem, neither start one, but when I call the API I get a 415 - Unsupported Media Type
I tried to correct this thing to PR but I can't figure how, on what param should I lean to set up this @RequestBody (or ot) ?
openapi-generator version
5.2.1
OpenAPI declaration file content or url
(quick extract may be no correctly indent)
openapi: 3.0.0
paths:
/insert:
post:
summary: ''
operationId: post-insert
responses:
'200':
description: OK
content:
application/json: [...]
requestBody:
$ref: '#/components/requestBodies/DataBody'
components:
requestBodies:
DataBody:
description: ''
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/Data'
schemas:
Data:
title: Data
type: object
properties:
DATA:
type: string
format: byte
Generation Details
generatorName: spring
library: spring-boot
No generation problem
Steps to reproduce
Create spring app with it
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 Spring generator's bodyParams.mustache and reproduce the provided OpenAPI example using application/x-www-form-urlencoded. Check how the generated @RequestBody parameter is handled, then verify the generated Spring application no longer returns 415 Unsupported Media Type for this request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100