Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #1801
Closed
Open
Issue created Jan 03, 2019 by Administrator@rootContributor

[C++][Pistache Server] const-conflict in generated code

Created by: jochengern

Hello, when I generate code for a pistache server, the code generator for the pistache server generates code that does not compile due to a conflict in the usage of a const-declaration. The following is the snippet out of my yaml-file that seems to be the cause for the error: '''yaml ... components: ... schemas: ... ResultArrayValue: type: object properties: value: type: string description: The string representation of the value isValid: type: boolean description: The validity information for the whole value fieldIsValid: description: The validity information for each field of the array type: array items: type: boolean required: - value - isValid - fieldIsValid ''' From this, the code generator generates a file named ResultArrayValue.cpp that contains the following method: nlohmann::json ResultArrayValue::toJson() const { nlohmann::json val = nlohmann::json::object();

val["value"] = ModelBase::toJson(m_Value);
val["isValid"] = m_IsValid;
{
    nlohmann::json jsonArray;
    for( auto& item : m_FieldIsValid )
    {
        jsonArray.push_back(ModelBase::toJson(item));
    }
    val["fieldIsValid"] = jsonArray;
    
}


return val;

}

When compiling this, the compiler complains about a non-const reference "item" within the for-loop that references the member "m_FieldIsValid" that is const due to the method being declared as const.

openapi-generator version

3.3.4

Command line used for generation

java -ea -Xms512M -Xmx1024M -server -jar openapi-generator-cli-3.3.4.jar generate -i oaa_objectaccessagent.yaml -g cpp-pistache-server -o ./server

Steps to reproduce

/opt/jdsu/ont6xx/x-tools-2_6/bin/x86_64-embedded-linux-gnu-g++ -DCPU=core2 -DVX_GCC_ENV=LINUX -march=core2 -fpic -std=gnu++14 -Wall -W -Wno-comment -Wno-trigraphs -Wno-unused -Wno-reorder -Wno-ctor-dtor-privacy -D_DEBUG -g -O0 -ffloat-store -DORB_OMNI=400 -DOMNI_NAME -D__x86__ -DLINUX -DDEBUG_BUFFER=1 -DMMIOMAP=1 -DPCIE_BUS=1 -DPCIE_DMA=1 -Wno-unused-parameter -I../../../../../include -I./ -c ResultArrayValue.cpp

ResultArrayValue.cpp: In member function 'virtual nlohmann::json org::openapitools::server::model::ResultArrayValue::toJson() const': ResultArrayValue.cpp:45:27: error: invalid initialization of non-const reference of type 'bool&' from an rvalue of type 'std::_Bit_const_iterator::const_reference {aka bool}' for( auto& item : m_FieldIsValid )

Suggest a fix/enhancement

When I manually add the const-declaration to the for-loop so that it looks like for( const auto& item : m_FieldIsValid ) the code compiles. So I suggest to make the code generator either to add this const-declaration or not to declare the method itself as const.

Assignee
Assign to
Time tracking