swagger-api / swagger-api/swagger-ui

Swagger UI incorrectly identifies EDN request bodies as JSON

Open
#8,980 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Q&A (please complete the following information)
Content & configuration

Example Swagger/OpenAPI definition:

 "paths": {
    "/math/plus": {
      "post": {
        ...
        "consumes": [
          "application/json",
          "application/transit+msgpack",
          "application/transit+json",
          "application/edn"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "body",
            "description": "",
            "required": true,
            "schema": {
              "type": "object",
              "properties": {
                "x": {
                  "type": "integer",
                  "format": "int64"
                },
                "y": {
                  "type": "integer",
                  "format": "int64"
                }
              },
              "required": [
                "x",
                "y"
              ],
              "additionalProperties": false
            }
          }
        ]
      }
    }
  }
Describe the bug you're encountering

When user selects application/edn as the Content-Type of a request body, Swagger UI incorrectly treats it as JSON.

To reproduce...

Steps to reproduce the behavior:

  1. Download this example project https://github.com/metosin/reitit/tree/master/examples/pedestal-swagger
  2. Run lein repl inside this folder
  3. Execute (start)
  4. Visit http://localhost:3000/
  5. Expand the POST /math/plus endpoint
  6. Set "parameter content type" to application/edn
  7. Input a body like {:x 0 :y 1}
  8. Press "Execute"
Expected behavior

Swagger UI simply sends the POST request. The backend can handle improperly formatted EDN data; Swagger does NOT need to validate anything.

Screenshots

Screenshot demonstrating problem

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using the metosin/reitit pedestal-swagger example: run lein repl, execute (start), and open the /math/plus endpoint in Swagger UI. Select application/edn and submit {:x 0 :y 1}; done means the request is sent without being treated as JSON or validated as JSON.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.