[BUG][dart-dio-next] Generator uses url encoded contentType even if the server content type requires application/json
See original GitHub issueBug 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
I’m using Asp.Net Core Swashbuckle to generate openapi scheme for my backend. The backend supports multiple content-type variants of application/json
. But generated code uses url encoded content type instead of application/json.
Here’s generated code output which picks first match which is “application/json-patch+json”.
contentType: [
'application/json-patch+json',
'application/json',
'text/json',
'application/_*+json',
].first
But then Did checks if content-type is application/json
then uses json encoding but if it isn’t, it uses url encoding and my server returns HTTP 415 Unsupported Media Type status.
openapi-generator version
5.1.0
OpenAPI declaration file content or url
The OpenAPI declaration that caused this issue was used for private api. So I couldn’t share it here.
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
- Overriding content-type header using command line options provided to generator CLI
- Updating
contentType
matching part to choose most suitable match rather than first one
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
What are the differences between application/json and ...
@buffer My understanding is using JSON as contentType helps when the data to be sent is more complex and involves a lot of...
Read more >Support Content type "application/x-www-form-urlencoded ...
It is sent like query params from client(zerocode)? and the server reads as Key-Value params?
Read more >Solved: application/x-www-form-urlencoded content type err...
Solved: Hi I'm using a webhook created by Unbounce forms. The problem with the webhook is that it sends the payload with a...
Read more >Content Type : x-www-form-urlencoded, form-data and json
Basically there are three ways to send the HTML data to the server. “Content Type : x-www-form-urlencoded, form-data and json” is published by...
Read more >Difference between application/x-www-form-urlencoded and ...
Javarevisited · 1) Both are MIME type which is sent on HTTP header ContentType e.g. · 2) Both are ways to send name-value...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, I don’t think so. Basically for dio and Dart, we only care about
application/json
,application/x-www-form-urlencoded
andmultipart/form-data
. Everything else we need to directly filter out and if none of these match we should probably add a warning and default to json.I’ve already fixed the issue by manually modifying generated dart code (since scheme is generated on runtime on our backend, modifying dart generated code is way easier for me).
But I think this needs to be fixed. Actually I can work on this issue but I might need a bit of direction for contributing (for example which file(s) implements dart-dio-next generation).