[BUG][cpp-restsdk] Segmentation fault and error compilation when trying to receive binary data
Created by: tzickel
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
When receiving an binary string as a result, the C++ resksdk generator does not allocate the HttpContent it returns to the user, causing a Segmentation fault.
autogen/api/DefaultApi.cpp
.then([=](std::vector<unsigned char> localVarResponse)
{
std::shared_ptr<HttpContent> localVarResult; // <-- Here is the bug, there is no allocation for HttpContent.
std::shared_ptr<std::stringstream> stream = std::make_shared<std::stringstream>(std::string(localVarResponse.begin(), localVarResponse.end()));
localVarResult->setData(stream);
return localVarResult;
});
Another related bug, is that in the api/model dirs, if the code returns an HttpContent, it adds in autogen/api/DefaultApi.h:
#include "HttpContent.h"
Which is wrong, and should point to:
#include "../HttpContent.h"
instead.
openapi-generator version
The docker image openapitools/openapi-generator-cli:latest as of 5/11/2020 The docker image openapitools/openapi-generator-cli:v5.0.0-beta2
OpenAPI declaration file content or url
swagger: "2.0"
info:
title: "test"
host: "localhost:8080"
paths:
/GetBackBinaryData:
get:
operationId: "GetBackBinaryData"
produces:
- "application/octet-stream"
responses:
"200":
description: "successful operation"
schema:
type: string
format: binary
Generation Details
generate -i /local/bug.yaml -g cpp-restsdk -o /local/autogen
Steps to reproduce
Generate, try to call the:
api.getBackBinaryData().wait()
Related issues/PRs
None
Suggest a fix
A fix would be to construct the HttpContent being used.
But a better fix, since this might be large data involved is to remove all this code, and simply return the std::vector from the previous stage (it's not like any of HttpContent other properties are used in this code base anyhow). But if it's used maybe in OpenAPI 3, then maybe allow for it to maybe hold the original std::vector anyhow ?