Skip to content

Commit f4e8e20

Browse files
mowijoKRJ-RTX
authored andcommitted
[cpp][pistache-server] Change HTTP Basic credentials to be contained on a struct instead of two std::strings
1 parent 0302640 commit f4e8e20

5 files changed

Lines changed: 16 additions & 6 deletions

File tree

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-base-header.mustache

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
namespace {{apiNamespace}}
1515
{
1616
17+
18+
{{#authMethods}}{{#isBasicBasic}}
19+
struct HttpBasicCredentials
20+
{
21+
std::string userid;
22+
std::string password;
23+
};
24+
{{/isBasicBasic}}{{/authMethods}}
25+
26+
27+
1728
class ApiBase {
1829
public:
1930
explicit ApiBase(const std::shared_ptr<Pistache::Rest::Router>& rtr) : router(rtr) {};

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private:
7979
{{#allParams}}
8080
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
8181
{{/allParams}}
82-
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;
82+
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;
8383
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
8484
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
8585
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public:
3535

3636
{{#operation}}
3737
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
38-
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);
38+
void {{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response);
3939
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
4040
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
4141
void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-source.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace {{modelNamespace}};{{/hasModelImport}}
1717

1818
{{#operation}}
1919
{{#vendorExtensions.x-codegen-pistache-is-parsing-supported}}
20-
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) {
20+
void {{classname}}Impl::{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}const HttpBasicCredentials &credentials, {{/isBasicBasic}}{{/authMethods}}{{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) {
2121
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
2222
}
2323
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}

modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,14 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
130130
response.send(Pistache::Http::Code::Unauthorized, "");
131131
return;
132132
}
133-
const std::string username(basicAuthHeader->getBasicUser());
134-
const std::string password(basicAuthHeader->getBasicPassword());
133+
HttpBasicCredentials credentials{basicAuthHeader->getBasicUser(), basicAuthHeader->getBasicPassword()};
135134
{{/isBasicBasic}}{{/authMethods}}
136135

137136
{{#authMethods}}{{#isBasicBearer}}
138137
/* BASIC BEARER */
139138
{{/isBasicBearer}}{{/authMethods}}
140139

141-
this->{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}username, password,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response);
140+
this->{{operationIdSnakeCase}}({{#authMethods}}{{#isBasicBasic}}credentials,{{/isBasicBasic}}{{/authMethods}}{{#allParams}}{{paramName}}, {{/allParams}}response);
142141
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
143142
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
144143
try {

0 commit comments

Comments
 (0)