[JAVA] fix toUrlQueryString for BigDecimal (#15764)

* add MyImportTest.java

* fix original issue

* fix same issue for native library

* remove MyImportTest

* add test configs

* generate samples (again?)

* generate samples again

* generate samples again, undo pom.xml mistake [amended to retrigger circliCi]
This commit is contained in:
martin-mfg
2023-06-08 03:34:06 +02:00
committed by GitHub
parent fbe768bb9c
commit b7f2b723aa
176 changed files with 7934 additions and 8 deletions

View File

@@ -55,6 +55,8 @@ model/EnumClass.cpp
model/EnumClass.h
model/Enum_Test.cpp
model/Enum_Test.h
model/FakeBigDecimalMap_200_response.cpp
model/FakeBigDecimalMap_200_response.h
model/File.cpp
model/File.h
model/FileSchemaTestClass.cpp

View File

@@ -114,6 +114,117 @@ std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
}
namespace FakeApiResources {
FakeBigDecimalMapResource::FakeBigDecimalMapResource(const std::string& context /* = "/v2" */)
{
this->set_path(context + "/fake/BigDecimalMap");
this->set_method_handler("GET",
std::bind(&FakeBigDecimalMapResource::handler_GET_internal, this,
std::placeholders::_1));
}
std::pair<int, std::string> FakeBigDecimalMapResource::handleFakeApiException(const FakeApiException& e)
{
return std::make_pair<int, std::string>(e.getStatus(), e.what());
}
std::pair<int, std::string> FakeBigDecimalMapResource::handleStdException(const std::exception& e)
{
return std::make_pair<int, std::string>(500, e.what());
}
std::pair<int, std::string> FakeBigDecimalMapResource::handleUnspecifiedException()
{
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
}
void FakeBigDecimalMapResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
{
session->set_header(header, "");
}
void FakeBigDecimalMapResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, std::multimap<std::string, std::string>& responseHeaders)
{
responseHeaders.insert(std::make_pair("Connection", "close"));
session->close(status, result, responseHeaders);
}
void FakeBigDecimalMapResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
{
session->close(status, result, { {"Connection", "close"} });
}
void FakeBigDecimalMapResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
{
const auto request = session->get_request();
int status_code = 500;
FakeBigDecimalMap_200_response resultObject = FakeBigDecimalMap_200_response{};
std::string result = "";
try {
std::tie(status_code, resultObject) =
handler_GET();
}
catch(const FakeApiException& e) {
std::tie(status_code, result) = handleFakeApiException(e);
}
catch(const std::exception& e) {
std::tie(status_code, result) = handleStdException(e);
}
catch(...) {
std::tie(status_code, result) = handleUnspecifiedException();
}
std::multimap< std::string, std::string > responseHeaders {};
static const std::vector<std::string> contentTypes{
"*/*",
};
static const std::string acceptTypes{
};
if (status_code == 200) {
responseHeaders.insert(std::make_pair("Content-Type", selectPreferredContentType(contentTypes)));
if (!acceptTypes.empty()) {
responseHeaders.insert(std::make_pair("Accept", acceptTypes));
}
result = resultObject.toJsonString();
returnResponse(session, 200, result.empty() ? "{}" : result, responseHeaders);
return;
}
defaultSessionClose(session, status_code, result);
}
std::pair<int, FakeBigDecimalMap_200_response> FakeBigDecimalMapResource::handler_GET(
)
{
return handler_GET_func();
}
std::string FakeBigDecimalMapResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
const auto request = session->get_request();
int content_length = request->get_header("Content-Length", 0);
std::string bodyContent;
session->fetch(content_length,
[&bodyContent](const std::shared_ptr<restbed::Session> session,
const restbed::Bytes &body) {
bodyContent = restbed::String::format(
"%.*s\n", (int)body.size(), body.data());
});
return bodyContent;
}
std::string FakeBigDecimalMapResource::extractFormParamsFromBody(const std::string& paramName, const std::string& body) {
const auto uri = restbed::Uri("urlencoded?" + body, true);
const auto params = uri.get_query_parameters();
const auto result = params.find(paramName);
if (result != params.cend()) {
return result->second;
}
return "";
}
FakeHealthResource::FakeHealthResource(const std::string& context /* = "/v2" */)
{
this->set_path(context + "/fake/health");
@@ -1945,6 +2056,12 @@ FakeApi::FakeApi(std::shared_ptr<restbed::Service> const& restbedService)
FakeApi::~FakeApi() {}
std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> FakeApi::getFakeBigDecimalMapResource() {
if (!m_spFakeBigDecimalMapResource) {
setResource(std::make_shared<FakeApiResources::FakeBigDecimalMapResource>());
}
return m_spFakeBigDecimalMapResource;
}
std::shared_ptr<FakeApiResources::FakeHealthResource> FakeApi::getFakeHealthResource() {
if (!m_spFakeHealthResource) {
setResource(std::make_shared<FakeApiResources::FakeHealthResource>());
@@ -2029,6 +2146,10 @@ std::shared_ptr<FakeApiResources::FakeTest_query_parametersResource> FakeApi::ge
}
return m_spFakeTest_query_parametersResource;
}
void FakeApi::setResource(std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> resource) {
m_spFakeBigDecimalMapResource = resource;
m_service->publish(m_spFakeBigDecimalMapResource);
}
void FakeApi::setResource(std::shared_ptr<FakeApiResources::FakeHealthResource> resource) {
m_spFakeHealthResource = resource;
m_service->publish(m_spFakeHealthResource);
@@ -2085,6 +2206,10 @@ void FakeApi::setResource(std::shared_ptr<FakeApiResources::FakeTest_query_param
m_spFakeTest_query_parametersResource = resource;
m_service->publish(m_spFakeTest_query_parametersResource);
}
void FakeApi::setFakeApiFakeBigDecimalMapResource(std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> spFakeBigDecimalMapResource) {
m_spFakeBigDecimalMapResource = spFakeBigDecimalMapResource;
m_service->publish(m_spFakeBigDecimalMapResource);
}
void FakeApi::setFakeApiFakeHealthResource(std::shared_ptr<FakeApiResources::FakeHealthResource> spFakeHealthResource) {
m_spFakeHealthResource = spFakeHealthResource;
m_service->publish(m_spFakeHealthResource);
@@ -2144,6 +2269,9 @@ void FakeApi::setFakeApiFakeTest_query_parametersResource(std::shared_ptr<FakeAp
void FakeApi::publishDefaultResources() {
if (!m_spFakeBigDecimalMapResource) {
setResource(std::make_shared<FakeApiResources::FakeBigDecimalMapResource>());
}
if (!m_spFakeHealthResource) {
setResource(std::make_shared<FakeApiResources::FakeHealthResource>());
}

View File

@@ -33,6 +33,7 @@
#include "Client.h"
#include "EnumClass.h"
#include "FakeBigDecimalMap_200_response.h"
#include "FileSchemaTestClass.h"
#include "HealthCheckResult.h"
#include "OuterComposite.h"
@@ -66,6 +67,68 @@ private:
};
namespace FakeApiResources {
/// <summary>
///
/// </summary>
/// <remarks>
/// for Java apache and Java native, test toUrlQueryString for maps with BegDecimal keys
/// </remarks>
class FakeBigDecimalMapResource: public restbed::Resource
{
public:
FakeBigDecimalMapResource(const std::string& context = "/v2");
virtual ~FakeBigDecimalMapResource() = default;
FakeBigDecimalMapResource(
const FakeBigDecimalMapResource& other) = default; // copy constructor
FakeBigDecimalMapResource(FakeBigDecimalMapResource&& other) noexcept = default; // move constructor
FakeBigDecimalMapResource& operator=(const FakeBigDecimalMapResource& other) = default; // copy assignment
FakeBigDecimalMapResource& operator=(FakeBigDecimalMapResource&& other) noexcept = default; // move assignment
/////////////////////////////////////////////////////
// Set these to implement the server functionality //
/////////////////////////////////////////////////////
std::function<std::pair<int, FakeBigDecimalMap_200_response>(
)> handler_GET_func =
[]() -> std::pair<int, FakeBigDecimalMap_200_response>
{ throw FakeApiException(501, "Not implemented"); };
protected:
//////////////////////////////////////////////////////////
// As an alternative to setting the `std::function`s //
// override these to implement the server functionality //
//////////////////////////////////////////////////////////
virtual std::pair<int, FakeBigDecimalMap_200_response> handler_GET(
);
protected:
//////////////////////////////////////
// Override these for customization //
//////////////////////////////////////
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
virtual std::string extractFormParamsFromBody(const std::string& paramName, const std::string& body);
virtual std::pair<int, std::string> handleFakeApiException(const FakeApiException& e);
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
virtual std::pair<int, std::string> handleUnspecifiedException();
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
const std::string& header);
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
const int status, const std::string& result, std::multimap<std::string, std::string>& contentType);
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
const int status, const std::string& result);
private:
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
};
/// <summary>
/// Health check endpoint
/// </summary>
@@ -960,6 +1023,7 @@ private:
} /* namespace FakeApiResources */
using FakeApiFakeBigDecimalMapResource [[deprecated]] = FakeApiResources::FakeBigDecimalMapResource;
using FakeApiFakeHealthResource [[deprecated]] = FakeApiResources::FakeHealthResource;
using FakeApiFakeHttp_signature_testResource [[deprecated]] = FakeApiResources::FakeHttp_signature_testResource;
using FakeApiFakeOuterBooleanResource [[deprecated]] = FakeApiResources::FakeOuterBooleanResource;
@@ -984,6 +1048,7 @@ public:
explicit FakeApi(std::shared_ptr<restbed::Service> const& restbedService);
virtual ~FakeApi();
std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> getFakeBigDecimalMapResource();
std::shared_ptr<FakeApiResources::FakeHealthResource> getFakeHealthResource();
std::shared_ptr<FakeApiResources::FakeHttp_signature_testResource> getFakeHttp_signature_testResource();
std::shared_ptr<FakeApiResources::FakeOuterBooleanResource> getFakeOuterBooleanResource();
@@ -999,6 +1064,7 @@ public:
std::shared_ptr<FakeApiResources::FakeJsonFormDataResource> getFakeJsonFormDataResource();
std::shared_ptr<FakeApiResources::FakeTest_query_parametersResource> getFakeTest_query_parametersResource();
void setResource(std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> resource);
void setResource(std::shared_ptr<FakeApiResources::FakeHealthResource> resource);
void setResource(std::shared_ptr<FakeApiResources::FakeHttp_signature_testResource> resource);
void setResource(std::shared_ptr<FakeApiResources::FakeOuterBooleanResource> resource);
@@ -1014,6 +1080,8 @@ public:
void setResource(std::shared_ptr<FakeApiResources::FakeJsonFormDataResource> resource);
void setResource(std::shared_ptr<FakeApiResources::FakeTest_query_parametersResource> resource);
[[deprecated("use setResource()")]]
virtual void setFakeApiFakeBigDecimalMapResource(std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> spFakeApiFakeBigDecimalMapResource);
[[deprecated("use setResource()")]]
virtual void setFakeApiFakeHealthResource(std::shared_ptr<FakeApiResources::FakeHealthResource> spFakeApiFakeHealthResource);
[[deprecated("use setResource()")]]
virtual void setFakeApiFakeHttp_signature_testResource(std::shared_ptr<FakeApiResources::FakeHttp_signature_testResource> spFakeApiFakeHttp_signature_testResource);
@@ -1047,6 +1115,7 @@ public:
virtual std::shared_ptr<restbed::Service> service();
protected:
std::shared_ptr<FakeApiResources::FakeBigDecimalMapResource> m_spFakeBigDecimalMapResource;
std::shared_ptr<FakeApiResources::FakeHealthResource> m_spFakeHealthResource;
std::shared_ptr<FakeApiResources::FakeHttp_signature_testResource> m_spFakeHttp_signature_testResource;
std::shared_ptr<FakeApiResources::FakeOuterBooleanResource> m_spFakeOuterBooleanResource;

View File

@@ -0,0 +1,125 @@
/**
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 7.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "FakeBigDecimalMap_200_response.h"
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <stdexcept>
#include <regex>
#include <boost/lexical_cast.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "helpers.h"
using boost::property_tree::ptree;
using boost::property_tree::read_json;
using boost::property_tree::write_json;
namespace org {
namespace openapitools {
namespace server {
namespace model {
FakeBigDecimalMap_200_response::FakeBigDecimalMap_200_response(boost::property_tree::ptree const& pt)
{
fromPropertyTree(pt);
}
std::string FakeBigDecimalMap_200_response::toJsonString(bool prettyJson /* = false */) const
{
std::stringstream ss;
write_json(ss, this->toPropertyTree(), prettyJson);
// workaround inspired by: https://stackoverflow.com/a/56395440
std::regex reg("\\\"([0-9]+\\.{0,1}[0-9]*)\\\"");
std::string result = std::regex_replace(ss.str(), reg, "$1");
return result;
}
void FakeBigDecimalMap_200_response::fromJsonString(std::string const& jsonString)
{
std::stringstream ss(jsonString);
ptree pt;
read_json(ss,pt);
this->fromPropertyTree(pt);
}
ptree FakeBigDecimalMap_200_response::toPropertyTree() const
{
ptree pt;
ptree tmp_node;
pt.put("someId", m_SomeId);
// generate tree for SomeMap
if (!m_SomeMap.empty()) {
tmp_node = toPt(m_SomeMap);
pt.add_child("someMap", tmp_node);
}
tmp_node.clear();
return pt;
}
void FakeBigDecimalMap_200_response::fromPropertyTree(ptree const &pt)
{
ptree tmp_node;
m_SomeId = pt.get("someId", 0.0);
if (pt.get_child_optional("someMap")) {
m_SomeMap = fromPt<std::map<std::string, double>>(pt.get_child("someMap"));
}
}
double FakeBigDecimalMap_200_response::getSomeId() const
{
return m_SomeId;
}
void FakeBigDecimalMap_200_response::setSomeId(double value)
{
m_SomeId = value;
}
std::map<std::string, double> FakeBigDecimalMap_200_response::getSomeMap() const
{
return m_SomeMap;
}
void FakeBigDecimalMap_200_response::setSomeMap(std::map<std::string, double> value)
{
m_SomeMap = value;
}
std::vector<FakeBigDecimalMap_200_response> createFakeBigDecimalMap_200_responseVectorFromJsonString(const std::string& json)
{
std::stringstream sstream(json);
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json(sstream,pt);
auto vec = std::vector<FakeBigDecimalMap_200_response>();
for (const auto& child: pt) {
vec.emplace_back(FakeBigDecimalMap_200_response(child.second));
}
return vec;
}
}
}
}
}

View File

@@ -0,0 +1,96 @@
/**
* OpenAPI Petstore
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 7.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* FakeBigDecimalMap_200_response.h
*
*
*/
#ifndef FakeBigDecimalMap_200_response_H_
#define FakeBigDecimalMap_200_response_H_
#include <map>
#include <memory>
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include "helpers.h"
namespace org {
namespace openapitools {
namespace server {
namespace model {
/// <summary>
///
/// </summary>
class FakeBigDecimalMap_200_response
{
public:
FakeBigDecimalMap_200_response() = default;
explicit FakeBigDecimalMap_200_response(boost::property_tree::ptree const& pt);
virtual ~FakeBigDecimalMap_200_response() = default;
FakeBigDecimalMap_200_response(const FakeBigDecimalMap_200_response& other) = default; // copy constructor
FakeBigDecimalMap_200_response(FakeBigDecimalMap_200_response&& other) noexcept = default; // move constructor
FakeBigDecimalMap_200_response& operator=(const FakeBigDecimalMap_200_response& other) = default; // copy assignment
FakeBigDecimalMap_200_response& operator=(FakeBigDecimalMap_200_response&& other) noexcept = default; // move assignment
std::string toJsonString(bool prettyJson = false) const;
void fromJsonString(std::string const& jsonString);
boost::property_tree::ptree toPropertyTree() const;
void fromPropertyTree(boost::property_tree::ptree const& pt);
/////////////////////////////////////////////
/// FakeBigDecimalMap_200_response members
/// <summary>
///
/// </summary>
double getSomeId() const;
void setSomeId(double value);
/// <summary>
///
/// </summary>
std::map<std::string, double> getSomeMap() const;
void setSomeMap(std::map<std::string, double> value);
protected:
double m_SomeId = 0.0;
std::map<std::string, double> m_SomeMap;
};
std::vector<FakeBigDecimalMap_200_response> createFakeBigDecimalMap_200_responseVectorFromJsonString(const std::string& json);
template<>
inline boost::property_tree::ptree toPt<FakeBigDecimalMap_200_response>(const FakeBigDecimalMap_200_response& val) {
return val.toPropertyTree();
}
template<>
inline FakeBigDecimalMap_200_response fromPt<FakeBigDecimalMap_200_response>(const boost::property_tree::ptree& pt) {
FakeBigDecimalMap_200_response ret;
ret.fromPropertyTree(pt);
return ret;
}
}
}
}
}
#endif /* FakeBigDecimalMap_200_response_H_ */