[BUG] [cpp-ue4] Content body being set for GET request causing issues
Created by: OktarianTB
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
We have encountered an issue in Unreal Engine (using 4.27) where an API call for a GET request to our server via a generated OpenAPI UE4 client never actually reaches the server. After a lot of debugging, we were able to pin it down to the content body being set for the GET request. This is an Unreal bug, but exacerbated by the OpenAPI UE4 generator because in the generated files, a content body is automatically set for GET requests, even if none is specified.
While this might have something to do with our server configuration, this is not an isolated case (refer to this post) and by definition GET requests should not have content bodies. In OpenAPI 3 GET requests are no longer allowed to have request body because it does not have defined semantics.
As a result, we commented out the following line HttpRequest->SetContentAsString(JsonBody);
in the SetupHttpRequest
method, which solved the problem.
void OpenAPIPayloadLocalApi::GetPayloadV0Request::SetupHttpRequest(const FHttpRequestRef& HttpRequest) const
{
static const TArray<FString> Consumes = { };
//static const TArray<FString> Produces = { TEXT("application/json") };
HttpRequest->SetVerb(TEXT("GET"));
// Default to Json Body request
if (Consumes.Num() == 0 || Consumes.Contains(TEXT("application/json")))
{
// Form parameters
FString JsonBody;
JsonWriter Writer = TJsonWriterFactory<>::Create(&JsonBody);
Writer->WriteObjectStart();
Writer->WriteObjectEnd();
Writer->Close();
HttpRequest->SetHeader(TEXT("Content-Type"), TEXT("application/json; charset=utf-8"));
//HttpRequest->SetContentAsString(JsonBody);
}
else if (Consumes.Contains(TEXT("multipart/form-data")))
{
}
else if (Consumes.Contains(TEXT("application/x-www-form-urlencoded")))
{
}
else
{
UE_LOG(LogIMSZeuzAPI, Error, TEXT("Request ContentType not supported (%s)"), *FString::Join(Consumes, TEXT(",")));
}
}
openapi-generator version
openapi: 3.0.1 openapi-generator-cli: 5.4.0 (npm package version 2.5.1)
OpenAPI declaration file content or url
https://docs.ims.improbable.io/openapi/ims-zeuz/payload-local-api
Generation Details
{
"$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "5.4.0"
}
}
rd /s /q ..\IMSZeuzAPI
npx @openapitools/openapi-generator-cli generate -i ./payload.api.yaml -g cpp-ue4 -o .\IMSZeuzAPI -c .\ims_zeuz_payload_local_api_config.json --package-name IMSZeuzAPI
Steps to reproduce
- Generate files for declaration file
- Try to make GET request
- Fails: repeated sleep logs
[2022.07.01-10.14.59:254][823]LogHttp: Display: Sleeping 0.500s to wait for 1 outstanding Http requests.
[2022.07.01-10.14.59:754][823]LogHttp: Display: Sleeping 0.500s to wait for 1 outstanding Http requests.
... forever
Related issues/PRs
None that I could find.
Suggest a fix
Currently GET requests with no body specified by developer will default to {}
which is enough to cause the issue. A fix would be to only set a content body only if there is one specified for GET requests.