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

Swagger API doesn't support requests with empty body #10

Open
asqui opened this issue May 1, 2018 · 2 comments
Open

Swagger API doesn't support requests with empty body #10

asqui opened this issue May 1, 2018 · 2 comments
Labels

Comments

@asqui
Copy link

asqui commented May 1, 2018

Not all requests require a body, however it looks like the Swagger API does not permit a request with an empty body.

For example, the close alert method does not have any mandatory JSON body fields, which implies you should be able to call it like this:

client.close_alert(alert.id)

Or more explicitly:

client.close_alert(alert.id, body=CloseAlertRequest())

However both of these fail with:

ApiException: (400)
Reason: Bad Request
HTTP response headers: HTTPHeaderDict({})
HTTP response body: {"message":"Body should be a JSON object","took":0.003,"requestId":"b5648d74-cee1-47ed-b8d7-1d458f31101a"}

I believe this section of the Swagger API code is at least partly responsible for this:

https://github.com/opsgenie/opsgenie-python-sdk/blob/master/opsgenie/swagger_client/rest.py#L152

                if body:
                    request_body = json.dumps(body)

My current workaround is to always specify source for these requests.

@asqui
Copy link
Author

asqui commented Jul 15, 2019

This is better in v2.0 Beta 3.

The explicit empty-payload form now works:

client.close_alert(alert_id, body=CloseAlertPayload())

However the simplest form which could reasonably be expected to work still fails:

client.close_alert(alert_id)  # Fails with: HTTP 400: Bad Request: Invalid JSON body

@asqui
Copy link
Author

asqui commented Nov 7, 2019

FYI: I just re-tested to make sure and this is still an issue on v2.0.1

@zfr zfr added the bug label Jan 24, 2020
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

2 participants