From 0302640cbc51de2a4be03949e570cfcfde0fa3f8 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sun, 20 Oct 2024 11:13:08 +0200 Subject: [PATCH 1/8] [cpp][pistache-server] Add extraction and forwarding of credentials for HTTP Basic protected endpoints. --- .../cpp-pistache-server/api-header.mustache | 2 +- .../api-impl-header.mustache | 2 +- .../api-impl-source.mustache | 2 +- .../cpp-pistache-server/api-source.mustache | 19 ++++++++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache index 3f7159044ea6..1b3475879bf1 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache @@ -79,7 +79,7 @@ private: {{#allParams}} /// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} {{/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 std::string &username, const std::string &password, {{/isBasicBasic}}{{/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; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache index 5ee20648851a..3c60c9667ef1 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache @@ -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 std::string &username, const std::string &password,{{/isBasicBasic}}{{/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); diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache index 2e25a8034b30..21bd1c8153f3 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache @@ -17,7 +17,7 @@ using namespace {{modelNamespace}};{{/hasModelImport}} {{#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 std::string &username, const std::string &password,{{/isBasicBasic}}{{/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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache index fa03ba64e1ed..15b63668076b 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache @@ -119,9 +119,26 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque } try { + {{/bodyParam}} {{/hasBodyParam}} - this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response); + {{#authMethods}}{{#isBasicBasic}} + auto basicAuthHeader = request.headers().tryGet(); + + if( (!basicAuthHeader) || (basicAuthHeader->getMethod() != Pistache::Http::Header::Authorization::Method::Basic)) + { + response.send(Pistache::Http::Code::Unauthorized, ""); + return; + } + const std::string username(basicAuthHeader->getBasicUser()); + const std::string password(basicAuthHeader->getBasicPassword()); + {{/isBasicBasic}}{{/authMethods}} + + {{#authMethods}}{{#isBasicBearer}} + /* BASIC BEARER */ + {{/isBasicBearer}}{{/authMethods}} + + this->{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}username, password,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response); {{/vendorExtensions.x-codegen-pistache-is-parsing-supported}} {{^vendorExtensions.x-codegen-pistache-is-parsing-supported}} try { From f4e8e20164bcb5f3a51c9b26219292edb028e642 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sun, 20 Oct 2024 12:09:26 +0200 Subject: [PATCH 2/8] [cpp][pistache-server] Change HTTP Basic credentials to be contained on a struct instead of two std::strings --- .../cpp-pistache-server/api-base-header.mustache | 11 +++++++++++ .../resources/cpp-pistache-server/api-header.mustache | 2 +- .../cpp-pistache-server/api-impl-header.mustache | 2 +- .../cpp-pistache-server/api-impl-source.mustache | 2 +- .../resources/cpp-pistache-server/api-source.mustache | 5 ++--- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache index ce4078976d92..f59090836d96 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache @@ -14,6 +14,17 @@ namespace {{apiNamespace}} { + + {{#authMethods}}{{#isBasicBasic}} + struct HttpBasicCredentials + { + std::string userid; + std::string password; + }; + {{/isBasicBasic}}{{/authMethods}} + + + class ApiBase { public: explicit ApiBase(const std::shared_ptr& rtr) : router(rtr) {}; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache index 1b3475879bf1..b408724e3edc 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache @@ -79,7 +79,7 @@ private: {{#allParams}} /// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} {{/allParams}} - virtual void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const std::string &username, const std::string &password, {{/isBasicBasic}}{{/authMethods}} {{#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}}{{/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; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache index 3c60c9667ef1..0bee71680f05 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache @@ -35,7 +35,7 @@ public: {{#operation}} {{#vendorExtensions.x-codegen-pistache-is-parsing-supported}} - void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const std::string &username, const std::string &password,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response); + void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials,{{/isBasicBasic}}{{/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); diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache index 21bd1c8153f3..9cecc14e4f80 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache @@ -17,7 +17,7 @@ using namespace {{modelNamespace}};{{/hasModelImport}} {{#operation}} {{#vendorExtensions.x-codegen-pistache-is-parsing-supported}} -void {{classname}}Impl::{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const std::string &username, const std::string &password,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) { +void {{classname}}Impl::{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{/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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache index 15b63668076b..5c08be5d4acc 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache @@ -130,15 +130,14 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque response.send(Pistache::Http::Code::Unauthorized, ""); return; } - const std::string username(basicAuthHeader->getBasicUser()); - const std::string password(basicAuthHeader->getBasicPassword()); + HttpBasicCredentials credentials{basicAuthHeader->getBasicUser(), basicAuthHeader->getBasicPassword()}; {{/isBasicBasic}}{{/authMethods}} {{#authMethods}}{{#isBasicBearer}} /* BASIC BEARER */ {{/isBasicBearer}}{{/authMethods}} - this->{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}username, password,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response); + this->{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}credentials,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response); {{/vendorExtensions.x-codegen-pistache-is-parsing-supported}} {{^vendorExtensions.x-codegen-pistache-is-parsing-supported}} try { From df0a1cc6a5233ff3a1ba3f4a410d5137e1219629 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Wed, 23 Oct 2024 11:21:00 +0200 Subject: [PATCH 3/8] [cpp][pistache-server] Add callbacks to authenticate http basic credentials. --- .../api-base-header.mustache | 21 +++++++++++-- .../api-impl-source.mustache | 31 +++++++++++++++++++ .../cpp-pistache-server/api-source.mustache | 17 ++++++++-- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache index f59090836d96..7abda679664b 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache @@ -16,11 +16,13 @@ namespace {{apiNamespace}} {{#authMethods}}{{#isBasicBasic}} - struct HttpBasicCredentials + typedef struct { - std::string userid; + std::string user; std::string password; - }; + } HttpBasicCredentials; + + typedef std::function BasicCredentialsAuthenticator; {{/isBasicBasic}}{{/authMethods}} @@ -31,8 +33,21 @@ public: virtual ~ApiBase() = default; virtual void init() = 0; + {{#authMethods}}{{#isBasicBasic}} + bool canCredentialsBeAccepted(const HttpBasicCredentials& credentials) const; + void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator) + { + basicCredentialsAuthenticator = newBasicCredentialsAuthenticator; + } + + {{/isBasicBasic}}{{/authMethods}} + + protected: const std::shared_ptr router; + {{#authMethods}}{{#isBasicBasic}}std::optional basicCredentialsAuthenticator;{{/isBasicBasic}}{{/authMethods}} + + }; } // namespace {{apiNamespace}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache index 9cecc14e4f80..b431ac07f4ea 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache @@ -13,6 +13,37 @@ using namespace {{modelNamespace}};{{/hasModelImport}} {{classname}}Impl::{{classname}}Impl(const std::shared_ptr& rtr) : {{classname}}(rtr) { + {{#authMethods}}{{#isBasicBasic}}/* + + Http Basic Auth + + Do this in the individual classes in the constructor + + this->setBasicCredentialsAuthenticator( + [](const HttpBasicCredentials &credentials)->bool + { + return credentials.user == "foo" && credentials.password == "bar"; + } + ); + + or in main: + + for (auto api : apiImpls) { + api->init(); + + setBasicCredentialsAuthenticator( + [](const HttpBasicCredentials &credentials)->bool + { + return credentials.user == "foo" && credentials.password == "bar"; + } + ); + } + + or a mix. + + Until you do either, protected resources will result in a 401. + */{{/isBasicBasic}}{{/authMethods}} + } {{#operation}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache index 5c08be5d4acc..9c1442c2e461 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache @@ -15,8 +15,7 @@ const std::string {{classname}}::base = "{{basePathWithoutHost}}"; {{classname}}::{{classname}}(const std::shared_ptr& rtr) : ApiBase(rtr) -{ -} +{} void {{classname}}::init() { setupRoutes(); @@ -122,7 +121,7 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque {{/bodyParam}} {{/hasBodyParam}} - {{#authMethods}}{{#isBasicBasic}} + {{#authMethods}}{{#isBasicBasic}} auto basicAuthHeader = request.headers().tryGet(); if( (!basicAuthHeader) || (basicAuthHeader->getMethod() != Pistache::Http::Header::Authorization::Method::Basic)) @@ -131,6 +130,18 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque 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}} From 94ce7ce4d901aaf5b0a91d9e83ff2c942db43388 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Wed, 23 Oct 2024 12:13:36 +0200 Subject: [PATCH 4/8] [cpp][pistache-server] Add `void* userdata` to HttpBasicCredentials. This allows for data ft be passed on from the authenticator to the handler implementation. For example a userid that has already been looked up --- .../api-base-header.mustache | 5 ++- .../api-impl-source.mustache | 45 +++++++++++++++---- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache index 7abda679664b..12e3cc4afbce 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache @@ -20,9 +20,10 @@ namespace {{apiNamespace}} { std::string user; std::string password; + std::unique_ptr> userdata; } HttpBasicCredentials; - typedef std::function BasicCredentialsAuthenticator; + typedef std::function BasicCredentialsAuthenticator; {{/isBasicBasic}}{{/authMethods}} @@ -34,7 +35,7 @@ public: virtual void init() = 0; {{#authMethods}}{{#isBasicBasic}} - bool canCredentialsBeAccepted(const HttpBasicCredentials& credentials) const; + bool canCredentialsBeAccepted(HttpBasicCredentials& credentials) const; void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator) { basicCredentialsAuthenticator = newBasicCredentialsAuthenticator; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache index b431ac07f4ea..96bd1402dd01 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache @@ -16,25 +16,54 @@ using namespace {{modelNamespace}};{{/hasModelImport}} {{#authMethods}}{{#isBasicBasic}}/* Http Basic Auth + =============== Do this in the individual classes in the constructor this->setBasicCredentialsAuthenticator( - [](const HttpBasicCredentials &credentials)->bool - { - return credentials.user == "foo" && credentials.password == "bar"; - } - ); + [](HttpBasicCredentials &credentials)->bool + { + if(credentials.user == "foo" && credentials.password == "bar") + { + + const int userIdOfFoo = 66; + credentials.userdata = std::unique_ptr> ( + reinterpret_cast(new int(userIdOfFoo)), + [&](void* ptr) + { + int * value = reinterpret_cast(ptr); + delete value; + } + ); + return true; + } + return false; + } + ); or in main: for (auto api : apiImpls) { api->init(); - setBasicCredentialsAuthenticator( - [](const HttpBasicCredentials &credentials)->bool + api->setBasicCredentialsAuthenticator( + []( HttpBasicCredentials &credentials)->bool { - return credentials.user == "foo" && credentials.password == "bar"; + if(credentials.user == "foo" && credentials.password == "bar") + { + + const int userIdOfFoo = 66; + credentials.userdata = std::unique_ptr> ( + reinterpret_cast(new int(userIdOfFoo)), + [&](void* ptr) + { + int * value = reinterpret_cast(ptr); + delete value; + } + ); + return true; + } + return false; } ); } From ebeed217071d898c87258abefba3b667509a5111 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Thu, 24 Oct 2024 11:14:11 +0200 Subject: [PATCH 5/8] [cpp][pistache-server] Add support for HTTP Bearer authentication. --- .../api-base-header.mustache | 24 +++++-- .../cpp-pistache-server/api-header.mustache | 2 +- .../api-impl-header.mustache | 2 +- .../api-impl-source.mustache | 62 ++++++++++++++++++- .../cpp-pistache-server/api-source.mustache | 61 +++++++++++++++++- 5 files changed, 141 insertions(+), 10 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache index 12e3cc4afbce..5b07a4381896 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache @@ -24,7 +24,18 @@ namespace {{apiNamespace}} } HttpBasicCredentials; typedef std::function BasicCredentialsAuthenticator; - {{/isBasicBasic}}{{/authMethods}} + {{/isBasicBasic}} + + {{#isBasicBearer}} + typedef struct + { + std::string token; + std::unique_ptr> userdata; + } HttpBearerToken; + + typedef std::function BearerTokenAuthenticator; + {{/isBasicBearer}} + {{/authMethods}} @@ -35,18 +46,23 @@ public: virtual void init() = 0; {{#authMethods}}{{#isBasicBasic}} - bool canCredentialsBeAccepted(HttpBasicCredentials& credentials) const; void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator) { basicCredentialsAuthenticator = newBasicCredentialsAuthenticator; } - - {{/isBasicBasic}}{{/authMethods}} + {{/isBasicBasic}} + {{#isBasicBearer}} + void setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator) + { + bearerTokenAuthenticator = newbearerTokenAuthenticator; + } + {{/isBasicBearer}}{{/authMethods}} protected: const std::shared_ptr router; {{#authMethods}}{{#isBasicBasic}}std::optional basicCredentialsAuthenticator;{{/isBasicBasic}}{{/authMethods}} + {{#authMethods}}{{#isBasicBearer}}std::optional bearerTokenAuthenticator;{{/isBasicBearer}}{{/authMethods}} }; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache index b408724e3edc..c556168700b3 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache @@ -79,7 +79,7 @@ private: {{#allParams}} /// {{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}} {{/allParams}} - virtual void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{/authMethods}} {{#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; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache index 0bee71680f05..090df0402163 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache @@ -35,7 +35,7 @@ public: {{#operation}} {{#vendorExtensions.x-codegen-pistache-is-parsing-supported}} - void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials,{{/isBasicBasic}}{{/authMethods}}{{#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); diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache index 96bd1402dd01..0309773ffd5c 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache @@ -71,13 +71,71 @@ using namespace {{modelNamespace}};{{/hasModelImport}} or a mix. Until you do either, protected resources will result in a 401. - */{{/isBasicBasic}}{{/authMethods}} + */{{/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>( + reinterpret_cast(new int(userIdOfFoo)), + [&](void* ptr) + { + int * value = reinterpret_cast(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>( + reinterpret_cast(new int(userIdOfFoo)), + [&](void* ptr) + { + int * value = reinterpret_cast(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}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{/authMethods}}{{#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}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache index 9c1442c2e461..178567cd7a4e 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache @@ -121,7 +121,22 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque {{/bodyParam}} {{/hasBodyParam}} + + {{#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(); if( (!basicAuthHeader) || (basicAuthHeader->getMethod() != Pistache::Http::Header::Authorization::Method::Basic)) @@ -145,10 +160,36 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque {{/isBasicBasic}}{{/authMethods}} {{#authMethods}}{{#isBasicBearer}} - /* BASIC BEARER */ +#undef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 1 + auto bearerAuthHeader = request.headers().tryGet(); + + 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}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response); + 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 { @@ -166,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}} From 7af511714fb156dc84772f7bc41ee3da0452c4b3 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sat, 26 Oct 2024 08:08:42 +0200 Subject: [PATCH 6/8] [cpp][pistache-server] Add new file `api-base-source.mustache` `api-base-source.mustache` contain implementations of security related methods and also the empty constructor. --- .../languages/CppPistacheServerCodegen.java | 1 + .../api-base-header.mustache | 16 +++---------- .../api-base-source.mustache | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java index 5e27db531d5a..b740e50db0a9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java @@ -191,6 +191,7 @@ public CppPistacheServerCodegen() { 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")); diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache index 5b07a4381896..38a04bc3164b 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache @@ -41,22 +41,12 @@ namespace {{apiNamespace}} class ApiBase { public: - explicit ApiBase(const std::shared_ptr& rtr) : router(rtr) {}; + explicit ApiBase(const std::shared_ptr& rtr); virtual ~ApiBase() = default; virtual void init() = 0; - {{#authMethods}}{{#isBasicBasic}} - void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator) - { - basicCredentialsAuthenticator = newBasicCredentialsAuthenticator; - } - {{/isBasicBasic}} - {{#isBasicBearer}} - void setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator) - { - bearerTokenAuthenticator = newbearerTokenAuthenticator; - } - {{/isBasicBearer}}{{/authMethods}} + {{#authMethods}}{{#isBasicBasic}}void setBasicCredentialsAuthenticator( const BasicCredentialsAuthenticator &newBasicCredentialsAuthenticator);{{/isBasicBasic}}{{/authMethods}} + {{#authMethods}}{{#isBasicBearer}}void setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbearerTokenAuthenticator);{{/isBasicBearer}}{{/authMethods}} protected: diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache new file mode 100644 index 000000000000..67ecde0d76a0 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache @@ -0,0 +1,24 @@ +{{>licenseInfo}} +#include "ApiBase.h" + +namespace {{apiNamespace}} +{ + +ApiBase::ApiBase(const std::shared_ptr& 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}} From 0b4bb41d0c89de90e76f9252b208dc80b7cacf39 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sat, 26 Oct 2024 08:40:27 +0200 Subject: [PATCH 7/8] [cpp][pistache-server] Add re-generated samples. --- .../.openapi-generator/FILES | 1 + .../cpp-pistache-everything/api/ApiBase.cpp | 23 ++ .../cpp-pistache-everything/api/ApiBase.h | 16 +- .../cpp-pistache-everything/api/PetApi.cpp | 189 ++++++++++++++++- .../cpp-pistache-everything/api/PetApi.h | 12 +- .../cpp-pistache-everything/api/StoreApi.cpp | 73 ++++++- .../cpp-pistache-everything/api/StoreApi.h | 8 +- .../cpp-pistache-everything/api/UserApi.cpp | 197 +++++++++++++++++- .../cpp-pistache-everything/api/UserApi.h | 16 +- .../impl/PetApiImpl.cpp | 5 + .../impl/StoreApiImpl.cpp | 5 + .../impl/UserApiImpl.cpp | 5 + .../.openapi-generator/FILES | 1 + .../api/ApiBase.cpp | 23 ++ .../api/ApiBase.h | 14 +- .../api/StoreApi.cpp | 17 +- .../api/StoreApi.h | 2 +- .../impl/StoreApiImpl.cpp | 1 + .../cpp-pistache/.openapi-generator/FILES | 1 + .../petstore/cpp-pistache/api/ApiBase.cpp | 23 ++ .../petstore/cpp-pistache/api/ApiBase.h | 16 +- .../petstore/cpp-pistache/api/PetApi.cpp | 189 ++++++++++++++++- .../server/petstore/cpp-pistache/api/PetApi.h | 12 +- .../petstore/cpp-pistache/api/StoreApi.cpp | 73 ++++++- .../petstore/cpp-pistache/api/StoreApi.h | 8 +- .../petstore/cpp-pistache/api/UserApi.cpp | 119 ++++++++++- .../petstore/cpp-pistache/api/UserApi.h | 16 +- .../petstore/cpp-pistache/impl/PetApiImpl.cpp | 5 + .../cpp-pistache/impl/StoreApiImpl.cpp | 5 + .../cpp-pistache/impl/UserApiImpl.cpp | 5 + 30 files changed, 989 insertions(+), 91 deletions(-) create mode 100644 samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp create mode 100644 samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp create mode 100644 samples/server/petstore/cpp-pistache/api/ApiBase.cpp diff --git a/samples/server/petstore/cpp-pistache-everything/.openapi-generator/FILES b/samples/server/petstore/cpp-pistache-everything/.openapi-generator/FILES index 8d2d9fc52434..6758e92432fd 100644 --- a/samples/server/petstore/cpp-pistache-everything/.openapi-generator/FILES +++ b/samples/server/petstore/cpp-pistache-everything/.openapi-generator/FILES @@ -1,5 +1,6 @@ CMakeLists.txt README.md +api/ApiBase.cpp api/ApiBase.h api/PetApi.cpp api/PetApi.h diff --git a/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp b/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp new file mode 100644 index 000000000000..673f738df944 --- /dev/null +++ b/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp @@ -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& rtr) : router(rtr) +{ +} + + + +} // Namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache-everything/api/ApiBase.h b/samples/server/petstore/cpp-pistache-everything/api/ApiBase.h index 5911d87c2d4b..d15a5e461432 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/ApiBase.h +++ b/samples/server/petstore/cpp-pistache-everything/api/ApiBase.h @@ -24,14 +24,28 @@ namespace org::openapitools::server::api { + + + + + + class ApiBase { public: - explicit ApiBase(const std::shared_ptr& rtr) : router(rtr) {}; + explicit ApiBase(const std::shared_ptr& rtr); virtual ~ApiBase() = default; virtual void init() = 0; + + + + protected: const std::shared_ptr router; + + + + }; } // namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp b/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp index 8e59e2864bdb..62fac02655ca 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp @@ -23,8 +23,7 @@ const std::string PetApi::base = "/v2"; PetApi::PetApi(const std::shared_ptr& 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(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(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(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(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(); 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(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(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) { diff --git a/samples/server/petstore/cpp-pistache-everything/api/PetApi.h b/samples/server/petstore/cpp-pistache-everything/api/PetApi.h index 29b0e2278cca..57f8e092adfe 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/PetApi.h +++ b/samples/server/petstore/cpp-pistache-everything/api/PetApi.h @@ -92,7 +92,7 @@ class PetApi : public ApiBase { /// /// /// Pet object that needs to be added to the store - 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; /// /// Deletes a pet /// @@ -101,7 +101,7 @@ class PetApi : public ApiBase { /// /// Pet id to delete /// (optional, default to "") - virtual void delete_pet(const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response) = 0; + virtual void delete_pet( const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response) = 0; /// /// Finds Pets by status /// @@ -109,7 +109,7 @@ class PetApi : public ApiBase { /// Multiple status values can be provided with comma separated strings /// /// Status values that need to be considered for filter - virtual void find_pets_by_status(const std::optional> &status, Pistache::Http::ResponseWriter &response) = 0; + virtual void find_pets_by_status( const std::optional> &status, Pistache::Http::ResponseWriter &response) = 0; /// /// Finds Pets by tags /// @@ -117,7 +117,7 @@ class PetApi : public ApiBase { /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. /// /// Tags to filter by - virtual void find_pets_by_tags(const std::optional> &tags, Pistache::Http::ResponseWriter &response) = 0; + virtual void find_pets_by_tags( const std::optional> &tags, Pistache::Http::ResponseWriter &response) = 0; /// /// Find pet by ID /// @@ -125,7 +125,7 @@ class PetApi : public ApiBase { /// Returns a single pet /// /// ID of pet to return - 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; /// /// Update an existing pet /// @@ -133,7 +133,7 @@ class PetApi : public ApiBase { /// /// /// Pet object that needs to be added to the store - 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; /// /// Updates a pet in the store with form data /// diff --git a/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp b/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp index fdb3338dddad..548fd8bbadae 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp @@ -23,8 +23,7 @@ const std::string StoreApi::base = "/v2"; StoreApi::StoreApi(const std::shared_ptr& 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(); try { - this->delete_order(orderId, response); + + + + + + + + + this->delete_order(orderId, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(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(); try { - this->get_order_by_id(orderId, response); + + + + + + + + + this->get_order_by_id(orderId, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(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) { diff --git a/samples/server/petstore/cpp-pistache-everything/api/StoreApi.h b/samples/server/petstore/cpp-pistache-everything/api/StoreApi.h index e0c75e4fd7c0..ffd70b686472 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/StoreApi.h +++ b/samples/server/petstore/cpp-pistache-everything/api/StoreApi.h @@ -87,14 +87,14 @@ class StoreApi : public ApiBase { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors /// /// ID of the order that needs to be deleted - 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; /// /// Returns pet inventories by status /// /// /// Returns a map of status codes to quantities /// - virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0; + virtual void get_inventory( Pistache::Http::ResponseWriter &response) = 0; /// /// Find purchase order by ID /// @@ -102,7 +102,7 @@ class StoreApi : public ApiBase { /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions /// /// ID of pet that needs to be fetched - 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; /// /// Place an order for a pet /// @@ -110,7 +110,7 @@ class StoreApi : public ApiBase { /// /// /// order placed for purchasing the pet - 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; }; diff --git a/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp b/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp index e2019050620f..13671dd13b97 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp @@ -23,8 +23,7 @@ const std::string UserApi::base = "/v2"; UserApi::UserApi(const std::shared_ptr& 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(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(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(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(); 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(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(); try { - this->get_user_by_name(username, response); + + + + + + + + + this->get_user_by_name(username, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(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(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(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) { diff --git a/samples/server/petstore/cpp-pistache-everything/api/UserApi.h b/samples/server/petstore/cpp-pistache-everything/api/UserApi.h index b40dc0ff6030..ab7587c9f1e4 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/UserApi.h +++ b/samples/server/petstore/cpp-pistache-everything/api/UserApi.h @@ -91,7 +91,7 @@ class UserApi : public ApiBase { /// This can only be done by the logged in user. /// /// Created user object - 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; /// /// Creates list of users with given input array /// @@ -99,7 +99,7 @@ class UserApi : public ApiBase { /// /// /// List of user object - virtual void create_users_with_array_input(const std::vector &user, Pistache::Http::ResponseWriter &response) = 0; + virtual void create_users_with_array_input( const std::vector &user, Pistache::Http::ResponseWriter &response) = 0; /// /// Creates list of users with given input array /// @@ -107,7 +107,7 @@ class UserApi : public ApiBase { /// /// /// List of user object - virtual void create_users_with_list_input(const std::vector &user, Pistache::Http::ResponseWriter &response) = 0; + virtual void create_users_with_list_input( const std::vector &user, Pistache::Http::ResponseWriter &response) = 0; /// /// Delete user /// @@ -115,7 +115,7 @@ class UserApi : public ApiBase { /// This can only be done by the logged in user. /// /// The name that needs to be deleted - 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; /// /// Get user by user name /// @@ -123,7 +123,7 @@ class UserApi : public ApiBase { /// /// /// The name that needs to be fetched. Use user1 for testing. - 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; /// /// Logs user into the system /// @@ -132,14 +132,14 @@ class UserApi : public ApiBase { /// /// The user name for login /// The password for login in clear text - virtual void login_user(const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response) = 0; + virtual void login_user( const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response) = 0; /// /// Logs out current logged in user session /// /// /// /// - virtual void logout_user(Pistache::Http::ResponseWriter &response) = 0; + virtual void logout_user( Pistache::Http::ResponseWriter &response) = 0; /// /// Updated user /// @@ -148,7 +148,7 @@ class UserApi : public ApiBase { /// /// name that need to be deleted /// Updated user object - 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; }; diff --git a/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp b/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp index 9841c6d24542..fca6ee95568e 100644 --- a/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp @@ -22,6 +22,11 @@ using namespace org::openapitools::server::model; PetApiImpl::PetApiImpl(const std::shared_ptr& rtr) : PetApi(rtr) { + + + + + } void PetApiImpl::add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache-everything/impl/StoreApiImpl.cpp b/samples/server/petstore/cpp-pistache-everything/impl/StoreApiImpl.cpp index f36debfb4c39..21270810e537 100644 --- a/samples/server/petstore/cpp-pistache-everything/impl/StoreApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache-everything/impl/StoreApiImpl.cpp @@ -22,6 +22,11 @@ using namespace org::openapitools::server::model; StoreApiImpl::StoreApiImpl(const std::shared_ptr& rtr) : StoreApi(rtr) { + + + + + } void StoreApiImpl::delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache-everything/impl/UserApiImpl.cpp b/samples/server/petstore/cpp-pistache-everything/impl/UserApiImpl.cpp index 97a3b8451202..11142ba0e0ef 100644 --- a/samples/server/petstore/cpp-pistache-everything/impl/UserApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache-everything/impl/UserApiImpl.cpp @@ -22,6 +22,11 @@ using namespace org::openapitools::server::model; UserApiImpl::UserApiImpl(const std::shared_ptr& rtr) : UserApi(rtr) { + + + + + } void UserApiImpl::create_user(const User &user, Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/.openapi-generator/FILES b/samples/server/petstore/cpp-pistache-nested-schema-refs/.openapi-generator/FILES index 1abc72ab7dfa..5a1fa9ea30ea 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/.openapi-generator/FILES +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/.openapi-generator/FILES @@ -1,5 +1,6 @@ CMakeLists.txt README.md +api/ApiBase.cpp api/ApiBase.h api/StoreApi.cpp api/StoreApi.h diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp new file mode 100644 index 000000000000..5244017f94a6 --- /dev/null +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp @@ -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& rtr) : router(rtr) +{ +} + + + +} // Namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.h b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.h index 21ce41d1fd6b..94bedb502904 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.h +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.h @@ -24,14 +24,26 @@ namespace org::openapitools::server::api { + + + + class ApiBase { public: - explicit ApiBase(const std::shared_ptr& rtr) : router(rtr) {}; + explicit ApiBase(const std::shared_ptr& rtr); virtual ~ApiBase() = default; virtual void init() = 0; + + + + protected: const std::shared_ptr router; + + + + }; } // namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp index 0be772810530..0fc2664f6d83 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp @@ -23,8 +23,7 @@ const std::string StoreApi::base = ""; StoreApi::StoreApi(const std::shared_ptr& 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(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) { diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.h b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.h index c58857af0d5e..f8000577dc23 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.h +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.h @@ -81,7 +81,7 @@ class StoreApi : public ApiBase { /// /// /// - virtual void get_nested_object(Pistache::Http::ResponseWriter &response) = 0; + virtual void get_nested_object( Pistache::Http::ResponseWriter &response) = 0; }; diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/impl/StoreApiImpl.cpp b/samples/server/petstore/cpp-pistache-nested-schema-refs/impl/StoreApiImpl.cpp index 93d057d023a3..461a67b0b333 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/impl/StoreApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/impl/StoreApiImpl.cpp @@ -22,6 +22,7 @@ using namespace org::openapitools::server::model; StoreApiImpl::StoreApiImpl(const std::shared_ptr& rtr) : StoreApi(rtr) { + } void StoreApiImpl::get_nested_object(Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache/.openapi-generator/FILES b/samples/server/petstore/cpp-pistache/.openapi-generator/FILES index fac6a2c285e6..e5fbc75ef495 100644 --- a/samples/server/petstore/cpp-pistache/.openapi-generator/FILES +++ b/samples/server/petstore/cpp-pistache/.openapi-generator/FILES @@ -1,5 +1,6 @@ CMakeLists.txt README.md +api/ApiBase.cpp api/ApiBase.h api/PetApi.cpp api/PetApi.h diff --git a/samples/server/petstore/cpp-pistache/api/ApiBase.cpp b/samples/server/petstore/cpp-pistache/api/ApiBase.cpp new file mode 100644 index 000000000000..673f738df944 --- /dev/null +++ b/samples/server/petstore/cpp-pistache/api/ApiBase.cpp @@ -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& rtr) : router(rtr) +{ +} + + + +} // Namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache/api/ApiBase.h b/samples/server/petstore/cpp-pistache/api/ApiBase.h index 5911d87c2d4b..d15a5e461432 100644 --- a/samples/server/petstore/cpp-pistache/api/ApiBase.h +++ b/samples/server/petstore/cpp-pistache/api/ApiBase.h @@ -24,14 +24,28 @@ namespace org::openapitools::server::api { + + + + + + class ApiBase { public: - explicit ApiBase(const std::shared_ptr& rtr) : router(rtr) {}; + explicit ApiBase(const std::shared_ptr& rtr); virtual ~ApiBase() = default; virtual void init() = 0; + + + + protected: const std::shared_ptr router; + + + + }; } // namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache/api/PetApi.cpp b/samples/server/petstore/cpp-pistache/api/PetApi.cpp index 0150d01324f4..74b40893278f 100644 --- a/samples/server/petstore/cpp-pistache/api/PetApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/PetApi.cpp @@ -23,8 +23,7 @@ const std::string PetApi::base = "/v2"; PetApi::PetApi(const std::shared_ptr& 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(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(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(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(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(); 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(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(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) { diff --git a/samples/server/petstore/cpp-pistache/api/PetApi.h b/samples/server/petstore/cpp-pistache/api/PetApi.h index 6829f157e54b..ebc94a35117f 100644 --- a/samples/server/petstore/cpp-pistache/api/PetApi.h +++ b/samples/server/petstore/cpp-pistache/api/PetApi.h @@ -92,7 +92,7 @@ class PetApi : public ApiBase { /// /// /// Pet object that needs to be added to the store - 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; /// /// Deletes a pet /// @@ -101,7 +101,7 @@ class PetApi : public ApiBase { /// /// Pet id to delete /// (optional, default to "") - virtual void delete_pet(const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response) = 0; + virtual void delete_pet( const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response) = 0; /// /// Finds Pets by status /// @@ -109,7 +109,7 @@ class PetApi : public ApiBase { /// Multiple status values can be provided with comma separated strings /// /// Status values that need to be considered for filter - virtual void find_pets_by_status(const std::optional> &status, Pistache::Http::ResponseWriter &response) = 0; + virtual void find_pets_by_status( const std::optional> &status, Pistache::Http::ResponseWriter &response) = 0; /// /// Finds Pets by tags /// @@ -117,7 +117,7 @@ class PetApi : public ApiBase { /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. /// /// Tags to filter by - virtual void find_pets_by_tags(const std::optional> &tags, Pistache::Http::ResponseWriter &response) = 0; + virtual void find_pets_by_tags( const std::optional> &tags, Pistache::Http::ResponseWriter &response) = 0; /// /// Find pet by ID /// @@ -125,7 +125,7 @@ class PetApi : public ApiBase { /// Returns a single pet /// /// ID of pet to return - 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; /// /// Update an existing pet /// @@ -133,7 +133,7 @@ class PetApi : public ApiBase { /// /// /// Pet object that needs to be added to the store - 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; /// /// Updates a pet in the store with form data /// diff --git a/samples/server/petstore/cpp-pistache/api/StoreApi.cpp b/samples/server/petstore/cpp-pistache/api/StoreApi.cpp index 768998c87f3e..870a79116194 100644 --- a/samples/server/petstore/cpp-pistache/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/StoreApi.cpp @@ -23,8 +23,7 @@ const std::string StoreApi::base = "/v2"; StoreApi::StoreApi(const std::shared_ptr& 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(); try { - this->delete_order(orderId, response); + + + + + + + + + this->delete_order(orderId, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(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(); try { - this->get_order_by_id(orderId, response); + + + + + + + + + this->get_order_by_id(orderId, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(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) { diff --git a/samples/server/petstore/cpp-pistache/api/StoreApi.h b/samples/server/petstore/cpp-pistache/api/StoreApi.h index 0357820d492f..d92812c448c6 100644 --- a/samples/server/petstore/cpp-pistache/api/StoreApi.h +++ b/samples/server/petstore/cpp-pistache/api/StoreApi.h @@ -87,14 +87,14 @@ class StoreApi : public ApiBase { /// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors /// /// ID of the order that needs to be deleted - 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; /// /// Returns pet inventories by status /// /// /// Returns a map of status codes to quantities /// - virtual void get_inventory(Pistache::Http::ResponseWriter &response) = 0; + virtual void get_inventory( Pistache::Http::ResponseWriter &response) = 0; /// /// Find purchase order by ID /// @@ -102,7 +102,7 @@ class StoreApi : public ApiBase { /// For valid response try integer IDs with value <= 5 or > 10. Other values will generate exceptions /// /// ID of pet that needs to be fetched - 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; /// /// Place an order for a pet /// @@ -110,7 +110,7 @@ class StoreApi : public ApiBase { /// /// /// order placed for purchasing the pet - 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; }; diff --git a/samples/server/petstore/cpp-pistache/api/UserApi.cpp b/samples/server/petstore/cpp-pistache/api/UserApi.cpp index 3669077f2146..3bdeea152f9d 100644 --- a/samples/server/petstore/cpp-pistache/api/UserApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/UserApi.cpp @@ -23,8 +23,7 @@ const std::string UserApi::base = "/v2"; UserApi::UserApi(const std::shared_ptr& 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(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(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(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(); try { - this->delete_user(username, response); + + + + + + + + + this->delete_user(username, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(); try { - this->get_user_by_name(username, response); + + + + + + + + + this->get_user_by_name(username, response); } catch (Pistache::Http::HttpError &e) { response.send(static_cast(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(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(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(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) { diff --git a/samples/server/petstore/cpp-pistache/api/UserApi.h b/samples/server/petstore/cpp-pistache/api/UserApi.h index b153acd9008b..6aa1d6fcd86e 100644 --- a/samples/server/petstore/cpp-pistache/api/UserApi.h +++ b/samples/server/petstore/cpp-pistache/api/UserApi.h @@ -91,7 +91,7 @@ class UserApi : public ApiBase { /// This can only be done by the logged in user. /// /// Created user object - 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; /// /// Creates list of users with given input array /// @@ -99,7 +99,7 @@ class UserApi : public ApiBase { /// /// /// List of user object - virtual void create_users_with_array_input(const std::vector &body, Pistache::Http::ResponseWriter &response) = 0; + virtual void create_users_with_array_input( const std::vector &body, Pistache::Http::ResponseWriter &response) = 0; /// /// Creates list of users with given input array /// @@ -107,7 +107,7 @@ class UserApi : public ApiBase { /// /// /// List of user object - virtual void create_users_with_list_input(const std::vector &body, Pistache::Http::ResponseWriter &response) = 0; + virtual void create_users_with_list_input( const std::vector &body, Pistache::Http::ResponseWriter &response) = 0; /// /// Delete user /// @@ -115,7 +115,7 @@ class UserApi : public ApiBase { /// This can only be done by the logged in user. /// /// The name that needs to be deleted - 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; /// /// Get user by user name /// @@ -123,7 +123,7 @@ class UserApi : public ApiBase { /// /// /// The name that needs to be fetched. Use user1 for testing. - 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; /// /// Logs user into the system /// @@ -132,14 +132,14 @@ class UserApi : public ApiBase { /// /// The user name for login /// The password for login in clear text - virtual void login_user(const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response) = 0; + virtual void login_user( const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response) = 0; /// /// Logs out current logged in user session /// /// /// /// - virtual void logout_user(Pistache::Http::ResponseWriter &response) = 0; + virtual void logout_user( Pistache::Http::ResponseWriter &response) = 0; /// /// Updated user /// @@ -148,7 +148,7 @@ class UserApi : public ApiBase { /// /// name that need to be deleted /// Updated user object - 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; }; diff --git a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp index b27e5d4d5845..a33aa5db630a 100644 --- a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp @@ -22,6 +22,11 @@ using namespace org::openapitools::server::model; PetApiImpl::PetApiImpl(const std::shared_ptr& rtr) : PetApi(rtr) { + + + + + } void PetApiImpl::add_pet(const Pet &body, Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.cpp b/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.cpp index a746316b8039..01c8c6e5ef86 100644 --- a/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.cpp @@ -22,6 +22,11 @@ using namespace org::openapitools::server::model; StoreApiImpl::StoreApiImpl(const std::shared_ptr& rtr) : StoreApi(rtr) { + + + + + } void StoreApiImpl::delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp b/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp index 54510e9970f9..1acf8a9e1b07 100644 --- a/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp @@ -22,6 +22,11 @@ using namespace org::openapitools::server::model; UserApiImpl::UserApiImpl(const std::shared_ptr& rtr) : UserApi(rtr) { + + + + + } void UserApiImpl::create_user(const User &body, Pistache::Http::ResponseWriter &response) { From 8f0bb7a0f015a89635d332a0b61a9f3b37fb2124 Mon Sep 17 00:00:00 2001 From: Kasper Kielsholm Ramsgaard Date: Wed, 12 Nov 2025 08:13:55 +0000 Subject: [PATCH 8/8] Fix PR 19978: Updated indentation levels and fixed test problems --- .../api-base-source.mustache | 3 +- .../api-impl-header.mustache | 3 +- .../api-impl-source.mustache | 5 +- .../cpp-pistache-server/api-source.mustache | 295 +++++----- .../cpp-pistache-everything/api/ApiBase.cpp | 1 - .../cpp-pistache-everything/api/PetApi.cpp | 541 +++++++++-------- .../cpp-pistache-everything/api/StoreApi.cpp | 189 +++--- .../cpp-pistache-everything/api/UserApi.cpp | 557 +++++++++--------- .../impl/PetApiImpl.cpp | 4 +- .../api/ApiBase.cpp | 1 - .../api/StoreApi.cpp | 41 +- .../petstore/cpp-pistache/api/ApiBase.cpp | 1 - .../petstore/cpp-pistache/api/PetApi.cpp | 541 +++++++++-------- .../petstore/cpp-pistache/api/StoreApi.cpp | 189 +++--- .../petstore/cpp-pistache/api/UserApi.cpp | 377 ++++++------ .../petstore/cpp-pistache/impl/PetApiImpl.cpp | 4 +- 16 files changed, 1426 insertions(+), 1326 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache index 67ecde0d76a0..4415c77cdf5b 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-source.mustache @@ -19,6 +19,7 @@ void ApiBase::setBearerTokenAuthenticator( const BearerTokenAuthenticator &newbe { bearerTokenAuthenticator = newbearerTokenAuthenticator; } -{{/isBasicBearer}}{{/authMethods}} +{{/isBasicBearer}} +{{/authMethods}} } // Namespace {{apiNamespace}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache index 090df0402163..ead66194855a 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache @@ -26,7 +26,8 @@ namespace {{apiNamespace}} { {{#hasModelImport}} -using namespace {{modelNamespace}};{{/hasModelImport}} +using namespace {{modelNamespace}}; +{{/hasModelImport}} class {{declspec}} {{classname}}Impl : public {{apiNamespace}}::{{classname}} { public: diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache index 0309773ffd5c..4ebaa3ec798b 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache @@ -8,7 +8,8 @@ namespace {{this}} { {{/apiNamespaceDeclarations}} {{#hasModelImport}} -using namespace {{modelNamespace}};{{/hasModelImport}} +using namespace {{modelNamespace}}; +{{/hasModelImport}} {{classname}}Impl::{{classname}}Impl(const std::shared_ptr& rtr) : {{classname}}(rtr) @@ -140,7 +141,7 @@ void {{classname}}Impl::{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic } {{/vendorExtensions.x-codegen-pistache-is-parsing-supported}} {{^vendorExtensions.x-codegen-pistache-is-parsing-supported}} -void {{classname}}Impl::{{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){ +void {{classname}}Impl::{{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } {{/vendorExtensions.x-codegen-pistache-is-parsing-supported}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache index 178567cd7a4e..1837398bdbb2 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache @@ -9,7 +9,8 @@ namespace {{apiNamespace}} using namespace {{helpersNamespace}}; {{#hasModelImport}} -using namespace {{modelNamespace}};{{/hasModelImport}} +using namespace {{modelNamespace}}; +{{/hasModelImport}} const std::string {{classname}}::base = "{{basePathWithoutHost}}"; @@ -32,14 +33,12 @@ void {{classname}}::setupRoutes() { router->addCustomHandler(Routes::bind(&{{classname}}::{{classnameSnakeLowerCase}}_default_handler, this)); } -void {{classname}}::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void {{classname}}::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair {{classname}}::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair {{classname}}::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -51,179 +50,187 @@ std::pair {{classname}}::handleParsingExcepti } } -void {{classname}}::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void {{classname}}::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair {{classname}}::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair {{classname}}::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } {{#operation}} -void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Request &{{#hasParams}}request{{/hasParams}}, Pistache::Http::ResponseWriter response) { +void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - - {{#vendorExtensions.x-codegen-pistache-is-parsing-supported}} - {{#hasPathParams}} - // Getting the path params - {{#pathParams}} - auto {{paramName}} = request.param(":{{paramName}}").as<{{dataType}}>(); - {{/pathParams}} - {{/hasPathParams}}{{#hasBodyParam}} - // Getting the body param - {{#bodyParam}} - {{^isPrimitiveType}}{{^isContainer}} - {{baseType}} {{paramName}};{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}> {{paramName}};{{/isArray}}{{#isMap}}std::map {{paramName}};{{/isMap}}{{/isPrimitiveType}} - {{#isPrimitiveType}} - {{dataType}} {{paramName}}; - {{/isPrimitiveType}} - {{/bodyParam}} - {{/hasBodyParam}}{{#hasQueryParams}} - // Getting the query params - {{#queryParams}} - auto {{paramName}}Query = request.query().get("{{baseName}}"); - std::optional<{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}}> {{paramName}}; - if({{paramName}}Query.has_value()){ - {{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}} valueQuery_instance; - if(fromStringValue({{paramName}}Query.value(), valueQuery_instance)){ - {{paramName}} = valueQuery_instance; + {{#vendorExtensions.x-codegen-pistache-is-parsing-supported}} + + {{#hasPathParams}} + // Getting the path params + {{#pathParams}} + auto {{paramName}} = request.param(":{{paramName}}").as<{{dataType}}>(); + {{/pathParams}} + {{/hasPathParams}} + + {{#hasBodyParam}} + // Getting the body param + {{#bodyParam}} + {{^isPrimitiveType}}{{^isContainer}} + {{baseType}} {{paramName}}; + {{/isContainer}} + {{#isArray}}std::vector<{{items.baseType}}> {{paramName}};{{/isArray}} + {{#isMap}}std::map {{paramName}};{{/isMap}} + {{/isPrimitiveType}} + {{#isPrimitiveType}} + {{dataType}} {{paramName}}; + {{/isPrimitiveType}} + {{/bodyParam}} + {{/hasBodyParam}} + + {{#hasQueryParams}} + // Getting the query params + {{#queryParams}} + auto {{paramName}}Query = request.query().get("{{baseName}}"); + std::optional<{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}}> {{paramName}}; + if ({{paramName}}Query.has_value()) { + {{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}} valueQuery_instance; + if (fromStringValue({{paramName}}Query.value(), valueQuery_instance)) { + {{paramName}} = valueQuery_instance; + } } - } - {{/queryParams}} - {{/hasQueryParams}}{{#hasHeaderParams}} - // Getting the header params - {{#headerParams}} - auto {{paramName}} = request.headers().tryGetRaw("{{baseName}}"); - {{/headerParams}} - {{/hasHeaderParams}} - - try { - {{#hasBodyParam}} - {{#bodyParam}} - {{^isPrimitiveType}} - 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(); - {{/isPrimitiveType}} - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - - try { - - {{/bodyParam}} - {{/hasBodyParam}} + {{/queryParams}} + {{/hasQueryParams}} + + {{#hasHeaderParams}} + // Getting the header params + {{#headerParams}} + auto {{paramName}} = request.headers().tryGetRaw("{{baseName}}"); + {{/headerParams}} + {{/hasHeaderParams}} + + {{#hasBodyParam}} + try { + {{#bodyParam}} + {{^isPrimitiveType}} + 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(); + {{/isPrimitiveType}} + {{/bodyParam}} + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + {{/hasBodyParam}} - {{#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}} + try { +{{#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}} +{{#authMethods}}{{#isBasicBasic}} #undef HTTP_BASIC_AUTH_DEFINED #define HTTP_BASIC_AUTH_DEFINED 1 - auto basicAuthHeader = request.headers().tryGet(); + auto basicAuthHeader = request.headers().tryGet(); - 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(!basicAuthHeader || (basicAuthHeader->getMethod() != Pistache::Http::Header::Authorization::Method::Basic)) + { + response.send(Pistache::Http::Code::Unauthorized, ""); + return; + } - if( ! this->basicCredentialsAuthenticator.value()(credentials)) - { - response.send(Pistache::Http::Code::Unauthorized, ""); - return; - } + HttpBasicCredentials credentials{basicAuthHeader->getBasicUser(), basicAuthHeader->getBasicPassword()}; + + if (!this->basicCredentialsAuthenticator.has_value() || !this->basicCredentialsAuthenticator.value()(credentials)) + { + response.send(Pistache::Http::Code::Unauthorized, ""); + return; + } - {{/isBasicBasic}}{{/authMethods}} +{{/isBasicBasic}} +{{/authMethods}} - {{#authMethods}}{{#isBasicBearer}} +{{#authMethods}} +{{#isBasicBearer}} #undef HTTP_BEARER_AUTH_DEFINED #define HTTP_BEARER_AUTH_DEFINED 1 - auto bearerAuthHeader = request.headers().tryGet(); - - 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 { - this->{{operationIdSnakeCase}}(request, response); - {{/vendorExtensions.x-codegen-pistache-is-parsing-supported}} - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + auto bearerAuthHeader = request.headers().tryGet(); + + 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() || !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 { + this->{{operationIdSnakeCase}}(request, response); + {{/vendorExtensions.x-codegen-pistache-is-parsing-supported}} + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } + {{#hasAuthMethods}} +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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}} + 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 - - {{#authMethods}} - #ifdef HTTP_BEARER_AUTH_DEFINED - #undef HTTP_BEARER_AUTH_DEFINED - #endif - #ifdef HTTP_BASIC_AUTH_DEFINED - #undef HTTP_BASIC_AUTH_DEFINED - #endif - {{/authMethods}} +#ifdef HTTP_BEARER_AUTH_DEFINED +#undef HTTP_BEARER_AUTH_DEFINED +#endif +#ifdef HTTP_BASIC_AUTH_DEFINED +#undef HTTP_BASIC_AUTH_DEFINED +#endif + {{/hasAuthMethods}} } + {{/operation}} void {{classname}}::{{classnameSnakeLowerCase}}_default_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { diff --git a/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp b/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp index 673f738df944..ae7fa32612d6 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/ApiBase.cpp @@ -19,5 +19,4 @@ ApiBase::ApiBase(const std::shared_ptr& rtr) : router(rt } - } // Namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp b/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp index 62fac02655ca..dbd1f9fe6412 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/PetApi.cpp @@ -45,14 +45,12 @@ void PetApi::setupRoutes() { router->addCustomHandler(Routes::bind(&PetApi::pet_api_default_handler, this)); } -void PetApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void PetApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair PetApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair PetApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -64,393 +62,440 @@ std::pair PetApi::handleParsingException(cons } } -void PetApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void PetApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair PetApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair PetApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { +void PetApi::add_pet_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - - // Getting the body param - - Pet pet; + + // Getting the body param + + Pet pet; + + + - try { - nlohmann::json::parse(request.body()).get_to(pet); - pet.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - - try { + try { + nlohmann::json::parse(request.body()).get_to(pet); + pet.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->add_pet(pet, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void PetApi::delete_pet_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto petId = request.param(":petId").as(); + // Getting the path params + auto petId = request.param(":petId").as(); + + - // Getting the header params - auto apiKey = request.headers().tryGetRaw("api_key"); + // Getting the header params + auto apiKey = request.headers().tryGetRaw("api_key"); - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->delete_pet(petId, apiKey, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { + try { - // Getting the query params - auto statusQuery = request.query().get("status"); - std::optional> status; - if(statusQuery.has_value()){ - std::vector valueQuery_instance; - if(fromStringValue(statusQuery.value(), valueQuery_instance)){ - status = valueQuery_instance; + + + // Getting the query params + auto statusQuery = request.query().get("status"); + std::optional> status; + if (statusQuery.has_value()) { + std::vector valueQuery_instance; + if (fromStringValue(statusQuery.value(), valueQuery_instance)) { + status = valueQuery_instance; + } } - } - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->find_pets_by_status(status, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { + try { - // Getting the query params - auto tagsQuery = request.query().get("tags"); - std::optional> tags; - if(tagsQuery.has_value()){ - std::vector valueQuery_instance; - if(fromStringValue(tagsQuery.value(), valueQuery_instance)){ - tags = valueQuery_instance; + + + // Getting the query params + auto tagsQuery = request.query().get("tags"); + std::optional> tags; + if (tagsQuery.has_value()) { + std::vector valueQuery_instance; + if (fromStringValue(tagsQuery.value(), valueQuery_instance)) { + tags = valueQuery_instance; + } } - } - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->find_pets_by_tags(tags, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto petId = request.param(":petId").as(); + // Getting the path params + auto petId = request.param(":petId").as(); + + - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->get_pet_by_id(petId, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { - - // Getting the body param - - Pet pet; - +void PetApi::update_pet_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(pet); - pet.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + + Pet pet; + + + + + try { + nlohmann::json::parse(request.body()).get_to(pet); + pet.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->update_pet(pet, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - this->update_pet_with_form(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + try { + this->update_pet_with_form(request, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::upload_file_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - this->upload_file(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + try { + this->upload_file(request, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp b/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp index 548fd8bbadae..af764f18fabb 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/StoreApi.cpp @@ -41,14 +41,12 @@ void StoreApi::setupRoutes() { router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this)); } -void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair StoreApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair StoreApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -60,172 +58,173 @@ std::pair StoreApi::handleParsingException(co } } -void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair StoreApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair StoreApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { +void StoreApi::delete_order_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto orderId = request.param(":orderId").as(); + // Getting the path params + auto orderId = request.param(":orderId").as(); + + - try { + try { - - - this->delete_order(orderId, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->delete_order(orderId, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { + +void StoreApi::get_inventory_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { + + + - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->get_inventory(response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto orderId = request.param(":orderId").as(); + // Getting the path params + auto orderId = request.param(":orderId").as(); + + - try { + try { - - - this->get_order_by_id(orderId, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->get_order_by_id(orderId, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { - - // Getting the body param - - Order order; - +void StoreApi::place_order_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(order); - order.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + + Order order; + + + + + try { + nlohmann::json::parse(request.body()).get_to(order); + order.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + try { - - - this->place_order(order, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->place_order(order, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp b/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp index 13671dd13b97..4e19fee2b877 100644 --- a/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp +++ b/samples/server/petstore/cpp-pistache-everything/api/UserApi.cpp @@ -45,14 +45,12 @@ void UserApi::setupRoutes() { router->addCustomHandler(Routes::bind(&UserApi::user_api_default_handler, this)); } -void UserApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void UserApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair UserApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair UserApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -64,420 +62,451 @@ std::pair UserApi::handleParsingException(con } } -void UserApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void UserApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair UserApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair UserApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { +void UserApi::create_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - - // Getting the body param - - User user; + + // Getting the body param + + User user; + + + - try { - nlohmann::json::parse(request.body()).get_to(user); - user.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - - try { + try { + nlohmann::json::parse(request.body()).get_to(user); + user.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->create_user(user, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { - - // Getting the body param - std::vector user; - +void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(user); - for (const auto& validationParam : user) - validationParam.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + std::vector user; + + + + try { + nlohmann::json::parse(request.body()).get_to(user); + for (const auto& validationParam : user) + validationParam.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->create_users_with_array_input(user, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { - - // Getting the body param - std::vector user; - +void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(user); - for (const auto& validationParam : user) - validationParam.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + std::vector user; + + + + try { + nlohmann::json::parse(request.body()).get_to(user); + for (const auto& validationParam : user) + validationParam.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->create_users_with_list_input(user, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void UserApi::delete_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto username = request.param(":username").as(); + // Getting the path params + auto username = request.param(":username").as(); + + - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->delete_user(username, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void UserApi::get_user_by_name_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto username = request.param(":username").as(); + // Getting the path params + auto username = request.param(":username").as(); + + - try { + try { - - - this->get_user_by_name(username, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->get_user_by_name(username, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { +void UserApi::login_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { + try { - // Getting the query params - auto usernameQuery = request.query().get("username"); - std::optional username; - if(usernameQuery.has_value()){ - std::string valueQuery_instance; - if(fromStringValue(usernameQuery.value(), valueQuery_instance)){ - username = valueQuery_instance; + + + // Getting the query params + auto usernameQuery = request.query().get("username"); + std::optional username; + if (usernameQuery.has_value()) { + std::string valueQuery_instance; + if (fromStringValue(usernameQuery.value(), valueQuery_instance)) { + username = valueQuery_instance; + } } - } - auto passwordQuery = request.query().get("password"); - std::optional password; - if(passwordQuery.has_value()){ - std::string valueQuery_instance; - if(fromStringValue(passwordQuery.value(), valueQuery_instance)){ - password = valueQuery_instance; + auto passwordQuery = request.query().get("password"); + std::optional password; + if (passwordQuery.has_value()) { + std::string valueQuery_instance; + if (fromStringValue(passwordQuery.value(), valueQuery_instance)) { + password = valueQuery_instance; + } } - } - try { + try { - - - this->login_user(username, password, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->login_user(username, password, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { + +void UserApi::logout_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { + + + - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->logout_user(response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { - // Getting the path params - auto username = request.param(":username").as(); - - // Getting the body param - - User user; - +void UserApi::update_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(user); - user.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + // Getting the path params + auto username = request.param(":username").as(); + + // Getting the body param + + User user; + + + + + try { + nlohmann::json::parse(request.body()).get_to(user); + user.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->update_user(username, user, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp b/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp index fca6ee95568e..d3ed60c323bb 100644 --- a/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache-everything/impl/PetApiImpl.cpp @@ -47,10 +47,10 @@ void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWri void PetApiImpl::update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){ +void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){ +void PetApiImpl::upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp index 5244017f94a6..9371c2fe5708 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/ApiBase.cpp @@ -19,5 +19,4 @@ ApiBase::ApiBase(const std::shared_ptr& rtr) : router(rt } - } // Namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp index 0fc2664f6d83..d23f51da8fd2 100644 --- a/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-pistache-nested-schema-refs/api/StoreApi.cpp @@ -38,14 +38,12 @@ void StoreApi::setupRoutes() { router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this)); } -void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair StoreApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair StoreApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -57,49 +55,46 @@ std::pair StoreApi::handleParsingException(co } } -void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair StoreApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair StoreApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void StoreApi::get_nested_object_handler(const Pistache::Rest::Request &, Pistache::Http::ResponseWriter response) { +void StoreApi::get_nested_object_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { + + + - try { + try { - - - this->get_nested_object(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->get_nested_object(response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache/api/ApiBase.cpp b/samples/server/petstore/cpp-pistache/api/ApiBase.cpp index 673f738df944..ae7fa32612d6 100644 --- a/samples/server/petstore/cpp-pistache/api/ApiBase.cpp +++ b/samples/server/petstore/cpp-pistache/api/ApiBase.cpp @@ -19,5 +19,4 @@ ApiBase::ApiBase(const std::shared_ptr& rtr) : router(rt } - } // Namespace org::openapitools::server::api diff --git a/samples/server/petstore/cpp-pistache/api/PetApi.cpp b/samples/server/petstore/cpp-pistache/api/PetApi.cpp index 74b40893278f..052ec8c4da09 100644 --- a/samples/server/petstore/cpp-pistache/api/PetApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/PetApi.cpp @@ -45,14 +45,12 @@ void PetApi::setupRoutes() { router->addCustomHandler(Routes::bind(&PetApi::pet_api_default_handler, this)); } -void PetApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void PetApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair PetApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair PetApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -64,393 +62,440 @@ std::pair PetApi::handleParsingException(cons } } -void PetApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void PetApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair PetApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair PetApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { +void PetApi::add_pet_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - - // Getting the body param - - Pet body; + + // Getting the body param + + Pet body; + + + - try { - nlohmann::json::parse(request.body()).get_to(body); - body.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - - try { + try { + nlohmann::json::parse(request.body()).get_to(body); + body.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->add_pet(body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void PetApi::delete_pet_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto petId = request.param(":petId").as(); + // Getting the path params + auto petId = request.param(":petId").as(); + + - // Getting the header params - auto apiKey = request.headers().tryGetRaw("api_key"); + // Getting the header params + auto apiKey = request.headers().tryGetRaw("api_key"); - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->delete_pet(petId, apiKey, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { + try { - // Getting the query params - auto statusQuery = request.query().get("status"); - std::optional> status; - if(statusQuery.has_value()){ - std::vector valueQuery_instance; - if(fromStringValue(statusQuery.value(), valueQuery_instance)){ - status = valueQuery_instance; + + + // Getting the query params + auto statusQuery = request.query().get("status"); + std::optional> status; + if (statusQuery.has_value()) { + std::vector valueQuery_instance; + if (fromStringValue(statusQuery.value(), valueQuery_instance)) { + status = valueQuery_instance; + } } - } - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->find_pets_by_status(status, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { + try { - // Getting the query params - auto tagsQuery = request.query().get("tags"); - std::optional> tags; - if(tagsQuery.has_value()){ - std::vector valueQuery_instance; - if(fromStringValue(tagsQuery.value(), valueQuery_instance)){ - tags = valueQuery_instance; + + + // Getting the query params + auto tagsQuery = request.query().get("tags"); + std::optional> tags; + if (tagsQuery.has_value()) { + std::vector valueQuery_instance; + if (fromStringValue(tagsQuery.value(), valueQuery_instance)) { + tags = valueQuery_instance; + } } - } - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->find_pets_by_tags(tags, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void PetApi::get_pet_by_id_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto petId = request.param(":petId").as(); + // Getting the path params + auto petId = request.param(":petId").as(); + + - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->get_pet_by_id(petId, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { - - // Getting the body param - - Pet body; - +void PetApi::update_pet_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(body); - body.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + + Pet body; + + + + + try { + nlohmann::json::parse(request.body()).get_to(body); + body.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->update_pet(body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::update_pet_with_form_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - this->update_pet_with_form(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + try { + this->update_pet_with_form(request, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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 { +void PetApi::upload_file_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - this->upload_file(request, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + try { + this->upload_file(request, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache/api/StoreApi.cpp b/samples/server/petstore/cpp-pistache/api/StoreApi.cpp index 870a79116194..235a82d50e87 100644 --- a/samples/server/petstore/cpp-pistache/api/StoreApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/StoreApi.cpp @@ -41,14 +41,12 @@ void StoreApi::setupRoutes() { router->addCustomHandler(Routes::bind(&StoreApi::store_api_default_handler, this)); } -void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void StoreApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair StoreApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair StoreApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -60,172 +58,173 @@ std::pair StoreApi::handleParsingException(co } } -void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void StoreApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair StoreApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair StoreApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void StoreApi::delete_order_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { +void StoreApi::delete_order_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto orderId = request.param(":orderId").as(); + // Getting the path params + auto orderId = request.param(":orderId").as(); + + - try { + try { - - - this->delete_order(orderId, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->delete_order(orderId, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { + +void StoreApi::get_inventory_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { + + + - try { - #ifndef HTTP_BASIC_AUTH_DEFINED - #define HTTP_BASIC_AUTH_DEFINED 0 - #endif - #ifndef HTTP_BEARER_AUTH_DEFINED - #define HTTP_BEARER_AUTH_DEFINED 0 - #endif + try { +#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(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->get_inventory(response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { response.send(Pistache::Http::Code::Internal_Server_Error, e.what()); } +#ifndef HTTP_BASIC_AUTH_DEFINED +#define HTTP_BASIC_AUTH_DEFINED 0 +#endif +#ifndef HTTP_BEARER_AUTH_DEFINED +#define HTTP_BEARER_AUTH_DEFINED 0 +#endif #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." ); + 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 +#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) { + +void StoreApi::get_order_by_id_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto orderId = request.param(":orderId").as(); + // Getting the path params + auto orderId = request.param(":orderId").as(); + + - try { + try { - - - this->get_order_by_id(orderId, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->get_order_by_id(orderId, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { - - // Getting the body param - - Order body; - +void StoreApi::place_order_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(body); - body.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + + Order body; + + + + + try { + nlohmann::json::parse(request.body()).get_to(body); + body.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + try { - - - this->place_order(body, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->place_order(body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache/api/UserApi.cpp b/samples/server/petstore/cpp-pistache/api/UserApi.cpp index 3bdeea152f9d..512aee94e606 100644 --- a/samples/server/petstore/cpp-pistache/api/UserApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/UserApi.cpp @@ -45,14 +45,12 @@ void UserApi::setupRoutes() { router->addCustomHandler(Routes::bind(&UserApi::user_api_default_handler, this)); } -void UserApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void UserApi::handleParsingException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleParsingException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair UserApi::handleParsingException(const std::exception& ex) const noexcept -{ +std::pair UserApi::handleParsingException(const std::exception& ex) const noexcept { try { throw; } catch (nlohmann::detail::exception &e) { @@ -64,342 +62,325 @@ std::pair UserApi::handleParsingException(con } } -void UserApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept -{ +void UserApi::handleOperationException(const std::exception& ex, Pistache::Http::ResponseWriter &response) const noexcept { std::pair codeAndError = handleOperationException(ex); response.send(codeAndError.first, codeAndError.second); } -std::pair UserApi::handleOperationException(const std::exception& ex) const noexcept -{ +std::pair UserApi::handleOperationException(const std::exception& ex) const noexcept { return std::make_pair(Pistache::Http::Code::Internal_Server_Error, ex.what()); } -void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) { +void UserApi::create_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - - // Getting the body param - - User body; + + // Getting the body param + + User body; + + + - try { - nlohmann::json::parse(request.body()).get_to(body); - body.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - - try { + try { + nlohmann::json::parse(request.body()).get_to(body); + body.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + try { - - - this->create_user(body, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->create_user(body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { - - // Getting the body param - std::vector body; - +void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(body); - for (const auto& validationParam : body) - validationParam.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + std::vector body; + + + + try { + nlohmann::json::parse(request.body()).get_to(body); + for (const auto& validationParam : body) + validationParam.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + try { - - - this->create_users_with_array_input(body, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->create_users_with_array_input(body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { - - // Getting the body param - std::vector body; - +void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(body); - for (const auto& validationParam : body) - validationParam.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + + // Getting the body param + std::vector body; + + + + try { + nlohmann::json::parse(request.body()).get_to(body); + for (const auto& validationParam : body) + validationParam.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + try { - - - this->create_users_with_list_input(body, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->create_users_with_list_input(body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { + +void UserApi::delete_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto username = request.param(":username").as(); + // Getting the path params + auto username = request.param(":username").as(); + + - try { + try { - - - this->delete_user(username, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->delete_user(username, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { + +void UserApi::get_user_by_name_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - // Getting the path params - auto username = request.param(":username").as(); + // Getting the path params + auto username = request.param(":username").as(); + + - try { + try { - - - this->get_user_by_name(username, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->get_user_by_name(username, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { +void UserApi::login_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { + try { - // Getting the query params - auto usernameQuery = request.query().get("username"); - std::optional username; - if(usernameQuery.has_value()){ - std::string valueQuery_instance; - if(fromStringValue(usernameQuery.value(), valueQuery_instance)){ - username = valueQuery_instance; + + + // Getting the query params + auto usernameQuery = request.query().get("username"); + std::optional username; + if (usernameQuery.has_value()) { + std::string valueQuery_instance; + if (fromStringValue(usernameQuery.value(), valueQuery_instance)) { + username = valueQuery_instance; + } } - } - auto passwordQuery = request.query().get("password"); - std::optional password; - if(passwordQuery.has_value()){ - std::string valueQuery_instance; - if(fromStringValue(passwordQuery.value(), valueQuery_instance)){ - password = valueQuery_instance; + auto passwordQuery = request.query().get("password"); + std::optional password; + if (passwordQuery.has_value()) { + std::string valueQuery_instance; + if (fromStringValue(passwordQuery.value(), valueQuery_instance)) { + password = valueQuery_instance; + } } - } - try { + try { - - - this->login_user(username, password, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + + this->login_user(username, password, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { + +void UserApi::logout_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { + + + - try { + try { - - - this->logout_user(response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->logout_user(response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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 { - // Getting the path params - auto username = request.param(":username").as(); - - // Getting the body param - - User body; - +void UserApi::update_user_handler(const Pistache::Rest::Request& request, Pistache::Http::ResponseWriter response) { try { - nlohmann::json::parse(request.body()).get_to(body); - body.validate(); - } catch (std::exception &e) { - this->handleParsingException(e, response); - return; - } - try { + // Getting the path params + auto username = request.param(":username").as(); + + // Getting the body param + + User body; + + + + + try { + nlohmann::json::parse(request.body()).get_to(body); + body.validate(); + } catch (std::exception& e) { + this->handleParsingException(e, response); + return; + } + try { - - - this->update_user(username, body, response); - } catch (Pistache::Http::HttpError &e) { - response.send(static_cast(e.code()), e.what()); - return; - } catch (std::exception &e) { - this->handleOperationException(e, response); - return; - } + this->update_user(username, body, response); + } catch (Pistache::Http::HttpError &e) { + response.send(static_cast(e.code()), e.what()); + return; + } catch (std::exception &e) { + this->handleOperationException(e, response); + return; + } } catch (std::exception &e) { 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) { response.send(Pistache::Http::Code::Not_Found, "The requested method does not exist"); } diff --git a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp index a33aa5db630a..480de06778ba 100644 --- a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp @@ -47,10 +47,10 @@ void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWri void PetApiImpl::update_pet(const Pet &body, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){ +void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){ +void PetApiImpl::upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); }