Skip to content

Commit a1c948d

Browse files
[cpp=qt] Add global server index setter for all operations (#22760)
1 parent bf5ced7 commit a1c948d

File tree

25 files changed

+98
-0
lines changed

25 files changed

+98
-0
lines changed

modules/openapi-generator/src/main/resources/cpp-qt-client/README.mustache

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ If your endpoint has multiple server objects in the servers array, you can set t
133133
void setServerIndex(const QString &operation, int serverIndex);
134134
```
135135
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.
136+
137+
Alternatively, to set the server index globally for all operations:
138+
```c++
139+
void setServerIndex(int serverIndex);
140+
```
141+
This will apply the specified server index to all operations in the API.
142+
136143
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.
137144
```yaml
138145
servers:

modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ void {{classname}}::setServerIndex(const QString &operation, int serverIndex) {
7373
}
7474
}
7575

76+
void {{classname}}::setServerIndex(int serverIndex) {
77+
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
78+
setServerIndex(*keyIt, serverIndex);
79+
}
80+
}
81+
7682
void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey) {
7783
_apiKeys.insert(apiKeyName, apiKey);
7884
}

modules/openapi-generator/src/main/resources/cpp-qt-client/api-header.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public:
3030
void initializeServerConfigs();
3131
int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val);
3232
void setServerIndex(const QString &operation, int serverIndex);
33+
void setServerIndex(int serverIndex);
3334
void setApiKey(const QString &apiKeyName, const QString &apiKey);
3435
void setBearerToken(const QString &token);
3536
void setUsername(const QString &username);

samples/client/petstore/cpp-qt-addDownloadProgress/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ If your endpoint has multiple server objects in the servers array, you can set t
123123
void setServerIndex(const QString &operation, int serverIndex);
124124
```
125125
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.
126+
127+
Alternatively, to set the server index globally for all operations:
128+
```c++
129+
void setServerIndex(int serverIndex);
130+
```
131+
This will apply the specified server index to all operations in the API.
132+
126133
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.
127134
```yaml
128135
servers:

samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ void PFXFakeApi::setServerIndex(const QString &operation, int serverIndex) {
6060
}
6161
}
6262

63+
void PFXFakeApi::setServerIndex(int serverIndex) {
64+
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
65+
setServerIndex(*keyIt, serverIndex);
66+
}
67+
}
68+
6369
void PFXFakeApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
6470
_apiKeys.insert(apiKeyName, apiKey);
6571
}

samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class PFXFakeApi : public QObject {
3838
void initializeServerConfigs();
3939
int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val);
4040
void setServerIndex(const QString &operation, int serverIndex);
41+
void setServerIndex(int serverIndex);
4142
void setApiKey(const QString &apiKeyName, const QString &apiKey);
4243
void setBearerToken(const QString &token);
4344
void setUsername(const QString &username);

samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) {
7676
}
7777
}
7878

79+
void PFXPetApi::setServerIndex(int serverIndex) {
80+
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
81+
setServerIndex(*keyIt, serverIndex);
82+
}
83+
}
84+
7985
void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
8086
_apiKeys.insert(apiKeyName, apiKey);
8187
}

samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPetApi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class PFXPetApi : public QObject {
4141
void initializeServerConfigs();
4242
int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val);
4343
void setServerIndex(const QString &operation, int serverIndex);
44+
void setServerIndex(int serverIndex);
4445
void setApiKey(const QString &apiKeyName, const QString &apiKey);
4546
void setBearerToken(const QString &token);
4647
void setUsername(const QString &username);

samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ void PFXPrimitivesApi::setServerIndex(const QString &operation, int serverIndex)
6262
}
6363
}
6464

65+
void PFXPrimitivesApi::setServerIndex(int serverIndex) {
66+
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
67+
setServerIndex(*keyIt, serverIndex);
68+
}
69+
}
70+
6571
void PFXPrimitivesApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
6672
_apiKeys.insert(apiKeyName, apiKey);
6773
}

samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXPrimitivesApi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class PFXPrimitivesApi : public QObject {
3737
void initializeServerConfigs();
3838
int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val);
3939
void setServerIndex(const QString &operation, int serverIndex);
40+
void setServerIndex(int serverIndex);
4041
void setApiKey(const QString &apiKeyName, const QString &apiKey);
4142
void setBearerToken(const QString &token);
4243
void setUsername(const QString &username);

0 commit comments

Comments
 (0)