forked from loafle/openapi-generator-original
[C++][Qt5] Added function to add a new Server. Removed unused variables (#8725)
* cleanup unused variables,added addServerConfiguration() function * added setNewServer functions * using QUrl instead of QString
This commit is contained in:
@@ -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<QString, {{prefix}}ServerVariable>& variables)
|
||||
{{prefix}}ServerConfiguration(const QUrl &url, const QString &description, const QMap<QString, {{prefix}}ServerVariable> &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<QString, {{prefix}}ServerVariable> _variables;
|
||||
QString _URL;
|
||||
QUrl _url;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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<QString, {{prefix}}ServerVariable>{ {{/-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<QString, {{prefix}}ServerVariable>{ {{/-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<QString, {{prefix}}ServerVariable> &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<QString, {{prefix}}ServerVariable> &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<QString, {{prefix}}ServerVariable> &variables){
|
||||
|
||||
setServerIndex(operation, addServerConfiguration(operation, url, description, variables));
|
||||
|
||||
}
|
||||
|
||||
void {{classname}}::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
@@ -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<QString, {{prefix}}ServerVariable> &variables = QMap<QString, {{prefix}}ServerVariable>());
|
||||
void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap<QString, {{prefix}}ServerVariable> &variables = QMap<QString, {{prefix}}ServerVariable>());
|
||||
void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap<QString, {{prefix}}ServerVariable> &variables = QMap<QString, {{prefix}}ServerVariable>());
|
||||
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<QString,int> _serverIndices;
|
||||
QMap<QString,QList<{{prefix}}ServerConfiguration>> _serverConfigs;
|
||||
QMap<QString, QString> _apiKeys;
|
||||
|
||||
@@ -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<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||
//varying endpoint server
|
||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
||||
defaultConf.append(PFXServerConfiguration(
|
||||
"http://petstore.swagger.io/v2",
|
||||
QUrl("http://petstore.swagger.io/v2"),
|
||||
"No description provided",
|
||||
QMap<QString, PFXServerVariable>()));
|
||||
_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<QString, PFXServerVariable> &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<QString, PFXServerVariable> &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<QString, PFXServerVariable> &variables){
|
||||
|
||||
setServerIndex(operation, addServerConfiguration(operation, url, description, variables));
|
||||
|
||||
}
|
||||
|
||||
void PFXPetApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
@@ -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<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
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<QString,int> _serverIndices;
|
||||
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;
|
||||
QMap<QString, QString> _apiKeys;
|
||||
|
||||
@@ -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<QString, PFXServerVariable>& variables)
|
||||
PFXServerConfiguration(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &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<QString, PFXServerVariable> _variables;
|
||||
QString _URL;
|
||||
QUrl _url;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||
//varying endpoint server
|
||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
||||
defaultConf.append(PFXServerConfiguration(
|
||||
"http://petstore.swagger.io/v2",
|
||||
QUrl("http://petstore.swagger.io/v2"),
|
||||
"No description provided",
|
||||
QMap<QString, PFXServerVariable>()));
|
||||
_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<QString, PFXServerVariable> &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<QString, PFXServerVariable> &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<QString, PFXServerVariable> &variables){
|
||||
|
||||
setServerIndex(operation, addServerConfiguration(operation, url, description, variables));
|
||||
|
||||
}
|
||||
|
||||
void PFXStoreApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
@@ -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<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
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<QString,int> _serverIndices;
|
||||
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;
|
||||
QMap<QString, QString> _apiKeys;
|
||||
|
||||
@@ -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<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||
//varying endpoint server
|
||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
||||
defaultConf.append(PFXServerConfiguration(
|
||||
"http://petstore.swagger.io/v2",
|
||||
QUrl("http://petstore.swagger.io/v2"),
|
||||
"No description provided",
|
||||
QMap<QString, PFXServerVariable>()));
|
||||
_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<QString, PFXServerVariable> &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<QString, PFXServerVariable> &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<QString, PFXServerVariable> &variables){
|
||||
|
||||
setServerIndex(operation, addServerConfiguration(operation, url, description, variables));
|
||||
|
||||
}
|
||||
|
||||
void PFXUserApi::addHeaders(const QString &key, const QString &value) {
|
||||
defaultHeaders.insert(key, value);
|
||||
}
|
||||
|
||||
@@ -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<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap<QString, PFXServerVariable> &variables = QMap<QString, PFXServerVariable>());
|
||||
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<QString,int> _serverIndices;
|
||||
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;
|
||||
QMap<QString, QString> _apiKeys;
|
||||
|
||||
Reference in New Issue
Block a user