Merge c896857e6ab7c860aaf4ac0dc612777661da5513 into d6c46342693205f0dae441b45742d9c85d41cf33

This commit is contained in:
mowijo 2025-05-09 20:36:36 +08:00 committed by GitHub
commit 54fd083f3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
37 changed files with 1256 additions and 98 deletions

View File

@ -191,6 +191,7 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
private void setupSupportingFiles() {
supportingFiles.clear();
supportingFiles.add(new SupportingFile("api-base-header.mustache", "api", "ApiBase.h"));
supportingFiles.add(new SupportingFile("api-base-source.mustache", "api", "ApiBase.cpp"));
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));

View File

@ -14,14 +14,47 @@
namespace {{apiNamespace}}
{
{{#authMethods}}{{#isBasicBasic}}
typedef struct
{
std::string user;
std::string password;
std::unique_ptr<void, std::function<void(void*)>> userdata;
} HttpBasicCredentials;
typedef std::function<bool(HttpBasicCredentials &)> BasicCredentialsAuthenticator;
{{/isBasicBasic}}
{{#isBasicBearer}}
typedef struct
{
std::string token;
std::unique_ptr<void, std::function<void(void*)>> userdata;
} HttpBearerToken;
typedef std::function<bool(HttpBearerToken &)> BearerTokenAuthenticator;
{{/isBasicBearer}}
{{/authMethods}}
class ApiBase {
public:
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr);
virtual ~ApiBase() = default;
virtual void init() = 0;
{{#authMethods}}{{#isBasicBasic}}void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator);{{/isBasicBasic}}{{/authMethods}}
{{#authMethods}}{{#isBasicBearer}}void setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator);{{/isBasicBearer}}{{/authMethods}}
protected:
const std::shared_ptr<Pistache::Rest::Router> router;
{{#authMethods}}{{#isBasicBasic}}std::optional<BasicCredentialsAuthenticator> basicCredentialsAuthenticator;{{/isBasicBasic}}{{/authMethods}}
{{#authMethods}}{{#isBasicBearer}}std::optional<BearerTokenAuthenticator> bearerTokenAuthenticator;{{/isBasicBearer}}{{/authMethods}}
};
} // namespace {{apiNamespace}}

View File

@ -0,0 +1,24 @@
{{>licenseInfo}}
#include "ApiBase.h"
namespace {{apiNamespace}}
{
ApiBase::ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr)
{
}
{{#authMethods}}{{#isBasicBasic}}
void ApiBase::setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator)
{
basicCredentialsAuthenticator = newBasicCredentialsAuthenticator;
}
{{/isBasicBasic}}
{{#isBasicBearer}}
void ApiBase::setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator)
{
bearerTokenAuthenticator = newbearerTokenAuthenticator;
}
{{/isBasicBearer}}{{/authMethods}}
} // Namespace {{apiNamespace}}

View File

@ -79,7 +79,7 @@ private:
{{#allParams}}
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}
virtual void {{operationIdSnakeCase}}({{#allParams}}const {{#isModel}}{{^isOptional}}{{modelNamespace}}::{{/isOptional}}{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
virtual void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{#isBasicBearer}}const HttpBearerToken &accessToken, {{/isBasicBearer}}{{/authMethods}} {{#allParams}}const {{#isModel}}{{^isOptional}}{{modelNamespace}}::{{/isOptional}}{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;

View File

@ -35,7 +35,7 @@ public:
{{#operation}}
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
void {{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response);
void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials,{{/isBasicBasic}}{{#isBasicBearer}}const HttpBearerToken &bearerToken, {{/isBasicBearer}}{{/authMethods}}{{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response);
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);

View File

@ -13,11 +13,129 @@ using namespace {{modelNamespace}};{{/hasModelImport}}
{{classname}}Impl::{{classname}}Impl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: {{classname}}(rtr)
{
{{#authMethods}}{{#isBasicBasic}}/*
Http Basic Auth
===============
Do this in the individual classes in the constructor
this->setBasicCredentialsAuthenticator(
[](HttpBasicCredentials &credentials)->bool
{
if(credentials.user == "foo" && credentials.password == "bar")
{
const int userIdOfFoo = 66;
credentials.userdata = std::unique_ptr<void, std::function<void(void*)>> (
reinterpret_cast<void*>(new int(userIdOfFoo)),
[&](void* ptr)
{
int * value = reinterpret_cast<int*>(ptr);
delete value;
}
);
return true;
}
return false;
}
);
or in main:
for (auto api : apiImpls) {
api->init();
api->setBasicCredentialsAuthenticator(
[]( HttpBasicCredentials &credentials)->bool
{
if(credentials.user == "foo" && credentials.password == "bar")
{
const int userIdOfFoo = 66;
credentials.userdata = std::unique_ptr<void, std::function<void(void*)>> (
reinterpret_cast<void*>(new int(userIdOfFoo)),
[&](void* ptr)
{
int * value = reinterpret_cast<int*>(ptr);
delete value;
}
);
return true;
}
return false;
}
);
}
or a mix.
Until you do either, protected resources will result in a 401.
*/{{/isBasicBasic}}
{{#isBasicBearer}}/*
Http Basic Bearer
===============
Do this in the individual classes in the constructor
this->setBearerTokenAuthenticator(
[](HttpBearerToken &token)->bool
{
if(token.token == "Zm9vYmFyCg==")
{
const int userIdOfFoo = 99;
token.userdata = std::unique_ptr<void,std::function<void(void*)>>(
reinterpret_cast<void*>(new int(userIdOfFoo)),
[&](void* ptr)
{
int * value = reinterpret_cast<int*>(ptr);
delete value;
}
);
return true;
}
return false;
}
);
or in main:
for (auto api : apiImpls) {
api->init();
api->setBearerTokenAuthenticator(
[](HttpBearerToken &token)->bool
{
if(token.token == "Zm9vYmFyCg==")
{
const int userIdOfFoo = 99;
token.userdata = std::unique_ptr<void,std::function<void(void*)>>(
reinterpret_cast<void*>(new int(userIdOfFoo)),
[&](void* ptr)
{
int * value = reinterpret_cast<int*>(ptr);
delete value;
}
);
return true;
}
return false;
}
);
}
or a mix.
Until you do either, protected resources will result in a 401.
*/{{/isBasicBearer}}
{{/authMethods}}
}
{{#operation}}
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
void {{classname}}Impl::{{operationIdSnakeCase}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) {
void {{classname}}Impl::{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{#isBasicBearer}}const HttpBearerToken &bearerToken, {{/isBasicBearer}}{{/authMethods}}{{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}

View File

@ -15,8 +15,7 @@ const std::string {{classname}}::base = "{{basePathWithoutHost}}";
{{classname}}::{{classname}}(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void {{classname}}::init() {
setupRoutes();
@ -119,9 +118,78 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
}
try {
{{/bodyParam}}
{{/hasBodyParam}}
this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
{{#authMethods}}
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
{{/authMethods}}
{{#authMethods}}{{#isBasicBasic}}
#undef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 1
auto basicAuthHeader = request.headers().tryGet<Pistache::Http::Header::Authorization>();
if( (!basicAuthHeader) || (basicAuthHeader->getMethod() != Pistache::Http::Header::Authorization::Method::Basic))
{
response.send(Pistache::Http::Code::Unauthorized, "");
return;
}
HttpBasicCredentials credentials{basicAuthHeader->getBasicUser(), basicAuthHeader->getBasicPassword()};
if( ! this->basicCredentialsAuthenticator.has_value())
{
response.send(Pistache::Http::Code::Unauthorized, "");
return;
}
if( ! this->basicCredentialsAuthenticator.value()(credentials))
{
response.send(Pistache::Http::Code::Unauthorized, "");
return;
}
{{/isBasicBasic}}{{/authMethods}}
{{#authMethods}}{{#isBasicBearer}}
#undef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 1
auto bearerAuthHeader = request.headers().tryGet<Pistache::Http::Header::Authorization>();
if( (!bearerAuthHeader) || (bearerAuthHeader->getMethod() != Pistache::Http::Header::Authorization::Method::Bearer))
{
response.send(Pistache::Http::Code::Unauthorized, "");
return;
}
std::string completeHeaderValue = bearerAuthHeader->value();
const std::string tokenAsString(completeHeaderValue.begin() + std::string("Bearer ").length(), completeHeaderValue.end());
HttpBearerToken bearerToken{tokenAsString};
if( ! this->bearerTokenAuthenticator.has_value())
{
response.send(Pistache::Http::Code::Unauthorized, "");
return;
}
if( ! this->bearerTokenAuthenticator.value()(bearerToken))
{
response.send(Pistache::Http::Code::Unauthorized, "");
return;
}
{{/isBasicBearer}}{{/authMethods}}
this->{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}credentials,{{/isBasicBasic}}{{#isBasicBearer}}bearerToken,{{/isBasicBearer}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response);
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
try {
@ -139,6 +207,22 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "{{{vendorExtensions.x-codegen-pistache-path}}}" {{! this is nessecary, because the path does not exist in the authMethods scope.}}
{{#authMethods}}
{{! This static assert may be rendered more that once, so the compilation will fail even harder!}}
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
{{/authMethods}}
#undef REST_PATH
{{#authMethods}}
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
{{/authMethods}}
}
{{/operation}}

View File

@ -1,5 +1,6 @@
CMakeLists.txt
README.md
api/ApiBase.cpp
api/ApiBase.h
api/PetApi.cpp
api/PetApi.h

View File

@ -0,0 +1,23 @@
/**
* 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 "ApiBase.h"
namespace org::openapitools::server::api
{
ApiBase::ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr)
{
}
} // Namespace org::openapitools::server::api

View File

@ -24,14 +24,28 @@
namespace org::openapitools::server::api
{
class ApiBase {
public:
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr);
virtual ~ApiBase() = default;
virtual void init() = 0;
protected:
const std::shared_ptr<Pistache::Rest::Router> router;
};
} // namespace org::openapitools::server::api

View File

@ -23,8 +23,7 @@ const std::string PetApi::base = "/v2";
PetApi::PetApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void PetApi::init() {
setupRoutes();
@ -93,7 +92,22 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
}
try {
this->add_pet(pet, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->add_pet(pet, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -106,6 +120,17 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -117,7 +142,21 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
auto apiKey = request.headers().tryGetRaw("api_key");
try {
this->delete_pet(petId, apiKey, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->delete_pet(petId, apiKey, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -130,6 +169,17 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -146,7 +196,21 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
}
try {
this->find_pets_by_status(status, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->find_pets_by_status(status, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -159,6 +223,17 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/findByStatus"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -175,7 +250,21 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
}
try {
this->find_pets_by_tags(tags, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->find_pets_by_tags(tags, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -188,6 +277,17 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/findByTags"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -196,7 +296,21 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
auto petId = request.param(":petId").as<int64_t>();
try {
this->get_pet_by_id(petId, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->get_pet_by_id(petId, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -209,6 +323,17 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -227,7 +352,22 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
}
try {
this->update_pet(pet, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->update_pet(pet, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -240,6 +380,17 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -258,6 +409,17 @@ void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -276,6 +438,17 @@ void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistach
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId/uploadImage"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::pet_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -92,7 +92,7 @@ private:
///
/// </remarks>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual void add_pet(const org::openapitools::server::model::Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
virtual void add_pet( const org::openapitools::server::model::Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Deletes a pet
/// </summary>
@ -101,7 +101,7 @@ private:
/// </remarks>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"> (optional, default to &quot;&quot;)</param>
virtual void delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_pet( const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Finds Pets by status
/// </summary>
@ -109,7 +109,7 @@ private:
/// Multiple status values can be provided with comma separated strings
/// </remarks>
/// <param name="status">Status values that need to be considered for filter</param>
virtual void find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
virtual void find_pets_by_status( const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Finds Pets by tags
/// </summary>
@ -117,7 +117,7 @@ private:
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
/// </remarks>
/// <param name="tags">Tags to filter by</param>
virtual void find_pets_by_tags(const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
virtual void find_pets_by_tags( const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Find pet by ID
/// </summary>
@ -125,7 +125,7 @@ private:
/// Returns a single pet
/// </remarks>
/// <param name="petId">ID of pet to return</param>
virtual void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) = 0;
virtual void get_pet_by_id( const int64_t &petId, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Update an existing pet
/// </summary>
@ -133,7 +133,7 @@ private:
///
/// </remarks>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual void update_pet(const org::openapitools::server::model::Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
virtual void update_pet( const org::openapitools::server::model::Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Updates a pet in the store with form data
/// </summary>

View File

@ -23,8 +23,7 @@ const std::string StoreApi::base = "/v2";
StoreApi::StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void StoreApi::init() {
setupRoutes();
@ -79,7 +78,15 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
auto orderId = request.param(":orderId").as<std::string>();
try {
this->delete_order(orderId, response);
this->delete_order(orderId, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -92,13 +99,31 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/order/:orderId"
#undef REST_PATH
}
void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
try {
try {
this->get_inventory(response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->get_inventory(response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -111,6 +136,17 @@ void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/inventory"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -119,7 +155,15 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
auto orderId = request.param(":orderId").as<int64_t>();
try {
this->get_order_by_id(orderId, response);
this->get_order_by_id(orderId, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -132,6 +176,10 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/order/:orderId"
#undef REST_PATH
}
void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -150,7 +198,16 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
}
try {
this->place_order(order, response);
this->place_order(order, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -163,6 +220,10 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/order"
#undef REST_PATH
}
void StoreApi::store_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -87,14 +87,14 @@ private:
/// For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
/// </remarks>
/// <param name="orderId">ID of the order that needs to be deleted</param>
virtual void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_order( const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Returns pet inventories by status
/// </summary>
/// <remarks>
/// Returns a map of status codes to quantities
/// </remarks>
virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0;
virtual void get_inventory( Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Find purchase order by ID
/// </summary>
@ -102,7 +102,7 @@ private:
/// For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
/// </remarks>
/// <param name="orderId">ID of pet that needs to be fetched</param>
virtual void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
virtual void get_order_by_id( const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Place an order for a pet
/// </summary>
@ -110,7 +110,7 @@ private:
///
/// </remarks>
/// <param name="order">order placed for purchasing the pet</param>
virtual void place_order(const org::openapitools::server::model::Order &order, Pistache::Http::ResponseWriter &response) = 0;
virtual void place_order( const org::openapitools::server::model::Order &order, Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -23,8 +23,7 @@ const std::string UserApi::base = "/v2";
UserApi::UserApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void UserApi::init() {
setupRoutes();
@ -93,7 +92,22 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
}
try {
this->create_user(user, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->create_user(user, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -106,6 +120,17 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -124,7 +149,22 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
}
try {
this->create_users_with_array_input(user, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->create_users_with_array_input(user, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -137,6 +177,17 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/createWithArray"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -155,7 +206,22 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
}
try {
this->create_users_with_list_input(user, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->create_users_with_list_input(user, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -168,6 +234,17 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/createWithList"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -176,7 +253,21 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
auto username = request.param(":username").as<std::string>();
try {
this->delete_user(username, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->delete_user(username, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -189,6 +280,17 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/:username"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -197,7 +299,15 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
auto username = request.param(":username").as<std::string>();
try {
this->get_user_by_name(username, response);
this->get_user_by_name(username, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -210,6 +320,10 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/:username"
#undef REST_PATH
}
void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -234,7 +348,15 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
}
try {
this->login_user(username, password, response);
this->login_user(username, password, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -247,13 +369,31 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/login"
#undef REST_PATH
}
void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
try {
try {
this->logout_user(response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->logout_user(response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -266,6 +406,17 @@ void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Htt
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/logout"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -286,7 +437,22 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
}
try {
this->update_user(username, user, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->update_user(username, user, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -299,6 +465,17 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/:username"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void UserApi::user_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -91,7 +91,7 @@ private:
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="user">Created user object</param>
virtual void create_user(const org::openapitools::server::model::User &user, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_user( const org::openapitools::server::model::User &user, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Creates list of users with given input array
/// </summary>
@ -99,7 +99,7 @@ private:
///
/// </remarks>
/// <param name="user">List of user object</param>
virtual void create_users_with_array_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_users_with_array_input( const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Creates list of users with given input array
/// </summary>
@ -107,7 +107,7 @@ private:
///
/// </remarks>
/// <param name="user">List of user object</param>
virtual void create_users_with_list_input(const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_users_with_list_input( const std::vector<org::openapitools::server::model::User> &user, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Delete user
/// </summary>
@ -115,7 +115,7 @@ private:
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="username">The name that needs to be deleted</param>
virtual void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_user( const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Get user by user name
/// </summary>
@ -123,7 +123,7 @@ private:
///
/// </remarks>
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
virtual void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
virtual void get_user_by_name( const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Logs user into the system
/// </summary>
@ -132,14 +132,14 @@ private:
/// </remarks>
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
virtual void login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
virtual void login_user( const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Logs out current logged in user session
/// </summary>
/// <remarks>
///
/// </remarks>
virtual void logout_user(Pistache::Http::ResponseWriter &response) = 0;
virtual void logout_user( Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Updated user
/// </summary>
@ -148,7 +148,7 @@ private:
/// </remarks>
/// <param name="username">name that need to be deleted</param>
/// <param name="user">Updated user object</param>
virtual void update_user(const std::string &username, const org::openapitools::server::model::User &user, Pistache::Http::ResponseWriter &response) = 0;
virtual void update_user( const std::string &username, const org::openapitools::server::model::User &user, Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -22,6 +22,11 @@ using namespace org::openapitools::server::model;
PetApiImpl::PetApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: PetApi(rtr)
{
}
void PetApiImpl::add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {

View File

@ -22,6 +22,11 @@ using namespace org::openapitools::server::model;
StoreApiImpl::StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: StoreApi(rtr)
{
}
void StoreApiImpl::delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) {

View File

@ -22,6 +22,11 @@ using namespace org::openapitools::server::model;
UserApiImpl::UserApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: UserApi(rtr)
{
}
void UserApiImpl::create_user(const User &user, Pistache::Http::ResponseWriter &response) {

View File

@ -1,5 +1,6 @@
CMakeLists.txt
README.md
api/ApiBase.cpp
api/ApiBase.h
api/StoreApi.cpp
api/StoreApi.h

View File

@ -0,0 +1,23 @@
/**
* Test swagger file
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* 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 "ApiBase.h"
namespace org::openapitools::server::api
{
ApiBase::ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr)
{
}
} // Namespace org::openapitools::server::api

View File

@ -24,14 +24,26 @@
namespace org::openapitools::server::api
{
class ApiBase {
public:
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr);
virtual ~ApiBase() = default;
virtual void init() = 0;
protected:
const std::shared_ptr<Pistache::Rest::Router> router;
};
} // namespace org::openapitools::server::api

View File

@ -23,8 +23,7 @@ const std::string StoreApi::base = "";
StoreApi::StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void StoreApi::init() {
setupRoutes();
@ -74,7 +73,15 @@ void StoreApi::get_nested_object_handler(const Pistache::Rest::Request &, Pistac
try {
this->get_nested_object(response);
this->get_nested_object(response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -87,6 +94,10 @@ void StoreApi::get_nested_object_handler(const Pistache::Rest::Request &, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet"
#undef REST_PATH
}
void StoreApi::store_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -81,7 +81,7 @@ private:
/// <remarks>
///
/// </remarks>
virtual void get_nested_object(Pistache::Http::ResponseWriter &response) = 0;
virtual void get_nested_object( Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -22,6 +22,7 @@ using namespace org::openapitools::server::model;
StoreApiImpl::StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: StoreApi(rtr)
{
}
void StoreApiImpl::get_nested_object(Pistache::Http::ResponseWriter &response) {

View File

@ -1,5 +1,6 @@
CMakeLists.txt
README.md
api/ApiBase.cpp
api/ApiBase.h
api/PetApi.cpp
api/PetApi.h

View File

@ -0,0 +1,23 @@
/**
* 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 "ApiBase.h"
namespace org::openapitools::server::api
{
ApiBase::ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr)
{
}
} // Namespace org::openapitools::server::api

View File

@ -24,14 +24,28 @@
namespace org::openapitools::server::api
{
class ApiBase {
public:
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr);
virtual ~ApiBase() = default;
virtual void init() = 0;
protected:
const std::shared_ptr<Pistache::Rest::Router> router;
};
} // namespace org::openapitools::server::api

View File

@ -23,8 +23,7 @@ const std::string PetApi::base = "/v2";
PetApi::PetApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void PetApi::init() {
setupRoutes();
@ -93,7 +92,22 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
}
try {
this->add_pet(body, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->add_pet(body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -106,6 +120,17 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -117,7 +142,21 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
auto apiKey = request.headers().tryGetRaw("api_key");
try {
this->delete_pet(petId, apiKey, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->delete_pet(petId, apiKey, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -130,6 +169,17 @@ void PetApi::delete_pet_handler(const Pistache::Rest::Request &request, Pistache
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -146,7 +196,21 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
}
try {
this->find_pets_by_status(status, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->find_pets_by_status(status, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -159,6 +223,17 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request,
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/findByStatus"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -175,7 +250,21 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
}
try {
this->find_pets_by_tags(tags, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->find_pets_by_tags(tags, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -188,6 +277,17 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/findByTags"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -196,7 +296,21 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
auto petId = request.param(":petId").as<int64_t>();
try {
this->get_pet_by_id(petId, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->get_pet_by_id(petId, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -209,6 +323,17 @@ void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request &request, Pista
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -227,7 +352,22 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
}
try {
this->update_pet(body, response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->update_pet(body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -240,6 +380,17 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -258,6 +409,17 @@ void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request &request
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -276,6 +438,17 @@ void PetApi::upload_file_handler(const Pistache::Rest::Request &request, Pistach
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/pet/:petId/uploadImage"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void PetApi::pet_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -92,7 +92,7 @@ private:
///
/// </remarks>
/// <param name="body">Pet object that needs to be added to the store</param>
virtual void add_pet(const org::openapitools::server::model::Pet &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void add_pet( const org::openapitools::server::model::Pet &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Deletes a pet
/// </summary>
@ -101,7 +101,7 @@ private:
/// </remarks>
/// <param name="petId">Pet id to delete</param>
/// <param name="apiKey"> (optional, default to &quot;&quot;)</param>
virtual void delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_pet( const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Finds Pets by status
/// </summary>
@ -109,7 +109,7 @@ private:
/// Multiple status values can be provided with comma separated strings
/// </remarks>
/// <param name="status">Status values that need to be considered for filter</param>
virtual void find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
virtual void find_pets_by_status( const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Finds Pets by tags
/// </summary>
@ -117,7 +117,7 @@ private:
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
/// </remarks>
/// <param name="tags">Tags to filter by</param>
virtual void find_pets_by_tags(const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
virtual void find_pets_by_tags( const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Find pet by ID
/// </summary>
@ -125,7 +125,7 @@ private:
/// Returns a single pet
/// </remarks>
/// <param name="petId">ID of pet to return</param>
virtual void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) = 0;
virtual void get_pet_by_id( const int64_t &petId, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Update an existing pet
/// </summary>
@ -133,7 +133,7 @@ private:
///
/// </remarks>
/// <param name="body">Pet object that needs to be added to the store</param>
virtual void update_pet(const org::openapitools::server::model::Pet &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void update_pet( const org::openapitools::server::model::Pet &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Updates a pet in the store with form data
/// </summary>

View File

@ -23,8 +23,7 @@ const std::string StoreApi::base = "/v2";
StoreApi::StoreApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void StoreApi::init() {
setupRoutes();
@ -79,7 +78,15 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
auto orderId = request.param(":orderId").as<std::string>();
try {
this->delete_order(orderId, response);
this->delete_order(orderId, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -92,13 +99,31 @@ void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pist
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/order/:orderId"
#undef REST_PATH
}
void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
try {
try {
this->get_inventory(response);
#ifndef HTTP_BASIC_AUTH_DEFINED
#define HTTP_BASIC_AUTH_DEFINED 0
#endif
#ifndef HTTP_BEARER_AUTH_DEFINED
#define HTTP_BEARER_AUTH_DEFINED 0
#endif
this->get_inventory(response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -111,6 +136,17 @@ void StoreApi::get_inventory_handler(const Pistache::Rest::Request &, Pistache::
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/inventory"
static_assert(HTTP_BASIC_AUTH_DEFINED + HTTP_BEARER_AUTH_DEFINED < 2, "Path '" REST_PATH "' has more than one security scheme specified, and the Pistache server generator does not support that." );
#undef REST_PATH
#ifdef HTTP_BEARER_AUTH_DEFINED
#undef HTTP_BEARER_AUTH_DEFINED
#endif
#ifdef HTTP_BASIC_AUTH_DEFINED
#undef HTTP_BASIC_AUTH_DEFINED
#endif
}
void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -119,7 +155,15 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
auto orderId = request.param(":orderId").as<int64_t>();
try {
this->get_order_by_id(orderId, response);
this->get_order_by_id(orderId, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -132,6 +176,10 @@ void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request &request, P
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/order/:orderId"
#undef REST_PATH
}
void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -150,7 +198,16 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
}
try {
this->place_order(body, response);
this->place_order(body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -163,6 +220,10 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/store/order"
#undef REST_PATH
}
void StoreApi::store_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -87,14 +87,14 @@ private:
/// For valid response try integer IDs with value &lt; 1000. Anything above 1000 or nonintegers will generate API errors
/// </remarks>
/// <param name="orderId">ID of the order that needs to be deleted</param>
virtual void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_order( const std::string &orderId, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Returns pet inventories by status
/// </summary>
/// <remarks>
/// Returns a map of status codes to quantities
/// </remarks>
virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0;
virtual void get_inventory( Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Find purchase order by ID
/// </summary>
@ -102,7 +102,7 @@ private:
/// For valid response try integer IDs with value &lt;&#x3D; 5 or &gt; 10. Other values will generate exceptions
/// </remarks>
/// <param name="orderId">ID of pet that needs to be fetched</param>
virtual void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
virtual void get_order_by_id( const int64_t &orderId, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Place an order for a pet
/// </summary>
@ -110,7 +110,7 @@ private:
///
/// </remarks>
/// <param name="body">order placed for purchasing the pet</param>
virtual void place_order(const org::openapitools::server::model::Order &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void place_order( const org::openapitools::server::model::Order &body, Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -23,8 +23,7 @@ const std::string UserApi::base = "/v2";
UserApi::UserApi(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: ApiBase(rtr)
{
}
{}
void UserApi::init() {
setupRoutes();
@ -93,7 +92,16 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
}
try {
this->create_user(body, response);
this->create_user(body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -106,6 +114,10 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user"
#undef REST_PATH
}
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -124,7 +136,16 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
}
try {
this->create_users_with_array_input(body, response);
this->create_users_with_array_input(body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -137,6 +158,10 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/createWithArray"
#undef REST_PATH
}
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -155,7 +180,16 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
}
try {
this->create_users_with_list_input(body, response);
this->create_users_with_list_input(body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -168,6 +202,10 @@ void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/createWithList"
#undef REST_PATH
}
void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -176,7 +214,15 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
auto username = request.param(":username").as<std::string>();
try {
this->delete_user(username, response);
this->delete_user(username, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -189,6 +235,10 @@ void UserApi::delete_user_handler(const Pistache::Rest::Request &request, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/:username"
#undef REST_PATH
}
void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -197,7 +247,15 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
auto username = request.param(":username").as<std::string>();
try {
this->get_user_by_name(username, response);
this->get_user_by_name(username, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -210,6 +268,10 @@ void UserApi::get_user_by_name_handler(const Pistache::Rest::Request &request, P
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/:username"
#undef REST_PATH
}
void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -234,7 +296,15 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
}
try {
this->login_user(username, password, response);
this->login_user(username, password, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -247,13 +317,25 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/login"
#undef REST_PATH
}
void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {
try {
try {
this->logout_user(response);
this->logout_user(response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -266,6 +348,10 @@ void UserApi::logout_user_handler(const Pistache::Rest::Request &, Pistache::Htt
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/logout"
#undef REST_PATH
}
void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
try {
@ -286,7 +372,16 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
}
try {
this->update_user(username, body, response);
this->update_user(username, body, response);
} catch (Pistache::Http::HttpError &e) {
response.send(static_cast<Pistache::Http::Code>(e.code()), e.what());
return;
@ -299,6 +394,10 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
}
#define REST_PATH "/user/:username"
#undef REST_PATH
}
void UserApi::user_api_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) {

View File

@ -91,7 +91,7 @@ private:
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="body">Created user object</param>
virtual void create_user(const org::openapitools::server::model::User &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void create_user( const org::openapitools::server::model::User &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Creates list of users with given input array
/// </summary>
@ -99,7 +99,7 @@ private:
///
/// </remarks>
/// <param name="body">List of user object</param>
virtual void create_users_with_array_input(const std::vector<org::openapitools::server::model::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>
@ -107,7 +107,7 @@ private:
///
/// </remarks>
/// <param name="body">List of user object</param>
virtual void create_users_with_list_input(const std::vector<org::openapitools::server::model::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>
@ -115,7 +115,7 @@ private:
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="username">The name that needs to be deleted</param>
virtual void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
virtual void delete_user( const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Get user by user name
/// </summary>
@ -123,7 +123,7 @@ private:
///
/// </remarks>
/// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
virtual void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
virtual void get_user_by_name( const std::string &username, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Logs user into the system
/// </summary>
@ -132,14 +132,14 @@ private:
/// </remarks>
/// <param name="username">The user name for login</param>
/// <param name="password">The password for login in clear text</param>
virtual void login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
virtual void login_user( const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Logs out current logged in user session
/// </summary>
/// <remarks>
///
/// </remarks>
virtual void logout_user(Pistache::Http::ResponseWriter &response) = 0;
virtual void logout_user( Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Updated user
/// </summary>
@ -148,7 +148,7 @@ private:
/// </remarks>
/// <param name="username">name that need to be deleted</param>
/// <param name="body">Updated user object</param>
virtual void update_user(const std::string &username, const org::openapitools::server::model::User &body, Pistache::Http::ResponseWriter &response) = 0;
virtual void update_user( const std::string &username, const org::openapitools::server::model::User &body, Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -22,6 +22,11 @@ using namespace org::openapitools::server::model;
PetApiImpl::PetApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: PetApi(rtr)
{
}
void PetApiImpl::add_pet(const Pet &body, Pistache::Http::ResponseWriter &response) {

View File

@ -22,6 +22,11 @@ using namespace org::openapitools::server::model;
StoreApiImpl::StoreApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: StoreApi(rtr)
{
}
void StoreApiImpl::delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) {

View File

@ -22,6 +22,11 @@ using namespace org::openapitools::server::model;
UserApiImpl::UserApiImpl(const std::shared_ptr<Pistache::Rest::Router>& rtr)
: UserApi(rtr)
{
}
void UserApiImpl::create_user(const User &body, Pistache::Http::ResponseWriter &response) {