diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerConfiguration.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerConfiguration.mustache index d4bd3526316e..7c2beff520b7 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerConfiguration.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerConfiguration.mustache @@ -17,14 +17,14 @@ namespace {{this}} { class {{prefix}}ServerConfiguration { public: /** - * @param URL A URL to the target host. + * @param url A URL to the target host. * @param description A description of the host designated by the URL. * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. */ - {{prefix}}ServerConfiguration(const QString& URL, const QString& description, const QMap& variables) + {{prefix}}ServerConfiguration(const QUrl &url, const QString &description, const QMap &variables) : _description(description), _variables(variables), - _URL(URL){} + _url(url){} {{prefix}}ServerConfiguration(){} ~{{prefix}}ServerConfiguration(){} @@ -35,7 +35,7 @@ public: * @return Formatted URL. */ QString URL() { - QString url = _URL; + QString url = _url.toString(); if(!_variables.empty()){ // go through variables and replace placeholders for (auto const& v : _variables.keys()) { @@ -55,7 +55,7 @@ public: return url; } - int setDefaultValue(const QString& variable,const QString& value){ + int setDefaultValue(const QString &variable,const QString &value){ if(_variables.contains(variable)) return _variables[variable].setDefaultValue(value); return -1; @@ -63,7 +63,7 @@ public: QString _description; QMap _variables; - QString _URL; + QUrl _url; }; diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache index 42c30bfba386..c1b3705fb3cd 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache @@ -9,12 +9,8 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} -{{classname}}::{{classname}}(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut) - : _scheme(scheme), - _host(host), - _port(port), - _basePath(basePath), - _timeOut(timeOut), +{{classname}}::{{classname}}(const int timeOut) + : _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), isRequestCompressionEnabled(false) { @@ -32,7 +28,7 @@ QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfigu QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>(); {{#vendorExtensions.x-cpp-global-server-list}} defaultConf.append({{prefix}}ServerConfiguration( - "{{{url}}}", + QUrl("{{{url}}}"), "{{{description}}}{{^description}}No description provided{{/description}}", {{#variables}}{{#-first}}QMap{ {{/-first}} {"{{{name}}}", {{prefix}}ServerVariable("{{{description}}}{{^description}}No description provided{{/description}}","{{{defaultValue}}}", @@ -48,7 +44,7 @@ _serverIndices.insert("{{nickname}}",0); {{/servers}} {{#servers}} serverConf.append({{prefix}}ServerConfiguration( - "{{{url}}}", + QUrl("{{{url}}}"), "{{{description}}}{{^description}}No description provided{{/description}}", {{#variables}}{{#-first}}QMap{ {{/-first}} {"{{{name}}}", {{prefix}}ServerVariable("{{{description}}}{{^description}}No description provided{{/description}}","{{{defaultValue}}}", @@ -79,18 +75,6 @@ void {{classname}}::setServerIndex(const QString &operation, int serverIndex){ _serverIndices[operation] = serverIndex; } -void {{classname}}::setScheme(const QString &scheme) { - _scheme = scheme; -} - -void {{classname}}::setHost(const QString &host) { - _host = host; -} - -void {{classname}}::setPort(int port) { - _port = port; -} - void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } @@ -107,9 +91,6 @@ void {{classname}}::setPassword(const QString &password) { _password = password; } -void {{classname}}::setBasePath(const QString &basePath) { - _basePath = basePath; -} void {{classname}}::setTimeOut(const int timeOut) { _timeOut = timeOut; @@ -123,6 +104,49 @@ void {{classname}}::setNetworkAccessManager(QNetworkAccessManager* manager) { _manager = manager; } + /** + * Appends a new ServerConfiguration to the config map for a specific operation. + * @param operation The id to the target operation. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + * returns the index of the new server config on success and -1 if the operation is not found + */ +int {{classname}}::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + if(_serverConfigs.contains(operation)){ + _serverConfigs[operation].append({{prefix}}ServerConfiguration( + url, + description, + variables)); + return _serverConfigs[operation].size()-1; + }else{ + return -1; + } +} + + /** + * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void {{classname}}::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables){ + for(auto e : _serverIndices.keys()){ + setServerIndex(e, addServerConfiguration(e, url, description, variables)); + } +} + /** + * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. + * @param URL A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void {{classname}}::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + + setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); + +} + void {{classname}}::addHeaders(const QString &key, const QString &value) { defaultHeaders.insert(key, value); } diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache index 86e099dfe8b7..11ba25f2adc2 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache @@ -22,23 +22,22 @@ class {{classname}} : public QObject { Q_OBJECT public: - {{classname}}(const QString &scheme = "{{scheme}}", const QString &host = "{{serverHost}}", int port = {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}0{{/serverPort}}, const QString &basePath = "{{basePathWithoutHost}}", const int timeOut = 0); + {{classname}}(const int timeOut = 0); ~{{classname}}(); void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); - void setScheme(const QString &scheme); - void setHost(const QString &host); - void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); - void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); void setNetworkAccessManager(QNetworkAccessManager* manager); + int addServerConfiguration(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); void addHeaders(const QString &key, const QString &value); void enableRequestCompression(); void enableResponseCompression(); @@ -50,9 +49,6 @@ public: {{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});{{/operation}}{{/operations}} private: - QString _scheme, _host; - int _port; - QString _basePath; QMap _serverIndices; QMap> _serverConfigs; QMap _apiKeys; diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index fa389e1c4dda..0935f41cfcec 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -17,12 +17,8 @@ namespace test_namespace { -PFXPetApi::PFXPetApi(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut) - : _scheme(scheme), - _host(host), - _port(port), - _basePath(basePath), - _timeOut(timeOut), +PFXPetApi::PFXPetApi(const int timeOut) + : _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), isRequestCompressionEnabled(false) { @@ -39,7 +35,7 @@ QList defaultConf = QList(); //varying endpoint server QList serverConf = QList(); defaultConf.append(PFXServerConfiguration( - "http://petstore.swagger.io/v2", + QUrl("http://petstore.swagger.io/v2"), "No description provided", QMap())); _serverConfigs.insert("addPet",defaultConf); @@ -85,18 +81,6 @@ void PFXPetApi::setServerIndex(const QString &operation, int serverIndex){ _serverIndices[operation] = serverIndex; } -void PFXPetApi::setScheme(const QString &scheme) { - _scheme = scheme; -} - -void PFXPetApi::setHost(const QString &host) { - _host = host; -} - -void PFXPetApi::setPort(int port) { - _port = port; -} - void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } @@ -113,9 +97,6 @@ void PFXPetApi::setPassword(const QString &password) { _password = password; } -void PFXPetApi::setBasePath(const QString &basePath) { - _basePath = basePath; -} void PFXPetApi::setTimeOut(const int timeOut) { _timeOut = timeOut; @@ -129,6 +110,49 @@ void PFXPetApi::setNetworkAccessManager(QNetworkAccessManager* manager) { _manager = manager; } + /** + * Appends a new ServerConfiguration to the config map for a specific operation. + * @param operation The id to the target operation. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + * returns the index of the new server config on success and -1 if the operation is not found + */ +int PFXPetApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + if(_serverConfigs.contains(operation)){ + _serverConfigs[operation].append(PFXServerConfiguration( + url, + description, + variables)); + return _serverConfigs[operation].size()-1; + }else{ + return -1; + } +} + + /** + * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXPetApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables){ + for(auto e : _serverIndices.keys()){ + setServerIndex(e, addServerConfiguration(e, url, description, variables)); + } +} + /** + * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. + * @param URL A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXPetApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + + setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); + +} + void PFXPetApi::addHeaders(const QString &key, const QString &value) { defaultHeaders.insert(key, value); } diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index d50826ff585d..5daa4b47fef3 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -32,23 +32,22 @@ class PFXPetApi : public QObject { Q_OBJECT public: - PFXPetApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString &basePath = "/v2", const int timeOut = 0); + PFXPetApi(const int timeOut = 0); ~PFXPetApi(); void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); - void setScheme(const QString &scheme); - void setHost(const QString &host); - void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); - void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); void setNetworkAccessManager(QNetworkAccessManager* manager); + int addServerConfiguration(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); void addHeaders(const QString &key, const QString &value); void enableRequestCompression(); void enableResponseCompression(); @@ -67,9 +66,6 @@ public: void uploadFile(const qint64 &pet_id, const QString &additional_metadata, const PFXHttpFileElement &file); private: - QString _scheme, _host; - int _port; - QString _basePath; QMap _serverIndices; QMap> _serverConfigs; QMap _apiKeys; diff --git a/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h b/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h index cc5273b8226e..72bd32a4f6ed 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h +++ b/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h @@ -25,14 +25,14 @@ namespace test_namespace { class PFXServerConfiguration { public: /** - * @param URL A URL to the target host. + * @param url A URL to the target host. * @param description A description of the host designated by the URL. * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. */ - PFXServerConfiguration(const QString& URL, const QString& description, const QMap& variables) + PFXServerConfiguration(const QUrl &url, const QString &description, const QMap &variables) : _description(description), _variables(variables), - _URL(URL){} + _url(url){} PFXServerConfiguration(){} ~PFXServerConfiguration(){} @@ -43,7 +43,7 @@ public: * @return Formatted URL. */ QString URL() { - QString url = _URL; + QString url = _url.toString(); if(!_variables.empty()){ // go through variables and replace placeholders for (auto const& v : _variables.keys()) { @@ -63,7 +63,7 @@ public: return url; } - int setDefaultValue(const QString& variable,const QString& value){ + int setDefaultValue(const QString &variable,const QString &value){ if(_variables.contains(variable)) return _variables[variable].setDefaultValue(value); return -1; @@ -71,7 +71,7 @@ public: QString _description; QMap _variables; - QString _URL; + QUrl _url; }; diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index 8be10eb33bb5..6f8cbecf42f2 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -17,12 +17,8 @@ namespace test_namespace { -PFXStoreApi::PFXStoreApi(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut) - : _scheme(scheme), - _host(host), - _port(port), - _basePath(basePath), - _timeOut(timeOut), +PFXStoreApi::PFXStoreApi(const int timeOut) + : _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), isRequestCompressionEnabled(false) { @@ -39,7 +35,7 @@ QList defaultConf = QList(); //varying endpoint server QList serverConf = QList(); defaultConf.append(PFXServerConfiguration( - "http://petstore.swagger.io/v2", + QUrl("http://petstore.swagger.io/v2"), "No description provided", QMap())); _serverConfigs.insert("deleteOrder",defaultConf); @@ -73,18 +69,6 @@ void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex){ _serverIndices[operation] = serverIndex; } -void PFXStoreApi::setScheme(const QString &scheme) { - _scheme = scheme; -} - -void PFXStoreApi::setHost(const QString &host) { - _host = host; -} - -void PFXStoreApi::setPort(int port) { - _port = port; -} - void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } @@ -101,9 +85,6 @@ void PFXStoreApi::setPassword(const QString &password) { _password = password; } -void PFXStoreApi::setBasePath(const QString &basePath) { - _basePath = basePath; -} void PFXStoreApi::setTimeOut(const int timeOut) { _timeOut = timeOut; @@ -117,6 +98,49 @@ void PFXStoreApi::setNetworkAccessManager(QNetworkAccessManager* manager) { _manager = manager; } + /** + * Appends a new ServerConfiguration to the config map for a specific operation. + * @param operation The id to the target operation. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + * returns the index of the new server config on success and -1 if the operation is not found + */ +int PFXStoreApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + if(_serverConfigs.contains(operation)){ + _serverConfigs[operation].append(PFXServerConfiguration( + url, + description, + variables)); + return _serverConfigs[operation].size()-1; + }else{ + return -1; + } +} + + /** + * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXStoreApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables){ + for(auto e : _serverIndices.keys()){ + setServerIndex(e, addServerConfiguration(e, url, description, variables)); + } +} + /** + * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. + * @param URL A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXStoreApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + + setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); + +} + void PFXStoreApi::addHeaders(const QString &key, const QString &value) { defaultHeaders.insert(key, value); } diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index 781dcb955ca8..f72bdec0efb3 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -31,23 +31,22 @@ class PFXStoreApi : public QObject { Q_OBJECT public: - PFXStoreApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString &basePath = "/v2", const int timeOut = 0); + PFXStoreApi(const int timeOut = 0); ~PFXStoreApi(); void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); - void setScheme(const QString &scheme); - void setHost(const QString &host); - void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); - void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); void setNetworkAccessManager(QNetworkAccessManager* manager); + int addServerConfiguration(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); void addHeaders(const QString &key, const QString &value); void enableRequestCompression(); void enableResponseCompression(); @@ -62,9 +61,6 @@ public: void placeOrder(const PFXOrder &body); private: - QString _scheme, _host; - int _port; - QString _basePath; QMap _serverIndices; QMap> _serverConfigs; QMap _apiKeys; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index ab8723212fda..2cc891dc413f 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -17,12 +17,8 @@ namespace test_namespace { -PFXUserApi::PFXUserApi(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut) - : _scheme(scheme), - _host(host), - _port(port), - _basePath(basePath), - _timeOut(timeOut), +PFXUserApi::PFXUserApi(const int timeOut) + : _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), isRequestCompressionEnabled(false) { @@ -39,7 +35,7 @@ QList defaultConf = QList(); //varying endpoint server QList serverConf = QList(); defaultConf.append(PFXServerConfiguration( - "http://petstore.swagger.io/v2", + QUrl("http://petstore.swagger.io/v2"), "No description provided", QMap())); _serverConfigs.insert("createUser",defaultConf); @@ -85,18 +81,6 @@ void PFXUserApi::setServerIndex(const QString &operation, int serverIndex){ _serverIndices[operation] = serverIndex; } -void PFXUserApi::setScheme(const QString &scheme) { - _scheme = scheme; -} - -void PFXUserApi::setHost(const QString &host) { - _host = host; -} - -void PFXUserApi::setPort(int port) { - _port = port; -} - void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } @@ -113,9 +97,6 @@ void PFXUserApi::setPassword(const QString &password) { _password = password; } -void PFXUserApi::setBasePath(const QString &basePath) { - _basePath = basePath; -} void PFXUserApi::setTimeOut(const int timeOut) { _timeOut = timeOut; @@ -129,6 +110,49 @@ void PFXUserApi::setNetworkAccessManager(QNetworkAccessManager* manager) { _manager = manager; } + /** + * Appends a new ServerConfiguration to the config map for a specific operation. + * @param operation The id to the target operation. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + * returns the index of the new server config on success and -1 if the operation is not found + */ +int PFXUserApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + if(_serverConfigs.contains(operation)){ + _serverConfigs[operation].append(PFXServerConfiguration( + url, + description, + variables)); + return _serverConfigs[operation].size()-1; + }else{ + return -1; + } +} + + /** + * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXUserApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables){ + for(auto e : _serverIndices.keys()){ + setServerIndex(e, addServerConfiguration(e, url, description, variables)); + } +} + /** + * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. + * @param URL A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXUserApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables){ + + setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); + +} + void PFXUserApi::addHeaders(const QString &key, const QString &value) { defaultHeaders.insert(key, value); } diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index f38b2ff74279..adba64db9f76 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -31,23 +31,22 @@ class PFXUserApi : public QObject { Q_OBJECT public: - PFXUserApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString &basePath = "/v2", const int timeOut = 0); + PFXUserApi(const int timeOut = 0); ~PFXUserApi(); void initializeServerConfigs(); int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); void setServerIndex(const QString &operation, int serverIndex); - void setScheme(const QString &scheme); - void setHost(const QString &host); - void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); - void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); void setNetworkAccessManager(QNetworkAccessManager* manager); + int addServerConfiguration(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); void addHeaders(const QString &key, const QString &value); void enableRequestCompression(); void enableResponseCompression(); @@ -66,9 +65,6 @@ public: void updateUser(const QString &username, const PFXUser &body); private: - QString _scheme, _host; - int _port; - QString _basePath; QMap _serverIndices; QMap> _serverConfigs; QMap _apiKeys;