From 7fec29eb258636e18fbc39cdbe647718e8de3472 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sun, 20 Oct 2024 11:13:08 +0200 Subject: [PATCH 1/7] [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 c9307f1f9cbe0a3632180b525837f46f20a81428 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sun, 20 Oct 2024 12:09:26 +0200 Subject: [PATCH 2/7] [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 d5e84f4f0e08aa0f363912e8d3898efaa96b3aa7 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Wed, 23 Oct 2024 11:21:00 +0200 Subject: [PATCH 3/7] [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 0006a6af0e57af9849497a1f93c7110e9709d41d Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Wed, 23 Oct 2024 12:13:36 +0200 Subject: [PATCH 4/7] [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 f6cc5d52afc73b92edeaa2d0702763cbe35bb77b Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Thu, 24 Oct 2024 11:14:11 +0200 Subject: [PATCH 5/7] [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 62f26adbb1400da5ead0e0d363af77a01f4c5cd6 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sat, 26 Oct 2024 08:08:42 +0200 Subject: [PATCH 6/7] [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 fe14ee6a86ca..5286f7d06ea9 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 @@ -175,6 +175,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 c896857e6ab7c860aaf4ac0dc612777661da5513 Mon Sep 17 00:00:00 2001 From: Morten Winkler Date: Sat, 26 Oct 2024 08:40:27 +0200 Subject: [PATCH 7/7] [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) {