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.

Only last schema is used for endpoints with multiple mimetypes

See original GitHub issue

Only last schema is being used for endpoints with multiple mimetypes: https://github.com/seriousme/fastify-openapi-glue/blob/a0269cfd605796baaf0d510b94e281b610346e75/lib/parser.v3.js#L71-L80

which contradicts the spec stating that Schemas can vary by media type.

Therefore, following sample spec will not consume text/plain requests by throwing

{
    "statusCode": 400,
    "error": "Bad Request",
    "message": "body should be object"
}
Sample spec:
openapi: 3.0.0
info:
  version: 1.0.0
  title: Test
paths:
  "/test":
    post:
      summary: Multiple mimetypes payload
      operationId: test
      requestBody:
        content:
          text/plain:
            schema:
              type: string
          application/json:
            schema:
              $ref: "#/components/schemas/TestMessage"
      responses:
        "200":
          description: Message received
components:
  schemas:
    TestMessage:
      type: object
      nullable: true
      properties:
        id:
          type: number
          description: Id

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
seriousmecommented, Feb 10, 2021

I have just added a note to the README to clarify the topic.

Thanks for the input.

Kind regards, Hans

0reactions
artu-olecommented, Feb 10, 2021

Thank you for the quick turnaround and support on the matter! I consider this case closed at the time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Investigate multiple schema case (different mime types) in ...
This feels wrong because when multiple Mime types are defined (like application/json or application/xml ) different Schemas can be returned.
Read more >
MIME Types - Swagger
You can use the consumes and produces keywords to specify the MIME types understood by your API. The value of consumes and produces...
Read more >
How many custom MIME types in a RESTful web API?
For example, GET "/customers/5" should only produce data that was serialized from your Customer entity.
Read more >
What's the Difference Between OpenAPI Types 2.0, 3.0, and ...
A deep look into different OpenAPI versions starting from 2.0 to the latest release candidate.
Read more >
MIME types (IANA media types) - HTTP - MDN Web Docs
MIME types are case-insensitive but are traditionally written in lowercase. The parameter values can be case-sensitive.
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