swagger-api / swagger-api/swagger-parser

Parser does not validate GET request with request body

Open
#1,601 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
867
Forks
560
Avg merge
2d 21h
Merged PRs (30d)
7

Description

According to OpenAPI specification v3 GET, DELETE and HEAD are no longer allowed to have request body because it does not have defined semantics as per RFC 7231.

When validating a definition file with below path in which GET request has request body, using https://editor.swagger.io/, it gives a semantic error saying GET operations cannot have a requestBody. which is compatible with OpenAPI specification.

However when using the swagger-parser in my java project it does not return any parser error. I have tried the both 2.0.27 and 2.0.24 versions which are listed in the Maven central repository.

Sample OpenAPI definition

paths:
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              properties:
                name:
                  type: string
              type: object
        required: false
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pet"

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

Start with the sample OpenAPI definition containing a requestBody under a GET operation, and compare swagger-parser 2.0.24 and 2.0.27 with the semantic error reported by editor.swagger.io. Done means validation reports an error for request bodies on GET, DELETE, and HEAD operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.