Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MediaType Validation does not support case insensitive Charset #463

Closed
tobiasvoelke opened this issue Nov 17, 2020 · 3 comments
Closed

MediaType Validation does not support case insensitive Charset #463

tobiasvoelke opened this issue Nov 17, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@tobiasvoelke
Copy link

Describe the bug
According to RFC2046 the charset in media types should be case insensitive. Whenever I pass a content-type where the charset does not match the case of the api spec I receive unsupported media type <...>. In case of a uppercase charset in the api spec even setting only the media type will fail

To Reproduce

  1. Provide API Spec containing a content-type with charset like e.g. 'application/json; charset=UTF-8'
    Send a request with content-type 'application/json; charset=utf-8' or 'application/json'

  2. Provide API Spec containing a content-type with charset like e.g. 'application/json; charset=utf-8'
    Send a request with content-type 'application/json; charset=UTF-8'

Actual behavior
Media Type validation fails with unsupported media type <...>

Expected behavior
Should accept charsets that only differ in casing

Examples and context

const express = require('express');
const bodyParser = require('body-parser')

const app = express();
const OpenApiValidator = require('express-openapi-validator');

app.use(bodyParser.json());

app.use(
  OpenApiValidator.middleware({
    apiSpec: 'api.yaml',
    validateResponses: true,
  }),
);

app.post('/api/foo', function (req, res, next) {
  res.json({});
});

app.listen(8080)
openapi: '3.0.3'
info:
  title: Dummy
  version: '0.1.0'

paths:
  /api/foo:
    post:
      requestBody:
        content:
          'application/json; charset=utf-8':
            schema:
              type: object
      responses:
        200:
          description: OK
          content:
            'application/json; charset=utf-8':
              schema:
                type: object
POST http://localhost:8080/api/foo
Content-Type: application/json; charset=UTF-8

{"foo":  "test"}

Providing the content-type as 'application/json; charset=UTF-8' in the spec will also cause API calls with content-type: application/json to fail.

openapi: '3.0.3'
info:
  title: Dummy
  version: '0.1.0'

paths:
  /api/foo:
    post:
      requestBody:
        content:
          'application/json; charset=UTF-8':
            schema:
              type: object
      responses:
        200:
          description: OK
          content:
            'application/json; charset=UTF-8':
              schema:
                type: object
POST http://localhost:8080/api/foo
Content-Type: application/json

{"foo":  "test"}
@cdimascio
Copy link
Owner

cdimascio commented Nov 19, 2020

@tobiasvoelke thanks for the issue. definitely something we'll want to fix.

@cdimascio cdimascio added the enhancement New feature or request label Nov 28, 2020
@cdimascio cdimascio added bug Something isn't working and removed enhancement New feature or request labels Dec 28, 2020
@cdimascio
Copy link
Owner

fixed in v4.10.1

@jayakrishnar
Copy link

The issue back again in version 4.13.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants