From c9cbb40073d6ad2b839022e5647878b002b7284f Mon Sep 17 00:00:00 2001 From: Lionel Schiepers Date: Fri, 12 Jun 2020 17:45:53 +0200 Subject: [PATCH 1/2] Don't set the content-type when there is no payload The HTTP Get operation actually set a content-type of 'application/json' when there is no payload. The request adds a content-length of 0 because there is no payload. Web server like https://github.com/stoplightio/prism (mock of openapi) reject the calls because the content-type has nothing to do with GET operations. Exemple: GET http://127.0.0.1:4010/RESTMethod HTTP/1.1 content-type: application/json accept: application/json host: 127.0.0.1:4010 content-length: 0 Connection: close Signed-off-by: Lionel Schiepers --- packages/openapi-to-graphql/src/resolver_builder.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/openapi-to-graphql/src/resolver_builder.ts b/packages/openapi-to-graphql/src/resolver_builder.ts index 49a18f9d..56c14085 100644 --- a/packages/openapi-to-graphql/src/resolver_builder.ts +++ b/packages/openapi-to-graphql/src/resolver_builder.ts @@ -446,10 +446,14 @@ export function getResolver({ * * NOTE: This may cause the user to encounter unexpected changes */ - headers['content-type'] = - typeof operation.payloadContentType !== 'undefined' - ? operation.payloadContentType - : 'application/json' + if (operation.payloadRequired) + { + headers['content-type'] = + typeof operation.payloadContentType !== 'undefined' + ? operation.payloadContentType + : 'application/json' + } + headers['accept'] = typeof operation.responseContentType !== 'undefined' ? operation.responseContentType From 11952c8815b4135848f8cf4d9ce2dba0f0c71fcc Mon Sep 17 00:00:00 2001 From: Lionel Schiepers Date: Mon, 15 Jun 2020 13:28:57 +0200 Subject: [PATCH 2/2] fix: check if there is a payload by checking the http method fix: check if there is a payload by checking the http method instead of payloadRequired because that field is not always correctly initialized during unit test Signed-off-by: Lionel Schiepers --- packages/openapi-to-graphql/src/resolver_builder.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/openapi-to-graphql/src/resolver_builder.ts b/packages/openapi-to-graphql/src/resolver_builder.ts index 56c14085..05685057 100644 --- a/packages/openapi-to-graphql/src/resolver_builder.ts +++ b/packages/openapi-to-graphql/src/resolver_builder.ts @@ -446,8 +446,12 @@ export function getResolver({ * * NOTE: This may cause the user to encounter unexpected changes */ - if (operation.payloadRequired) + if (operation.method !== 'get') { + /** + * the check is done on the 'get' operation to determine if there is a payload because + * operation.payloadRequired is not always correctly initialized (at least during the unit test) + */ headers['content-type'] = typeof operation.payloadContentType !== 'undefined' ? operation.payloadContentType