Skip to content

[cpp-pistache-server] newItem.fromJson() always called even when type is std::string #1251

@brianwaters3

Description

@brianwaters3
Description

The fromJson method defined via model-source.mustache declares newItem to be of type items.datatype. When processing an array of stings this results in generating declaring newItem as std::string and subsequently attempting to execute the fromJson() method which is undefined. In this case, here is a snippet of the generated code for UePerLocationReport::fromJson(nlohmann:json& val).

...
void UePerLocationReport::fromJson(nlohmann::json& val)
{
    setUeCount(val.at("ueCount"));
    {
        m_ExternalIds.clear();
        nlohmann::json jsonArray;
        if(val.find("externalIds") != val.end())
        {
        for( auto& item : val["externalIds"] )
        {

            if(item.is_null())
            {
                m_ExternalIds.push_back( std::string() );
            }
            else
            {
                std::string newItem;
                newItem.fromJson(item);
                m_ExternalIds.push_back( newItem );
            }

        }
        }
    }
...
openapi-generator version

3.3.0

OpenAPI declaration file content or url

Archive .zip contains the yaml and support files to reproduce the issue.

Archive.zip

Command line used for generation

java -jar ~/code/git/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i updated/TS29122_MonitoringEvent.yaml -g cpp-pistache-server --config config -o ./src/MonitoringEvent/

Modify the openapi-generator-cli.jar path to match your system.

Steps to reproduce
  1. Create a blank working directory
  2. Unzip Archive.zip to the newly created directory.
  3. Generate the source using the provided command making path adjustments for your system.
  4. Install pistache.io.
  5. Compile with the following command:

g++ -g -pthread -std=c++11 -I ./include -I ./src/MonitoringEvent/api -I ./src/MonitoringEvent/impl -I t8/src/MonitoringEvent/model -c -o ./UePerLocationReport.o ./src/MonitoringEvent/model/UePerLocationReport.cpp

Related issues/PRs
Suggest a fix/enhancement

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions