Skip to content

Content-Type header added despite no request body defined in POST/PUT/PATCH endpoints #2734

@nikrooz

Description

@nikrooz

Context

This bug affects POST/PUT/PATCH endpoints that lack a request body. When a request is made, a Content-Type: application/json header is added, which can cause an error in the API as it attempts to decode a nonexistent request body.

Current Behavior

The "Try-it" feature and example snippets add a Content-Type: application/json header to the request, even when no request body is specified in the spec for POST/PUT/PATCH endpoints.

Expected Behavior

If no request body is defined, the Content-Type header should not be included.

Possible Workaround/Solution

Steps to Reproduce

  1. Use this spec openapi.json in https://elements-demo.stoplight.io/
  2. You'll see the example curl snippet include Content-Type
Screenshot 2024-11-15 at 10 30 13 3. And the request from Try it includes `Content-Type` header

Environment

  • Version used: 8.4.7
  • Environment name and version (e.g. Chrome 39, node.js 5.4):
  • Operating System and version (desktop or mobile):
  • Link to your environment/workspace/project:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions