From 4fb3dd896f86288fe20d3caa7400b237090b3710 Mon Sep 17 00:00:00 2001 From: Martin Delille Date: Wed, 21 Jan 2026 18:33:09 +0100 Subject: [PATCH] [cpp=qt] Add global server index setter for all operations --- .../src/main/resources/cpp-qt-client/README.mustache | 7 +++++++ .../src/main/resources/cpp-qt-client/api-body.mustache | 6 ++++++ .../src/main/resources/cpp-qt-client/api-header.mustache | 1 + .../client/petstore/cpp-qt-addDownloadProgress/README.md | 7 +++++++ .../cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp | 6 ++++++ .../cpp-qt-addDownloadProgress/client/PFXFakeApi.h | 1 + .../cpp-qt-addDownloadProgress/client/PFXPetApi.cpp | 6 ++++++ .../petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h | 1 + .../cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.cpp | 6 ++++++ .../cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h | 1 + .../cpp-qt-addDownloadProgress/client/PFXStoreApi.cpp | 6 ++++++ .../cpp-qt-addDownloadProgress/client/PFXStoreApi.h | 1 + .../cpp-qt-addDownloadProgress/client/PFXUserApi.cpp | 6 ++++++ .../cpp-qt-addDownloadProgress/client/PFXUserApi.h | 1 + samples/client/petstore/cpp-qt/README.md | 7 +++++++ samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp | 6 ++++++ samples/client/petstore/cpp-qt/client/PFXFakeApi.h | 1 + samples/client/petstore/cpp-qt/client/PFXPetApi.cpp | 6 ++++++ samples/client/petstore/cpp-qt/client/PFXPetApi.h | 1 + samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.cpp | 6 ++++++ samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h | 1 + samples/client/petstore/cpp-qt/client/PFXStoreApi.cpp | 6 ++++++ samples/client/petstore/cpp-qt/client/PFXStoreApi.h | 1 + samples/client/petstore/cpp-qt/client/PFXUserApi.cpp | 6 ++++++ samples/client/petstore/cpp-qt/client/PFXUserApi.h | 1 + 25 files changed, 98 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/README.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/README.mustache index 57275a57e868..7ce175c627b8 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/README.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/README.mustache @@ -133,6 +133,13 @@ If your endpoint has multiple server objects in the servers array, you can set t void setServerIndex(const QString &operation, int serverIndex); ``` Parameter "operation" should be your operationid. "serverIndex" is the index you want to set as your default server. The function will check if there is a server with your index. + +Alternatively, to set the server index globally for all operations: +```c++ +void setServerIndex(int serverIndex); +``` +This will apply the specified server index to all operations in the API. + Here is an example of multiple servers in the servers array. The first server will have index 0 and the second will have index 1. ```yaml servers: diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache index 2a51b5f1d87a..912067239baa 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache @@ -73,6 +73,12 @@ void {{classname}}::setServerIndex(const QString &operation, int serverIndex) { } } +void {{classname}}::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache index c23076286fbc..888589643701 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache @@ -30,6 +30,7 @@ public: void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/README.md b/samples/client/petstore/cpp-qt-addDownloadProgress/README.md index 07519e2c8e5b..3d404afb9e88 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/README.md +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/README.md @@ -123,6 +123,13 @@ If your endpoint has multiple server objects in the servers array, you can set t void setServerIndex(const QString &operation, int serverIndex); ``` Parameter "operation" should be your operationid. "serverIndex" is the index you want to set as your default server. The function will check if there is a server with your index. + +Alternatively, to set the server index globally for all operations: +```c++ +void setServerIndex(int serverIndex); +``` +This will apply the specified server index to all operations in the API. + Here is an example of multiple servers in the servers array. The first server will have index 0 and the second will have index 1. ```yaml servers: diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp index 41b2f6793212..da0ba60726de 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp @@ -60,6 +60,12 @@ void PFXFakeApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXFakeApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXFakeApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h index 51bb33fc716d..cba16795183b 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h @@ -38,6 +38,7 @@ class PFXFakeApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.cpp index 071d160a6968..a0683b0d9da1 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.cpp @@ -76,6 +76,12 @@ void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXPetApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h index 5d69d20d8726..265237f4e555 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h @@ -41,6 +41,7 @@ class PFXPetApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.cpp index ac9b0d4a41d5..bb9458e59c70 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.cpp +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.cpp @@ -62,6 +62,12 @@ void PFXPrimitivesApi::setServerIndex(const QString &operation, int serverIndex) } } +void PFXPrimitivesApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXPrimitivesApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h index f3a447e2d94c..b13e83173984 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h @@ -37,6 +37,7 @@ class PFXPrimitivesApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.cpp index eddb89813c2d..7c99d1f36ce2 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.cpp @@ -66,6 +66,12 @@ void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXStoreApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h index a9998a0e55c6..c46b31250a15 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXStoreApi.h @@ -39,6 +39,7 @@ class PFXStoreApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.cpp index b0cb7f651048..fe8bf4549493 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.cpp @@ -81,6 +81,12 @@ void PFXUserApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXUserApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h index 39821909a15c..cce2728f3114 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXUserApi.h @@ -38,6 +38,7 @@ class PFXUserApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt/README.md b/samples/client/petstore/cpp-qt/README.md index 07519e2c8e5b..3d404afb9e88 100644 --- a/samples/client/petstore/cpp-qt/README.md +++ b/samples/client/petstore/cpp-qt/README.md @@ -123,6 +123,13 @@ If your endpoint has multiple server objects in the servers array, you can set t void setServerIndex(const QString &operation, int serverIndex); ``` Parameter "operation" should be your operationid. "serverIndex" is the index you want to set as your default server. The function will check if there is a server with your index. + +Alternatively, to set the server index globally for all operations: +```c++ +void setServerIndex(int serverIndex); +``` +This will apply the specified server index to all operations in the API. + Here is an example of multiple servers in the servers array. The first server will have index 0 and the second will have index 1. ```yaml servers: diff --git a/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp b/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp index e31b35d4b66c..607463f8816b 100644 --- a/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp @@ -60,6 +60,12 @@ void PFXFakeApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXFakeApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXFakeApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt/client/PFXFakeApi.h b/samples/client/petstore/cpp-qt/client/PFXFakeApi.h index 0b4e100065ad..f81543a99463 100644 --- a/samples/client/petstore/cpp-qt/client/PFXFakeApi.h +++ b/samples/client/petstore/cpp-qt/client/PFXFakeApi.h @@ -38,6 +38,7 @@ class PFXFakeApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp index ff602c656f85..90d6545c00e4 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp @@ -76,6 +76,12 @@ void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXPetApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt/client/PFXPetApi.h b/samples/client/petstore/cpp-qt/client/PFXPetApi.h index 4e86ad47e1fa..be4917756d21 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt/client/PFXPetApi.h @@ -41,6 +41,7 @@ class PFXPetApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.cpp b/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.cpp index ab48ad857817..40fc23277c29 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.cpp @@ -62,6 +62,12 @@ void PFXPrimitivesApi::setServerIndex(const QString &operation, int serverIndex) } } +void PFXPrimitivesApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXPrimitivesApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h b/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h index 00851c1f27ef..a5bdfeeabb1e 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h +++ b/samples/client/petstore/cpp-qt/client/PFXPrimitivesApi.h @@ -37,6 +37,7 @@ class PFXPrimitivesApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt/client/PFXStoreApi.cpp index db8ad6b0de70..1e03e475b84d 100644 --- a/samples/client/petstore/cpp-qt/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXStoreApi.cpp @@ -66,6 +66,12 @@ void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXStoreApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt/client/PFXStoreApi.h index d401bdfa337c..d16fbe9502d5 100644 --- a/samples/client/petstore/cpp-qt/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt/client/PFXStoreApi.h @@ -39,6 +39,7 @@ class PFXStoreApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); diff --git a/samples/client/petstore/cpp-qt/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt/client/PFXUserApi.cpp index 78e53081fdee..276d770579b4 100644 --- a/samples/client/petstore/cpp-qt/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXUserApi.cpp @@ -81,6 +81,12 @@ void PFXUserApi::setServerIndex(const QString &operation, int serverIndex) { } } +void PFXUserApi::setServerIndex(int serverIndex) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, serverIndex); + } +} + void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { _apiKeys.insert(apiKeyName, apiKey); } diff --git a/samples/client/petstore/cpp-qt/client/PFXUserApi.h b/samples/client/petstore/cpp-qt/client/PFXUserApi.h index 3344f95783ac..15bc9510433f 100644 --- a/samples/client/petstore/cpp-qt/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt/client/PFXUserApi.h @@ -38,6 +38,7 @@ class PFXUserApi : public QObject { void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); + void setServerIndex(int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username);