forked from loafle/openapi-generator-original
[cpp-restbed-server] Allow to implement validation of input data for enumerations (#7717)
* Allow to implement validation of input data for enumerations * Regen petstore sample
This commit is contained in:
parent
0b6d70d351
commit
bb6785ad70
@ -183,6 +183,8 @@ void {{classname}}::{{setter}}({{{dataType}}} value)
|
||||
{
|
||||
{{#isEnum}}if (std::find(m_{{enumName}}.begin(), m_{{enumName}}.end(), value) != m_{{enumName}}.end()) {
|
||||
{{/isEnum}}m_{{name}} = value;{{#isEnum}}
|
||||
} else {
|
||||
throw std::runtime_error("Value " + value + " not allowed");
|
||||
}{{/isEnum}}
|
||||
}
|
||||
{{/vars}}
|
||||
|
@ -38,23 +38,6 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class PetApi: public restbed::Service
|
||||
{
|
||||
public:
|
||||
PetApi();
|
||||
~PetApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PetApiPetResource> m_spPetApiPetResource;
|
||||
std::shared_ptr<PetApiPetPetIdResource> m_spPetApiPetPetIdResource;
|
||||
std::shared_ptr<PetApiPetFindByStatusResource> m_spPetApiPetFindByStatusResource;
|
||||
std::shared_ptr<PetApiPetFindByTagsResource> m_spPetApiPetFindByTagsResource;
|
||||
std::shared_ptr<PetApiPetPetIdUploadImageResource> m_spPetApiPetPetIdUploadImageResource;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Add a new pet to the store
|
||||
/// </summary>
|
||||
@ -222,6 +205,26 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class PetApi: public restbed::Service
|
||||
{
|
||||
public:
|
||||
PetApi();
|
||||
~PetApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PetApiPetResource> m_spPetApiPetResource;
|
||||
std::shared_ptr<PetApiPetPetIdResource> m_spPetApiPetPetIdResource;
|
||||
std::shared_ptr<PetApiPetFindByStatusResource> m_spPetApiPetFindByStatusResource;
|
||||
std::shared_ptr<PetApiPetFindByTagsResource> m_spPetApiPetFindByTagsResource;
|
||||
std::shared_ptr<PetApiPetPetIdUploadImageResource> m_spPetApiPetPetIdUploadImageResource;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,21 +38,6 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class StoreApi: public restbed::Service
|
||||
{
|
||||
public:
|
||||
StoreApi();
|
||||
~StoreApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<StoreApiStoreOrderOrderIdResource> m_spStoreApiStoreOrderOrderIdResource;
|
||||
std::shared_ptr<StoreApiStoreInventoryResource> m_spStoreApiStoreInventoryResource;
|
||||
std::shared_ptr<StoreApiStoreOrderResource> m_spStoreApiStoreOrderResource;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
@ -149,6 +134,24 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class StoreApi: public restbed::Service
|
||||
{
|
||||
public:
|
||||
StoreApi();
|
||||
~StoreApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<StoreApiStoreOrderOrderIdResource> m_spStoreApiStoreOrderOrderIdResource;
|
||||
std::shared_ptr<StoreApiStoreInventoryResource> m_spStoreApiStoreInventoryResource;
|
||||
std::shared_ptr<StoreApiStoreOrderResource> m_spStoreApiStoreOrderResource;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,24 +38,6 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
class UserApi: public restbed::Service
|
||||
{
|
||||
public:
|
||||
UserApi();
|
||||
~UserApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<UserApiUserResource> m_spUserApiUserResource;
|
||||
std::shared_ptr<UserApiUserCreateWithArrayResource> m_spUserApiUserCreateWithArrayResource;
|
||||
std::shared_ptr<UserApiUserCreateWithListResource> m_spUserApiUserCreateWithListResource;
|
||||
std::shared_ptr<UserApiUserUsernameResource> m_spUserApiUserUsernameResource;
|
||||
std::shared_ptr<UserApiUserLoginResource> m_spUserApiUserLoginResource;
|
||||
std::shared_ptr<UserApiUserLogoutResource> m_spUserApiUserLogoutResource;
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// </summary>
|
||||
@ -240,6 +222,27 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class UserApi: public restbed::Service
|
||||
{
|
||||
public:
|
||||
UserApi();
|
||||
~UserApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<UserApiUserResource> m_spUserApiUserResource;
|
||||
std::shared_ptr<UserApiUserCreateWithArrayResource> m_spUserApiUserCreateWithArrayResource;
|
||||
std::shared_ptr<UserApiUserCreateWithListResource> m_spUserApiUserCreateWithListResource;
|
||||
std::shared_ptr<UserApiUserUsernameResource> m_spUserApiUserUsernameResource;
|
||||
std::shared_ptr<UserApiUserLoginResource> m_spUserApiUserLoginResource;
|
||||
std::shared_ptr<UserApiUserLogoutResource> m_spUserApiUserLogoutResource;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +123,8 @@ void Order::setStatus(std::string value)
|
||||
{
|
||||
if (std::find(m_StatusEnum.begin(), m_StatusEnum.end(), value) != m_StatusEnum.end()) {
|
||||
m_Status = value;
|
||||
} else {
|
||||
throw std::runtime_error("Value " + value + " not allowed");
|
||||
}
|
||||
}
|
||||
bool Order::isComplete() const
|
||||
|
@ -161,6 +161,8 @@ void Pet::setStatus(std::string value)
|
||||
{
|
||||
if (std::find(m_StatusEnum.begin(), m_StatusEnum.end(), value) != m_StatusEnum.end()) {
|
||||
m_Status = value;
|
||||
} else {
|
||||
throw std::runtime_error("Value " + value + " not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user