Marc Le Bihan fde8c772fb
[BUG] [C++][Pistache] cpp-pistache-server generating API include unde… (#18553)
* [BUG] [C++][Pistache] cpp-pistache-server generating API include undefined "Object.h" (#2769)

Should handle Object.h, AnyType.h correctly. Set.h also tested.

   - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues
   - object had an invalid syntax: ':' instead of '::' in types with namespace
   - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp>
   - nlohmann::json is excluded from model namespace

Tested with custom petstore played, with suggested openapi specs coming from issues #2769, #10266, #14234

   ```bash
   rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml  && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel
   ```

* - Adding to samples/server/petstore cpp-pistache-everything

* - .md and FILES missing
2024-05-04 21:59:49 +08:00

165 lines
3.3 KiB
C++

/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "ApiResponse.h"
#include "Helpers.h"
#include <sstream>
namespace org::openapitools::server::model
{
ApiResponse::ApiResponse()
{
m_Code = 0;
m_CodeIsSet = false;
m_Type = "";
m_TypeIsSet = false;
m_Message = "";
m_MessageIsSet = false;
}
void ApiResponse::validate() const
{
std::stringstream msg;
if (!validate(msg))
{
throw org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool ApiResponse::validate(std::stringstream& msg) const
{
return validate(msg, "");
}
bool ApiResponse::validate(std::stringstream& msg, const std::string& pathPrefix) const
{
bool success = true;
const std::string _pathPrefix = pathPrefix.empty() ? "ApiResponse" : pathPrefix;
return success;
}
bool ApiResponse::operator==(const ApiResponse& rhs) const
{
return
((!codeIsSet() && !rhs.codeIsSet()) || (codeIsSet() && rhs.codeIsSet() && getCode() == rhs.getCode())) &&
((!typeIsSet() && !rhs.typeIsSet()) || (typeIsSet() && rhs.typeIsSet() && getType() == rhs.getType())) &&
((!messageIsSet() && !rhs.messageIsSet()) || (messageIsSet() && rhs.messageIsSet() && getMessage() == rhs.getMessage()))
;
}
bool ApiResponse::operator!=(const ApiResponse& rhs) const
{
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const ApiResponse& o)
{
j = nlohmann::json::object();
if(o.codeIsSet())
j["code"] = o.m_Code;
if(o.typeIsSet())
j["type"] = o.m_Type;
if(o.messageIsSet())
j["message"] = o.m_Message;
}
void from_json(const nlohmann::json& j, ApiResponse& o)
{
if(j.find("code") != j.end())
{
j.at("code").get_to(o.m_Code);
o.m_CodeIsSet = true;
}
if(j.find("type") != j.end())
{
j.at("type").get_to(o.m_Type);
o.m_TypeIsSet = true;
}
if(j.find("message") != j.end())
{
j.at("message").get_to(o.m_Message);
o.m_MessageIsSet = true;
}
}
int32_t ApiResponse::getCode() const
{
return m_Code;
}
void ApiResponse::setCode(int32_t const value)
{
m_Code = value;
m_CodeIsSet = true;
}
bool ApiResponse::codeIsSet() const
{
return m_CodeIsSet;
}
void ApiResponse::unsetCode()
{
m_CodeIsSet = false;
}
std::string ApiResponse::getType() const
{
return m_Type;
}
void ApiResponse::setType(std::string const& value)
{
m_Type = value;
m_TypeIsSet = true;
}
bool ApiResponse::typeIsSet() const
{
return m_TypeIsSet;
}
void ApiResponse::unsetType()
{
m_TypeIsSet = false;
}
std::string ApiResponse::getMessage() const
{
return m_Message;
}
void ApiResponse::setMessage(std::string const& value)
{
m_Message = value;
m_MessageIsSet = true;
}
bool ApiResponse::messageIsSet() const
{
return m_MessageIsSet;
}
void ApiResponse::unsetMessage()
{
m_MessageIsSet = false;
}
} // namespace org::openapitools::server::model