Skip to content

[BUG] C++ Server (Qt5) does not implement "fromStringValue(const QString &, OAIObject &)" #5252

Closed
@redturtlepower

Description

@redturtlepower

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

spec.yaml

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;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions