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

when use prism proxy - GET/HEAD can't have body error #1408

Closed
ram-potla opened this issue Sep 11, 2020 · 4 comments
Closed

when use prism proxy - GET/HEAD can't have body error #1408

ram-potla opened this issue Sep 11, 2020 · 4 comments
Labels

Comments

@ram-potla
Copy link

Describe the bug

A clear and concise description of what the bug is.

To Reproduce

1 .feed openspec to prism
2. run prism mock severs
3. get response ok as per spec.

  1. when prism proxy spec.yaml localhost: --errors

I see below error.
{
“type”: “TypeError”,
“title”: “Request with GET/HEAD method cannot have body”,
“status”: 500,
“detail”: “”
}

Environment:

  • OS: mac mojave
  • node: v14.10.0
  • prism: 4.0.1

spec: openapi: 3.0.1
info:
title: dfdfsdfdf
license:
name: Apache 2.0
url: http://springdoc.org
version: 1.4.6
servers:

  • url: http://localhost:9000
    description: Generated server url
    tags:
  • name: name
    description: description
    paths:
    /api/v1/employees:
    get:
    tags:
    - employee
    summary: employees
    description: Fetches all engineers from db
    operationId: fetchAll
    parameters:
    - name: Content-Type
    in: header
    required: false
    schema:
    type: string
    default: application/json
    - name: Accept
    in: header
    required: true
    schema:
    type: string
    - name: X-type
    in: header
    required: true
    schema:
    type: string
    responses:
    "200":
    description: successful operation
    content:
    application/json:
    schema:
    type: array
    items:
    $ref: '#/components/schemas/Employee'
@ram-potla ram-potla added the bug label Sep 11, 2020
@philsturgeon
Copy link
Contributor

Mind if I ask why GET or HEAD has a body? :)

A payload within a GET request message has no defined semantics; sending a payload body on a GET request might cause some existing implementations to reject the request.

https://tools.ietf.org/html/rfc7231#section-4.3.1

@XVincentX
Copy link
Contributor

Yeah same here — this is something we really advice not to do.

I'm closing this since it's the behaviour we want; we can keep the conversation going on if you think it's beneficial.

@ram-potla
Copy link
Author

ram-potla commented Sep 11, 2020 via email

@XVincentX
Copy link
Contributor

@ram-potla For some reason I've missed the message.

From the error message, it looks that you're sending a body with a GET request; the example you provided is not well formatted and I struggle to reproduce the issue.

If you could set up a better scenario, I can take a look into.

Cheers!

johnboyes added a commit to johnboyes/openapi-generator that referenced this issue Jun 27, 2021
The Python generator no longer sets a default `Content-Type` of
`application/json` for `GET`, `HEAD` and `DELETE` requests.

Having the `Content-Type` set for these requests was causing issues with
other tools which insist that GET, HEAD and DELETE requests do not have
a Content-Type (as per the OpenAPI 3 specification).

An example of the problem that this commit fixes is when using
[Prism][1] as a [validation proxy][2].

[Prism rejects any GET request that has a Content-Type][3].

Here is [an example of the problem manifesting itself][4].

To validate the fix in this commit:

1. Start with any OpenAPI3 spec e.g. the Petstore example at
https://editor.swagger.io/
2. Generate Python client code for the spec
3. Look at the generated `rest.py` e.g. in the [standard sample in this
repo][5] and see that the `Content-Type` defaults to `application/json`
for all HTTP methods (including `GET`, `HEAD` and `DELETE`), rather than
there being no `Content-Type` for `GET`, `HEAD` and `DELETE`.

Fixes OpenAPITools#9831

[1]: https://github.com/stoplightio/prism
[2]: https://meta.stoplight.io/docs/prism/docs/guides/03-validation-proxy.md
[3]: stoplightio/prism#1408 (comment)
[4]: https://github.com/agilepathway/gauge-openapi-example/pull/28/checks?check_run_id=2888606052#step:13:18
[5]: https://github.com/OpenAPITools/openapi-generator/blob/969cea8ce10cb9d012c3936fb377d631c0d044c9/samples/openapi3/client/petstore/python/petstore_api/rest.py#L141
wing328 added a commit to OpenAPITools/openapi-generator that referenced this issue Jul 7, 2021
#9852)

* [BUG][PYTHON] Do not set Content-Type for GET, HEAD or DELETE requests

The Python generator no longer sets a default `Content-Type` of
`application/json` for `GET`, `HEAD` and `DELETE` requests.

Having the `Content-Type` set for these requests was causing issues with
other tools which insist that GET, HEAD and DELETE requests do not have
a Content-Type (as per the OpenAPI 3 specification).

An example of the problem that this commit fixes is when using
[Prism][1] as a [validation proxy][2].

[Prism rejects any GET request that has a Content-Type][3].

Here is [an example of the problem manifesting itself][4].

To validate the fix in this commit:

1. Start with any OpenAPI3 spec e.g. the Petstore example at
https://editor.swagger.io/
2. Generate Python client code for the spec
3. Look at the generated `rest.py` e.g. in the [standard sample in this
repo][5] and see that the `Content-Type` defaults to `application/json`
for all HTTP methods (including `GET`, `HEAD` and `DELETE`), rather than
there being no `Content-Type` for `GET`, `HEAD` and `DELETE`.

Fixes #9831

[1]: https://github.com/stoplightio/prism
[2]: https://meta.stoplight.io/docs/prism/docs/guides/03-validation-proxy.md
[3]: stoplightio/prism#1408 (comment)
[4]: https://github.com/agilepathway/gauge-openapi-example/pull/28/checks?check_run_id=2888606052#step:13:18
[5]: https://github.com/OpenAPITools/openapi-generator/blob/969cea8ce10cb9d012c3936fb377d631c0d044c9/samples/openapi3/client/petstore/python/petstore_api/rest.py#L141

* update samples

* Fix Python DELETE bug introduced in earlier commit

The earlier commit 9dfe1f6 introduced a bug for `DELETE` requests on the
standard Python generator.  This commit fixes that bug and also includes
the updated samples.

Co-authored-by: William Cheng <[email protected]>
zippolyte pushed a commit to DataDog/datadog-api-client-python that referenced this issue Jul 27, 2021
…s (#9852)

* [BUG][PYTHON] Do not set Content-Type for GET, HEAD or DELETE requests

The Python generator no longer sets a default `Content-Type` of
`application/json` for `GET`, `HEAD` and `DELETE` requests.

Having the `Content-Type` set for these requests was causing issues with
other tools which insist that GET, HEAD and DELETE requests do not have
a Content-Type (as per the OpenAPI 3 specification).

An example of the problem that this commit fixes is when using
[Prism][1] as a [validation proxy][2].

[Prism rejects any GET request that has a Content-Type][3].

Here is [an example of the problem manifesting itself][4].

To validate the fix in this commit:

1. Start with any OpenAPI3 spec e.g. the Petstore example at
https://editor.swagger.io/
2. Generate Python client code for the spec
3. Look at the generated `rest.py` e.g. in the [standard sample in this
repo][5] and see that the `Content-Type` defaults to `application/json`
for all HTTP methods (including `GET`, `HEAD` and `DELETE`), rather than
there being no `Content-Type` for `GET`, `HEAD` and `DELETE`.

Fixes #9831

[1]: https://github.com/stoplightio/prism
[2]: https://meta.stoplight.io/docs/prism/docs/guides/03-validation-proxy.md
[3]: stoplightio/prism#1408 (comment)
[4]: https://github.com/agilepathway/gauge-openapi-example/pull/28/checks?check_run_id=2888606052#step:13:18
[5]: https://github.com/OpenAPITools/openapi-generator/blob/969cea8ce10cb9d012c3936fb377d631c0d044c9/samples/openapi3/client/petstore/python/petstore_api/rest.py#L141

* update samples

* Fix Python DELETE bug introduced in earlier commit

The earlier commit 9dfe1f6 introduced a bug for `DELETE` requests on the
standard Python generator.  This commit fixes that bug and also includes
the updated samples.

Co-authored-by: William Cheng <[email protected]>
jirikuncar pushed a commit to DataDog/datadog-api-client-python that referenced this issue Sep 8, 2021
…s (#9852)

* [BUG][PYTHON] Do not set Content-Type for GET, HEAD or DELETE requests

The Python generator no longer sets a default `Content-Type` of
`application/json` for `GET`, `HEAD` and `DELETE` requests.

Having the `Content-Type` set for these requests was causing issues with
other tools which insist that GET, HEAD and DELETE requests do not have
a Content-Type (as per the OpenAPI 3 specification).

An example of the problem that this commit fixes is when using
[Prism][1] as a [validation proxy][2].

[Prism rejects any GET request that has a Content-Type][3].

Here is [an example of the problem manifesting itself][4].

To validate the fix in this commit:

1. Start with any OpenAPI3 spec e.g. the Petstore example at
https://editor.swagger.io/
2. Generate Python client code for the spec
3. Look at the generated `rest.py` e.g. in the [standard sample in this
repo][5] and see that the `Content-Type` defaults to `application/json`
for all HTTP methods (including `GET`, `HEAD` and `DELETE`), rather than
there being no `Content-Type` for `GET`, `HEAD` and `DELETE`.

Fixes #9831

[1]: https://github.com/stoplightio/prism
[2]: https://meta.stoplight.io/docs/prism/docs/guides/03-validation-proxy.md
[3]: stoplightio/prism#1408 (comment)
[4]: https://github.com/agilepathway/gauge-openapi-example/pull/28/checks?check_run_id=2888606052#step:13:18
[5]: https://github.com/OpenAPITools/openapi-generator/blob/969cea8ce10cb9d012c3936fb377d631c0d044c9/samples/openapi3/client/petstore/python/petstore_api/rest.py#L141

* update samples

* Fix Python DELETE bug introduced in earlier commit

The earlier commit 9dfe1f6 introduced a bug for `DELETE` requests on the
standard Python generator.  This commit fixes that bug and also includes
the updated samples.

Co-authored-by: William Cheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants