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.

unsupported media type for "application/json; charset=utf-8"

See original GitHub issue

Hi, my company has a rule that we mandatory set Content-Type: application.json; charset=utf-8 to all the request/response header. (I know the charset=utf-8 is probably redundant for json though.) Since OpenAPI Validator drop charactors of Content-Type after the charactor of ; as below, our OpenAPI Validator cannot find the appropriate request body schema and respond unsupported media type application/json.

https://github.com/cdimascio/express-openapi-validator/blob/04a84e513ab253f7d7e655c53bdac7978ba43093/src/middlewares/util.ts#L6-L17

Sample api spec is described as below. Due to the issue above, requests which has Content-Type: application.json; charset=utf-8 cannot be associated with the schema $ref: '#/components/schemas/user'.

paths:
  /user/:userId:
    post:
# --- skip ---
      requestBody:
        content:
          application/json; charset=utf-8:
            schema:
              $ref: '#/components/schemas/user'
# --- skip ---

I think we should use original raw value of Content-Type in request header to find appropriate schema.

https://github.com/cdimascio/express-openapi-validator/blob/04a84e513ab253f7d7e655c53bdac7978ba43093/src/middlewares/openapi.request.validator.ts#L196

If you feel okay with my suggestion, let me create PR.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cdimasciocommented, Nov 17, 2019

fix available in v2.15.1

1reaction
cdimasciocommented, Nov 15, 2019

@mk811 how are you making out? If u have any questions or want to discuss more freely, feel free to join us on gitter. https://gitter.im/cdimascio-oss/community

Read more comments on GitHub >

github_iconTop Results From Across the Web

What does "Content-type: application/json; charset=utf-8 ...
The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format...
Read more >
"application/json; charset=utf-8" not supported - aerogear-dev
Hello Guys Writing code for ProDoctor demo, on client side, I'm using Xcode template for AGPush which is based on AFNetworking 121 When...
Read more >
Make default charset UTF-8 when using `receiveText` for ...
I mean, I expected Content-Type: application/json to be enough here for deserialization to switch to proper JSON (with UTF-8 instead of ISO-8859-1 )....
Read more >
415 unsupported media type
415 unsupported media type · response status 415 with reason content type 'application/json not supported · content-type 'text/plain;charset=utf-8 postman.
Read more >
MediaType (Spring Framework 6.0.3 API)
public class MediaType extends MimeType implements Serializable ... Public constant media type for application/json;charset=UTF-8 .
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