Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ public String getTypeDeclaration(Schema p) {
return toModelName(openAPIType);
}

return openAPIType;
String namespace = (String)additionalProperties.get("modelNamespace");
return namespace + "::" + openAPIType;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
{{#hasBodyParam}}
{{#bodyParam}}
{{^isPrimitiveType}}
nlohmann::json::parse(request.body()).get_to({{paramName}});
{{paramName}}.validate();
nlohmann::json::parse(request.body()).get_to({{paramName}});{{#isArray}}
for (const auto& validationParam : {{paramName}})
validationParam.validate();{{/isArray}}{{^isArray}}
{{paramName}}.validate();{{/isArray}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
{{paramName}} = request.body();
Expand Down
6 changes: 4 additions & 2 deletions samples/server/petstore/cpp-pistache/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques

try {
nlohmann::json::parse(request.body()).get_to(body);
body.validate();
for (const auto& validationParam : body)
validationParam.validate();
} catch (std::exception &e) {
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
response.send(errorInfo.first, errorInfo.second);
Expand Down Expand Up @@ -138,7 +139,8 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request

try {
nlohmann::json::parse(request.body()).get_to(body);
body.validate();
for (const auto& validationParam : body)
validationParam.validate();
} catch (std::exception &e) {
const std::pair<Pistache::Http::Code, std::string> errorInfo = this->handleParsingException(e);
response.send(errorInfo.first, errorInfo.second);
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/cpp-pistache/api/UserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ class UserApi {
///
/// </remarks>
/// <param name="body">List of user object</param>
virtual void create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Creates list of users with given input array
/// </summary>
/// <remarks>
///
/// </remarks>
/// <param name="body">List of user object</param>
virtual void create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Delete user
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ UserApiImpl::UserApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
void UserApiImpl::create_user(const User &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) {
void UserApiImpl::create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) {
void UserApiImpl::create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) {
Expand Down
4 changes: 2 additions & 2 deletions samples/server/petstore/cpp-pistache/impl/UserApiImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class UserApiImpl : public org::openapitools::server::api::UserApi {
~UserApiImpl() override = default;

void create_user(const User &body, Pistache::Http::ResponseWriter &response);
void create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response);
void create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response);
void create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &body, Pistache::Http::ResponseWriter &response);
void create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &body, Pistache::Http::ResponseWriter &response);
void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response);
void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response);
void login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response);
Expand Down
12 changes: 6 additions & 6 deletions samples/server/petstore/cpp-pistache/model/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ bool Pet::validate(std::stringstream& msg, const std::string& pathPrefix) const

if (tagsIsSet())
{
const std::vector<Tag>& value = m_Tags;
const std::vector<org::openapitools::server::model::Tag>& value = m_Tags;
const std::string currentValuePath = _pathPrefix + ".tags";


{ // Recursive validation of array elements
const std::string oldValuePath = currentValuePath;
int i = 0;
for (const Tag& value : value)
for (const org::openapitools::server::model::Tag& value : value)
{
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";

Expand Down Expand Up @@ -187,11 +187,11 @@ void Pet::unsetId()
{
m_IdIsSet = false;
}
Category Pet::getCategory() const
org::openapitools::server::model::Category Pet::getCategory() const
{
return m_Category;
}
void Pet::setCategory(Category const& value)
void Pet::setCategory(org::openapitools::server::model::Category const& value)
{
m_Category = value;
m_CategoryIsSet = true;
Expand Down Expand Up @@ -220,11 +220,11 @@ void Pet::setPhotoUrls(std::vector<std::string> const& value)
{
m_PhotoUrls = value;
}
std::vector<Tag> Pet::getTags() const
std::vector<org::openapitools::server::model::Tag> Pet::getTags() const
{
return m_Tags;
}
void Pet::setTags(std::vector<Tag> const& value)
void Pet::setTags(std::vector<org::openapitools::server::model::Tag> const& value)
{
m_Tags = value;
m_TagsIsSet = true;
Expand Down
12 changes: 6 additions & 6 deletions samples/server/petstore/cpp-pistache/model/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class Pet
/// <summary>
///
/// </summary>
Category getCategory() const;
void setCategory(Category const& value);
org::openapitools::server::model::Category getCategory() const;
void setCategory(org::openapitools::server::model::Category const& value);
bool categoryIsSet() const;
void unsetCategory();
/// <summary>
Expand All @@ -88,8 +88,8 @@ class Pet
/// <summary>
///
/// </summary>
std::vector<Tag> getTags() const;
void setTags(std::vector<Tag> const& value);
std::vector<org::openapitools::server::model::Tag> getTags() const;
void setTags(std::vector<org::openapitools::server::model::Tag> const& value);
bool tagsIsSet() const;
void unsetTags();
/// <summary>
Expand All @@ -105,13 +105,13 @@ class Pet
protected:
int64_t m_Id;
bool m_IdIsSet;
Category m_Category;
org::openapitools::server::model::Category m_Category;
bool m_CategoryIsSet;
std::string m_Name;

std::vector<std::string> m_PhotoUrls;

std::vector<Tag> m_Tags;
std::vector<org::openapitools::server::model::Tag> m_Tags;
bool m_TagsIsSet;
std::string m_Status;
bool m_StatusIsSet;
Expand Down