Closed
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
Sending a Post request with a json payload (application/json mime type) the generator generates the code
void OAIUserApiRequest::loginUserRequest(){
qDebug() << "/v1/user/login";
connect(this, &OAIUserApiRequest::loginUser, handler.data(), &OAIUserApiHandler::loginUser);
OAIObject body;
::OpenAPI::fromStringValue(QString(socket->readAll()), body);
emit loginUser(body);
}
The function ::OpenAPI::fromStringValue(QString(socket->readAll()), body);
is only declared in file helpers-header.mustache
but not defined in file helpers-body.mustache
.
openapi-generator version
cli: 4.2.3
OpenAPI declaration file content or url
Command line used for generation
rmdir /s /q .\myapp-api-v1-server
java -jar openapi-generator-cli.jar generate -i spec.yaml -g cpp-qt5-qhttpengine-server -o myapp-api-v1-server
Steps to reproduce
Generate the source from the linked spec file.
Open the generated file 'OAIUserApiRequest.cpp' at line 53.
The code won't link because the function is not defined.
Suggest a fix
Add the following code to file helpers-body.mustache
#include <QJsonParseError>
bool
fromStringValue(const QString &inStr, {{prefix}}Object &value)
{
QJsonParseError err;
QJsonDocument::fromJson(inStr.toUtf8(),&err);
if ( err.error == QJsonParseError::NoError ){
value.fromJson(inStr);
return true;
}
return false;
}