[C++][Pistache-server] Wrong "toJson" and "fromJson" method generation - compilation failed
Created by: vbs96
Description
The C++ generated code does not compile because of the following errors:
- there is no matching function for ModelBase::toJson taking as argument std::map<std::string, std::vector>
- the generated code is calling "fromJson" method as it is a member of std::map type
- the generated code is calling a set method that is not generated
These error occur in model/Detections.cpp file.
Detection.h:
#include "ModelBase.h"
#include "BoundingRectangle.h"
#include <string>
#include "Point2D.h"
#include <map>
#include <vector>
namespace org {
namespace openapitools {
namespace server {
namespace model {
class Detection
: public ModelBase
{
public:
Detection();
virtual ~Detection();
nlohmann::json toJson() const override;
void fromJson(nlohmann::json& json) override;
std::map<std::string, std::vector<Point2D>>& getKeyPoints();
//setKeyPoints is missing
bool keyPointsIsSet() const;
void unsetKeyPoints();
protected:
std::map<std::string, std::vector<Point2D>> m_KeyPoints;
bool m_KeyPointsIsSet;
};
}
}
}
}
#endif /* Detection_H_ */
Detection.cpp:
nlohmann::json Detection::toJson() const
{
//
//
if(m_KeyPointsIsSet)
{
//this call
val["keyPoints"] = ModelBase::toJson(m_KeyPoints);
}
//
//
return val;
}
void Detection::fromJson(nlohmann::json& val)
{
//
//
if(val.find("keyPoints") != val.end())
{
if(!val["keyPoints"].is_null())
{
std::map<std::string, std::vector<Point2D>> newItem;
//and these 2 lines below
newItem.fromJson(val["keyPoints"]);
setKeyPoints( newItem );
}
}
}
openapi-generator version
3.2.0 (I cloned the latest master branch 2 days ago)
OpenAPI declaration file content or url
Command line used for generation
Inside cloned repository, after mvn clean package: java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate / -i deep-viss.json / -g cpp-pistache-server / -o ../openapi-pistache-server
Steps to reproduce
Note: Assuming Pistache is installed
- Go to output folder
- copy json.hpp (from https://github.com/nlohmann/json) to model folder
- mkdir build
- cd build
- cmake ..
- make