openapi-to-graphql icon indicating copy to clipboard operation
openapi-to-graphql copied to clipboard

Don't set the content-type when there is no payload

Open lionelschiepers opened this issue 5 years ago • 5 comments

Hi,

I can't use the Mock Web Server https://github.com/stoplightio/prism because the GET operations set a content-type & content-length in the http headers. I think it's an error. a content-type & content-length must be set when there is a payload with operations like 'PUT' or 'POST'...

Web server like https://github.com/stoplightio/prism (mock of openapi) rejects the calls because it validate the request and a content-type has nothing to do with GET operations.

Exemple of a call made by openapi-to-graphql to my openapi web server:

GET http://127.0.0.1:4010/RESTMethod HTTP/1.1 content-type: application/json (bad) accept: application/json host: 127.0.0.1:4010 content-length: 0 (bad) Connection: close

lionelschiepers avatar Jun 12 '20 15:06 lionelschiepers

Hi, I'm not a specialist of node.js/javascript.

I tried to find the reason why payloadRequired was not correctly initialized during the unit test but didn't find the reason. That's why I changed the logic by checking the method instead of payloadRequired. Do you have any advise?

Lionel.

lionelschiepers avatar Jun 15 '20 11:06 lionelschiepers

@lionelschiepers I apologize for the late reply! A lot of things have been going on at my end.

We set the content-type here. This will be probably a super simple fix, we just need to check for the operation.method to see if it is a GET request or not. I'm not sure where we set the content-length, however. I assume that's set by the request.js library by default when we do not include a payload.

Let me give it a shot...

Alan-Cha avatar Jun 26 '20 22:06 Alan-Cha

Ah sorry, I got a bit ahead of myself. It seems that you have already made the changes.

This is the way I would have done as well. I do not think we should make things more complicated by checking if the payload is required.

Do these changes address your issue? Do you have any other problems with OtG?

Alan-Cha avatar Jun 26 '20 22:06 Alan-Cha

Hi,

Yes. This pullrequest solves my problem. If every body agree on the change I would be the most happiest man in the world if the pullrequest is merged :-)

Thanks, Lionel.

lionelschiepers avatar Jul 01 '20 12:07 lionelschiepers

@lionelschiepers I can try to get this checked in later today. I think we need a test case which I will look into.

Alan-Cha avatar Jul 01 '20 13:07 Alan-Cha