Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brianwaters3 opened this issue Oct 15, 2018 · 7 comments

Comments

@brianwaters3
Copy link

brianwaters3 commented Oct 15, 2018

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
@wing328
Copy link
Member

wing328 commented Oct 19, 2018

@brianwaters3 thanks for reporting the issue.

What does the correct code look like?

cc @ravinikam (2017/07) @stkrwork (2017/07) @fvarose (2017/11) @etherealjoy (2018/02) @MartinDelille (2018/03)

@MartinDelille
Copy link
Contributor

@brianwaters3 Publishing the code on a gist or a github repository would make the analysis easier.

@etherealjoy
Copy link
Contributor

etherealjoy commented Oct 21, 2018

@wing328
After debugging the topic, it seems indeed the mustache files are correct in this regard.

It seems to me there is a regression somewhere that Array members don't have the type updated properly anymore.
I checked the postProcessOperationsWithModels and this std::string does not have isString set to true.
so in the mustache {{^items.isString}} is passing and generating wrong code.
This is a new bug, I don't remember this issue before.

Update:
Ok the issues seems to be that there is a ref and the property type is not updated.

@CyrilleBenard
Copy link

Also interested in a fix
(post to follow this issue :) )

@CyrilleBenard
Copy link

Any news on this bug fix ?
Last week I checked the current status of PR #1296 but it did not fixed this current issue.

@etherealjoy
Copy link
Contributor

indeed, It solves at top level only. needs to be done still.

@etherealjoy
Copy link
Contributor

etherealjoy commented Apr 25, 2019

I tried this now on the 4.0.0 branch and it is solved.

Fixed with #2653

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants