question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG][dart-dio-next] Generator uses url encoded contentType even if the server content type requires application/json

See original GitHub issue

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

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
  1. Overriding content-type header using command line options provided to generator CLI
  2. Updating contentType matching part to choose most suitable match rather than first one

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kuhnroyalcommented, May 11, 2021

No, I don’t think so. Basically for dio and Dart, we only care about application/json, application/x-www-form-urlencoded and multipart/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.

1reaction
themisircommented, Apr 28, 2021

Thanks for the report. You can try changing the order of the content-types in the spec around, not sure if that works.

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found