From febd65d3b8a583befb3e951ca646d9d132437406 Mon Sep 17 00:00:00 2001 From: basyskom-dege <72982549+basyskom-dege@users.noreply.github.com> Date: Sat, 19 Dec 2020 04:34:12 +0100 Subject: [PATCH] Qt5 parameterized server (#8183) * first Commit parameterzied Server support * fixed serverconfig classes * Defautl constructor f. Config, fixed regex replace * Polosihed Templates, Added MultiServer support * Update Readme. Fixed MultiServer. Fixed def. Value * Passing global Server to mustache. Small fixes * Updated samples, fixed mustache for multi server * added prefixes, removed unused imports * added newly generated samples * missing vendorExtension in mustache. Update smaple * update doc Co-authored-by: William Cheng --- docs/generators/cpp-qt5-client.md | 6 +- .../codegen/languages/AbstractCppCodegen.java | 30 +++++ .../languages/CppQt5ClientCodegen.java | 13 ++ .../resources/cpp-qt5-client/Project.mustache | 6 +- .../resources/cpp-qt5-client/README.mustache | 52 ++++++++ .../ServerConfiguration.mustache | 73 +++++++++++ .../cpp-qt5-client/ServerVariable.mustache | 52 ++++++++ .../cpp-qt5-client/api-body.mustache | 70 +++++++++-- .../cpp-qt5-client/api-header.mustache | 9 +- .../petstore/cpp-qt5/.openapi-generator/FILES | 31 +++++ samples/client/petstore/cpp-qt5/README.md | 52 ++++++++ .../petstore/cpp-qt5/client/PFXPetApi.cpp | 115 ++++++++++-------- .../petstore/cpp-qt5/client/PFXPetApi.h | 9 +- .../cpp-qt5/client/PFXServerConfiguration.h | 79 ++++++++++++ .../cpp-qt5/client/PFXServerVariable.h | 58 +++++++++ .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 75 ++++++++---- .../petstore/cpp-qt5/client/PFXStoreApi.h | 9 +- .../petstore/cpp-qt5/client/PFXUserApi.cpp | 115 ++++++++++-------- .../petstore/cpp-qt5/client/PFXUserApi.h | 9 +- .../petstore/cpp-qt5/client/PFXclient.pri | 6 +- .../cpp-qt5/client/ServerConfiguration.h | 75 ++++++++++++ .../petstore/cpp-qt5/client/ServerVariable.h | 53 ++++++++ .../cpp-tizen/.openapi-generator/FILES | 29 +++++ .../cpp-tizen/.openapi-generator/VERSION | 2 +- .../petstore/cpp-tizen/src/PetManager.cpp | 28 ++--- .../petstore/cpp-tizen/src/PetManager.h | 16 +-- .../petstore/cpp-tizen/src/StoreManager.cpp | 14 +-- .../petstore/cpp-tizen/src/StoreManager.h | 8 +- .../petstore/cpp-tizen/src/UserManager.cpp | 64 +++++----- .../petstore/cpp-tizen/src/UserManager.h | 32 ++--- .../cpp-ue4/Private/OpenAPIPetApi.cpp | 8 +- .../cpp-ue4/Private/OpenAPIStoreApi.cpp | 8 +- .../cpp-ue4/Private/OpenAPIUserApi.cpp | 8 +- .../cpp-restbed/.openapi-generator/FILES | 21 ++++ 34 files changed, 1002 insertions(+), 233 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerConfiguration.mustache create mode 100644 modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerVariable.mustache create mode 100644 samples/client/petstore/cpp-qt5/.openapi-generator/FILES create mode 100644 samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h create mode 100644 samples/client/petstore/cpp-qt5/client/PFXServerVariable.h create mode 100644 samples/client/petstore/cpp-qt5/client/ServerConfiguration.h create mode 100644 samples/client/petstore/cpp-qt5/client/ServerVariable.h create mode 100644 samples/client/petstore/cpp-tizen/.openapi-generator/FILES create mode 100644 samples/server/petstore/cpp-restbed/.openapi-generator/FILES diff --git a/docs/generators/cpp-qt5-client.md b/docs/generators/cpp-qt5-client.md index 7ed47285e40..557ea18b69b 100644 --- a/docs/generators/cpp-qt5-client.md +++ b/docs/generators/cpp-qt5-client.md @@ -187,7 +187,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl ### Documentation Feature | Name | Supported | Defined By | | ---- | --------- | ---------- | -|Readme|✗|ToolingExtension +|Readme|✓|ToolingExtension |Model|✓|ToolingExtension |Api|✓|ToolingExtension @@ -204,8 +204,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl |ExternalDocumentation|✓|OAS2,OAS3 |Examples|✓|OAS2,OAS3 |XMLStructureDefinitions|✗|OAS2,OAS3 -|MultiServer|✗|OAS3 -|ParameterizedServer|✗|OAS3 +|MultiServer|✓|OAS3 +|ParameterizedServer|✓|OAS3 |ParameterStyling|✗|OAS3 |Callbacks|✗|OAS3 |LinkObjects|✗|OAS3 diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java index f03ac52aece..314fde7a787 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java @@ -19,8 +19,14 @@ package org.openapitools.codegen.languages; import com.google.common.collect.ImmutableMap.Builder; import com.samskivert.mustache.Mustache.Lambda; + import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.media.Schema; +import io.swagger.v3.oas.models.servers.Server; +import io.swagger.v3.oas.models.servers.ServerVariables; +import io.swagger.v3.oas.models.servers.ServerVariable; +import org.openapitools.codegen.CodegenServer; +import org.openapitools.codegen.CodegenServerVariable; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.CodegenConfig; @@ -327,6 +333,8 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg @Override public void preprocessOpenAPI(OpenAPI openAPI) { + List serverList = openAPI.getServers(); + List CodegenServerList = new ArrayList(); URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides()); String port = URLPathUtils.getPort(url, ""); String host = url.getHost(); @@ -341,6 +349,28 @@ abstract public class AbstractCppCodegen extends DefaultCodegen implements Codeg if (!scheme.isEmpty()) { this.additionalProperties.put("scheme", scheme); } + if (!serverList.isEmpty()) { + for (Server server : serverList) { + CodegenServer s = new CodegenServer(); + s.description = server.getDescription(); + s.url = server.getUrl(); + s.variables = new ArrayList(); + ServerVariables serverVars = server.getVariables(); + if(serverVars != null){ + serverVars.forEach((key,value) -> { + CodegenServerVariable codegenServerVar= new CodegenServerVariable(); + ServerVariable ServerVar = value; + codegenServerVar.name = key; + codegenServerVar.description = ServerVar.getDescription(); + codegenServerVar.defaultValue = ServerVar.getDefault(); + codegenServerVar.enumValues = ServerVar.getEnum(); + s.variables.add(codegenServerVar); + }); + } + CodegenServerList.add(s); + } + this.vendorExtensions.put("x-codegen-globalServerList", CodegenServerList); + } } @Override diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java index 79a63c00845..f0b8cfc957c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java @@ -21,6 +21,8 @@ import org.openapitools.codegen.CodegenConfig; import org.openapitools.codegen.CodegenConstants; import org.openapitools.codegen.CodegenType; import org.openapitools.codegen.SupportingFile; +import org.openapitools.codegen.meta.features.DocumentationFeature; +import org.openapitools.codegen.meta.features.GlobalFeature; import java.io.File; @@ -35,6 +37,13 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege public CppQt5ClientCodegen() { super(); + + modifyFeatureSet(features -> features + .includeDocumentationFeatures(DocumentationFeature.Readme) + .includeGlobalFeatures(GlobalFeature.ParameterizedServer) + .includeGlobalFeatures(GlobalFeature.MultiServer) + ); + // set the output folder here outputFolder = "generated-code/qt5cpp"; @@ -80,6 +89,8 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, PREFIX + "HttpFileElement.cpp")); supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h")); supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h")); + supportingFiles.add(new SupportingFile("ServerConfiguration.mustache", sourceFolder, PREFIX +"ServerConfiguration.h")); + supportingFiles.add(new SupportingFile("ServerVariable.mustache", sourceFolder, PREFIX +"ServerVariable.h")); supportingFiles.add(new SupportingFile("README.mustache", "","README.md")); supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt")); if (optionalProjectFileFlag) { @@ -109,6 +120,8 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, modelNamePrefix + "HttpFileElement.cpp")); supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h")); supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h")); + supportingFiles.add(new SupportingFile("ServerConfiguration.mustache", sourceFolder, modelNamePrefix + "ServerConfiguration.h")); + supportingFiles.add(new SupportingFile("ServerVariable.mustache", sourceFolder, modelNamePrefix + "ServerVariable.h")); supportingFiles.add(new SupportingFile("README.mustache", "","README.md")); supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt")); diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/Project.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/Project.mustache index 6b989b8c00e..5a601d0978a 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/Project.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/Project.mustache @@ -20,8 +20,10 @@ HEADERS += \ $${PWD}/{{prefix}}HttpRequest.h \ $${PWD}/{{prefix}}Object.h \ $${PWD}/{{prefix}}Enum.h \ - $${PWD}/{{prefix}}HttpFileElement.h - + $${PWD}/{{prefix}}HttpFileElement.h \ + $${PWD}/{{prefix}}ServerConfiguration.h \ + $${PWD}/{{prefix}}ServerVariable.h + SOURCES += \ # Models {{#models}} diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache index 2cd99b3520e..5f319457532 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache @@ -146,6 +146,58 @@ Class | Method | HTTP request | Description {{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md) {{/model}}{{/models}} +## Documentation for Servers + +Parameterized Servers are supported. Define a server in the API for each endpoint with arbitrary numbers of variables: + +``` +servers: +- url: http://{server}:{port}/{basePath} + description: Description of the Server + variables: + server: + enum: + - 'petstore' + - 'qa-petstore' + - 'dev-petstore' + default: 'petstore' + port: + enum: + - '3000' + - '1000' + default: '3000' + basePath: + default: v1 +``` +To change the default variable, use this function in each Api: +``` + int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); +``` +The parameter "serverIndex" will choose a server from the server list for each endpoint. There is always at least one server with index 0. The Paramter "operation" should be the desired endpoint operationid. +Variable is the name of the variable you wish to change and the value is the new default Value. +The function will return -1 when the variable does not exists, -2 if value is not defined in the variable enum and -3 if the operation is not found. + +If your endpoint has multiple server objects in the servers array, you can set the server that will be used with this function: +``` + 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. +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. +``` +servers: +- url: http://{server}:8080/ + description: Description of the Server + variables: + server: + enum: + - 'petstore' + - 'qa-petstore' + - 'dev-petstore' + default: 'petstore' +- url: https://localhost:8080/v1 +``` + + ## Documentation for Authorization {{^authMethods}}All endpoints do not require authorization. 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 new file mode 100644 index 00000000000..87bf899487c --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerConfiguration.mustache @@ -0,0 +1,73 @@ +{{>licenseInfo}} +/** + * Representing a Server configuration. + */ +#ifndef {{prefix}}_SERVERVCONFIGURATION_H +#define {{prefix}}_SERVERVCONFIGURATION_H +#include +#include +#include +#include "{{prefix}}ServerVariable.h" + +{{#cppNamespaceDeclarations}} +namespace {{this}} { +{{/cppNamespaceDeclarations}} + +class {{prefix}}ServerConfiguration { +public: + /** + * @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) + : _description(description), + _variables(variables), + _URL(URL){} + {{prefix}}ServerConfiguration(){} + ~{{prefix}}ServerConfiguration(){} + + /** + * Format URL template using given variables. + * + * @param variables A map between a variable name and its value. + * @return Formatted URL. + */ + QString URL() { + QString url = _URL; + if(!_variables.empty()){ + // go through variables and replace placeholders + for (auto const& v : _variables.keys()) { + QString name = v; + {{prefix}}ServerVariable serverVariable = _variables.value(v); + QString value = serverVariable._defaultValue; + + if (!serverVariable._enumValues.empty() && !serverVariable._enumValues.contains(value)) { + throw std::runtime_error(QString("The variable " + name + " in the server URL has invalid value " + value + ".").toUtf8()); + } + QRegularExpression regex(QString("\\{" + name + "\\}")); + url = url.replace(regex, value); + + } + return url; + } + return url; + } + + int setDefaultValue(const QString& variable,const QString& value){ + if(_variables.contains(variable)) + return _variables[variable].setDefaultValue(value); + return -1; + } + + QString _description; + QMap _variables; + QString _URL; + +}; + +{{#cppNamespaceDeclarations}} +} // namespace {{this}} +{{/cppNamespaceDeclarations}} + +#endif // {{prefix}}_SERVERVCONFIGURATION_H diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerVariable.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerVariable.mustache new file mode 100644 index 00000000000..04abcf783ff --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/ServerVariable.mustache @@ -0,0 +1,52 @@ +{{>licenseInfo}} +/** + * Representing a Server Variable for server URL template substitution. + */ +#ifndef {{prefix}}_SERVERVARIABLE_H +#define {{prefix}}_SERVERVARIABLE_H +#include +#include + +{{#cppNamespaceDeclarations}} +namespace {{this}} { +{{/cppNamespaceDeclarations}} + +class {{prefix}}ServerVariable { +public: + + /** + * @param description A description for the server variable. + * @param defaultValue The default value to use for substitution. + * @param enumValues An enumeration of string values to be used if the substitution options are from a limited set. + */ + {{prefix}}ServerVariable(const QString &description, const QString &defaultValue, const QSet &enumValues) + : _defaultValue(defaultValue), + _description(description), + _enumValues(enumValues){} + + {{prefix}}ServerVariable(){} + ~{{prefix}}ServerVariable(){} + + int setDefaultValue(const QString& value){ + if( _enumValues.contains(value)){ + _defaultValue = value; + return 0; + } + return -2; + } + + QString getDefaultValue(){return _defaultValue;} + QSet getEnumValues(){return _enumValues;} + + + QString _defaultValue; + QString _description; + QSet _enumValues; + +}; + +{{#cppNamespaceDeclarations}} +} // namespace {{this}} +{{/cppNamespaceDeclarations}} + +#endif // {{prefix}}_SERVERVARIABLE_H 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 5e37fc0ba11..db31fb6a92e 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 @@ -1,7 +1,7 @@ {{>licenseInfo}} #include "{{classname}}.h" #include "{{prefix}}Helpers.h" - +#include "{{prefix}}ServerConfiguration.h" #include #include @@ -17,11 +17,70 @@ namespace {{this}} { _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), - isRequestCompressionEnabled(false) {} + isRequestCompressionEnabled(false) { + initializeServerConfigs(); + } {{classname}}::~{{classname}}() { } +void {{classname}}::initializeServerConfigs(){ + +//Default server +QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfiguration>(); +//varying endpoint server +QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>(); +{{#vendorExtensions}} +{{#x-codegen-globalServerList}} +defaultConf.append({{prefix}}ServerConfiguration( + "{{{url}}}", + "{{{description}}}{{^description}}No description provided{{/description}}", + {{#variables}}{{#-first}}QMap{ {{/-first}} + {"{{{name}}}", {{prefix}}ServerVariable("{{{description}}}{{^description}}No description provided{{/description}}","{{{defaultValue}}}", + QSet{ {{#enumValues}}{"{{{.}}}"}{{#-last}} })},{{/-last}}{{^-last}},{{/-last}}{{/enumValues}}{{^enumValues}}{"{{defaultValue}}"} })},{{/enumValues}}{{#-last}} }));{{/-last}} + {{/variables}}{{^variables}}QMap()));{{/variables}} +{{/x-codegen-globalServerList}} +{{/vendorExtensions}} +{{#operations}} + {{#operation}} + {{^servers}} +_serverConfigs.insert("{{nickname}}",defaultConf); +_serverIndices.insert("{{nickname}}",0); + +{{/servers}} +{{#servers}} +serverConf.append({{prefix}}ServerConfiguration( + "{{{url}}}", + "{{{description}}}{{^description}}No description provided{{/description}}", + {{#variables}}{{#-first}}QMap{ {{/-first}} + {"{{{name}}}", {{prefix}}ServerVariable("{{{description}}}{{^description}}No description provided{{/description}}","{{{defaultValue}}}", + QSet{ {{#enumValues}}{"{{{.}}}"}{{#-last}} })}, {{/-last}}{{^-last}},{{/-last}}{{/enumValues}}{{^enumValues}}{"{{defaultValue}}"} })},{{/enumValues}}{{#-last}} }));{{/-last}} + {{/variables}}{{^variables}}QMap()));{{/variables}} +{{#-last}}_serverConfigs.insert("{{nickname}}",serverConf); +_serverIndices.insert("{{nickname}}",0);{{/-last}} + +{{/servers}} +{{/operation}} +{{/operations}} + +} + +/** +* returns 0 on success and -1, -2 or -3 on failure. +* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found +*/ +int {{classname}}::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value){ + auto it = _serverConfigs.find(operation); + if(it != _serverConfigs.end() && serverIndex < it.value().size() ){ + return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); + } + return -3; +} +void {{classname}}::setServerIndex(const QString &operation, int serverIndex){ + if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() ) + _serverIndices[operation] = serverIndex; +} + void {{classname}}::setScheme(const QString &scheme) { _scheme = scheme; } @@ -85,12 +144,7 @@ void {{classname}}::abortRequests(){ {{#operations}} {{#operation}} void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("{{{path}}}"); + QString fullPath = QString(_serverConfigs["{{nickname}}"][_serverIndices.value("{{nickname}}")].URL()+"{{{path}}}"); {{#pathParams}} QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{baseName}}").append("}"); 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 4f241ec3ff3..f802c2015da 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 @@ -3,6 +3,7 @@ #define {{prefix}}_{{classname}}_H #include "{{prefix}}HttpRequest.h" +#include "{{prefix}}ServerConfiguration.h" {{#imports}}{{{import}}} {{/imports}} @@ -10,6 +11,7 @@ #include #include #include +#include #include {{#cppNamespaceDeclarations}} @@ -23,6 +25,9 @@ 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}}(); + 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); @@ -44,11 +49,13 @@ public: private: QString _scheme, _host; int _port; + QString _basePath; + QMap _serverIndices; + QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; QString _username; QString _password; - QString _basePath; int _timeOut; QString _workingDirectory; QNetworkAccessManager* _manager; diff --git a/samples/client/petstore/cpp-qt5/.openapi-generator/FILES b/samples/client/petstore/cpp-qt5/.openapi-generator/FILES new file mode 100644 index 00000000000..3b14ec399c5 --- /dev/null +++ b/samples/client/petstore/cpp-qt5/.openapi-generator/FILES @@ -0,0 +1,31 @@ +README.md +client/CMakeLists.txt +client/PFXApiResponse.cpp +client/PFXApiResponse.h +client/PFXCategory.cpp +client/PFXCategory.h +client/PFXEnum.h +client/PFXHelpers.cpp +client/PFXHelpers.h +client/PFXHttpFileElement.cpp +client/PFXHttpFileElement.h +client/PFXHttpRequest.cpp +client/PFXHttpRequest.h +client/PFXObject.h +client/PFXOrder.cpp +client/PFXOrder.h +client/PFXPet.cpp +client/PFXPet.h +client/PFXPetApi.cpp +client/PFXPetApi.h +client/PFXServerConfiguration.h +client/PFXServerVariable.h +client/PFXStoreApi.cpp +client/PFXStoreApi.h +client/PFXTag.cpp +client/PFXTag.h +client/PFXUser.cpp +client/PFXUser.h +client/PFXUserApi.cpp +client/PFXUserApi.h +client/PFXclient.pri diff --git a/samples/client/petstore/cpp-qt5/README.md b/samples/client/petstore/cpp-qt5/README.md index 4ae23681d5d..f72d21e557d 100644 --- a/samples/client/petstore/cpp-qt5/README.md +++ b/samples/client/petstore/cpp-qt5/README.md @@ -147,6 +147,58 @@ Class | Method | HTTP request | Description - [PFXUser](PFXUser.md) +## Documentation for Servers + +Parameterized Servers are supported. Define a server in the API for each endpoint with arbitrary numbers of variables: + +``` +servers: +- url: http://{server}:{port}/{basePath} + description: Description of the Server + variables: + server: + enum: + - 'petstore' + - 'qa-petstore' + - 'dev-petstore' + default: 'petstore' + port: + enum: + - '3000' + - '1000' + default: '3000' + basePath: + default: v1 +``` +To change the default variable, use this function in each Api: +``` + int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); +``` +The parameter "serverIndex" will choose a server from the server list for each endpoint. There is always at least one server with index 0. The Paramter "operation" should be the desired endpoint operationid. +Variable is the name of the variable you wish to change and the value is the new default Value. +The function will return -1 when the variable does not exists, -2 if value is not defined in the variable enum and -3 if the operation is not found. + +If your endpoint has multiple server objects in the servers array, you can set the server that will be used with this function: +``` + 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. +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. +``` +servers: +- url: http://{server}:8080/ + description: Description of the Server + variables: + server: + enum: + - 'petstore' + - 'qa-petstore' + - 'dev-petstore' + default: 'petstore' +- url: https://localhost:8080/v1 +``` + + ## Documentation for Authorization Authentication schemes defined for the API: diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index d637fddb7fe..6adce3da88d 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -11,7 +11,7 @@ #include "PFXPetApi.h" #include "PFXHelpers.h" - +#include "PFXServerConfiguration.h" #include #include @@ -25,11 +25,66 @@ PFXPetApi::PFXPetApi(const QString &scheme, const QString &host, int port, const _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), - isRequestCompressionEnabled(false) {} + isRequestCompressionEnabled(false) { + initializeServerConfigs(); + } PFXPetApi::~PFXPetApi() { } +void PFXPetApi::initializeServerConfigs(){ + +//Default server +QList defaultConf = QList(); +//varying endpoint server +QList serverConf = QList(); +defaultConf.append(PFXServerConfiguration( + "http://petstore.swagger.io/v2", + "No description provided", + QMap())); +_serverConfigs.insert("addPet",defaultConf); +_serverIndices.insert("addPet",0); + +_serverConfigs.insert("deletePet",defaultConf); +_serverIndices.insert("deletePet",0); + +_serverConfigs.insert("findPetsByStatus",defaultConf); +_serverIndices.insert("findPetsByStatus",0); + +_serverConfigs.insert("findPetsByTags",defaultConf); +_serverIndices.insert("findPetsByTags",0); + +_serverConfigs.insert("getPetById",defaultConf); +_serverIndices.insert("getPetById",0); + +_serverConfigs.insert("updatePet",defaultConf); +_serverIndices.insert("updatePet",0); + +_serverConfigs.insert("updatePetWithForm",defaultConf); +_serverIndices.insert("updatePetWithForm",0); + +_serverConfigs.insert("uploadFile",defaultConf); +_serverIndices.insert("uploadFile",0); + + +} + +/** +* returns 0 on success and -1, -2 or -3 on failure. +* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found +*/ +int PFXPetApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value){ + auto it = _serverConfigs.find(operation); + if(it != _serverConfigs.end() && serverIndex < it.value().size() ){ + return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); + } + return -3; +} +void PFXPetApi::setServerIndex(const QString &operation, int serverIndex){ + if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() ) + _serverIndices[operation] = serverIndex; +} + void PFXPetApi::setScheme(const QString &scheme) { _scheme = scheme; } @@ -91,12 +146,7 @@ void PFXPetApi::abortRequests(){ } void PFXPetApi::addPet(const PFXPet &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet"); + QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -137,12 +187,7 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet/{petId}"); + QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); @@ -187,12 +232,7 @@ void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::findPetsByStatus(const QList &status) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet/findByStatus"); + QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus"); if (status.size() > 0) { @@ -278,12 +318,7 @@ void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::findPetsByTags(const QList &tags) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet/findByTags"); + QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags"); if (tags.size() > 0) { @@ -369,12 +404,7 @@ void PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::getPetById(const qint64 &pet_id) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet/{petId}"); + QString fullPath = QString(_serverConfigs["getPetById"][_serverIndices.value("getPetById")].URL()+"/pet/{petId}"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); @@ -420,12 +450,7 @@ void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::updatePet(const PFXPet &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet"); + QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -466,12 +491,7 @@ void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, const QString &status) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet/{petId}"); + QString fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); @@ -514,12 +534,7 @@ void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) { } void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metadata, const PFXHttpFileElement &file) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/pet/{petId}/uploadImage"); + QString fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index 71f0e48cb37..7c3e9b331f3 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -13,6 +13,7 @@ #define PFX_PFXPetApi_H #include "PFXHttpRequest.h" +#include "PFXServerConfiguration.h" #include "PFXApiResponse.h" #include "PFXHttpFileElement.h" @@ -22,6 +23,7 @@ #include #include #include +#include #include namespace test_namespace { @@ -33,6 +35,9 @@ public: PFXPetApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString &basePath = "/v2", 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); @@ -61,11 +66,13 @@ public: private: QString _scheme, _host; int _port; + QString _basePath; + QMap _serverIndices; + QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; QString _username; QString _password; - QString _basePath; int _timeOut; QString _workingDirectory; QNetworkAccessManager* _manager; diff --git a/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h b/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h new file mode 100644 index 00000000000..b619015428c --- /dev/null +++ b/samples/client/petstore/cpp-qt5/client/PFXServerConfiguration.h @@ -0,0 +1,79 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * Representing a Server configuration. + */ +#ifndef PFX_SERVERVCONFIGURATION_H +#define PFX_SERVERVCONFIGURATION_H +#include +#include +#include +#include "PFXServerVariable.h" + +namespace test_namespace { + +class PFXServerConfiguration { +public: + /** + * @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) + : _description(description), + _variables(variables), + _URL(URL){} + PFXServerConfiguration(){} + ~PFXServerConfiguration(){} + + /** + * Format URL template using given variables. + * + * @param variables A map between a variable name and its value. + * @return Formatted URL. + */ + QString URL() { + QString url = _URL; + if(!_variables.empty()){ + // go through variables and replace placeholders + for (auto const& v : _variables.keys()) { + QString name = v; + PFXServerVariable serverVariable = _variables.value(v); + QString value = serverVariable._defaultValue; + + if (!serverVariable._enumValues.empty() && !serverVariable._enumValues.contains(value)) { + throw std::runtime_error(QString("The variable " + name + " in the server URL has invalid value " + value + ".").toUtf8()); + } + QRegularExpression regex(QString("\\{" + name + "\\}")); + url = url.replace(regex, value); + + } + return url; + } + return url; + } + + int setDefaultValue(const QString& variable,const QString& value){ + if(_variables.contains(variable)) + return _variables[variable].setDefaultValue(value); + return -1; + } + + QString _description; + QMap _variables; + QString _URL; + +}; + +} // namespace test_namespace + +#endif // PFX_SERVERVCONFIGURATION_H diff --git a/samples/client/petstore/cpp-qt5/client/PFXServerVariable.h b/samples/client/petstore/cpp-qt5/client/PFXServerVariable.h new file mode 100644 index 00000000000..b4cd0036238 --- /dev/null +++ b/samples/client/petstore/cpp-qt5/client/PFXServerVariable.h @@ -0,0 +1,58 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * Representing a Server Variable for server URL template substitution. + */ +#ifndef PFX_SERVERVARIABLE_H +#define PFX_SERVERVARIABLE_H +#include +#include + +namespace test_namespace { + +class PFXServerVariable { +public: + + /** + * @param description A description for the server variable. + * @param defaultValue The default value to use for substitution. + * @param enumValues An enumeration of string values to be used if the substitution options are from a limited set. + */ + PFXServerVariable(const QString &description, const QString &defaultValue, const QSet &enumValues) + : _defaultValue(defaultValue), + _description(description), + _enumValues(enumValues){} + + PFXServerVariable(){} + ~PFXServerVariable(){} + + int setDefaultValue(const QString& value){ + if( _enumValues.contains(value)){ + _defaultValue = value; + return 0; + } + return -2; + } + + QString getDefaultValue(){return _defaultValue;} + QSet getEnumValues(){return _enumValues;} + + + QString _defaultValue; + QString _description; + QSet _enumValues; + +}; + +} // namespace test_namespace + +#endif // PFX_SERVERVARIABLE_H diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index 922e1fd5c3d..2c3113677d0 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -11,7 +11,7 @@ #include "PFXStoreApi.h" #include "PFXHelpers.h" - +#include "PFXServerConfiguration.h" #include #include @@ -25,11 +25,54 @@ PFXStoreApi::PFXStoreApi(const QString &scheme, const QString &host, int port, c _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), - isRequestCompressionEnabled(false) {} + isRequestCompressionEnabled(false) { + initializeServerConfigs(); + } PFXStoreApi::~PFXStoreApi() { } +void PFXStoreApi::initializeServerConfigs(){ + +//Default server +QList defaultConf = QList(); +//varying endpoint server +QList serverConf = QList(); +defaultConf.append(PFXServerConfiguration( + "http://petstore.swagger.io/v2", + "No description provided", + QMap())); +_serverConfigs.insert("deleteOrder",defaultConf); +_serverIndices.insert("deleteOrder",0); + +_serverConfigs.insert("getInventory",defaultConf); +_serverIndices.insert("getInventory",0); + +_serverConfigs.insert("getOrderById",defaultConf); +_serverIndices.insert("getOrderById",0); + +_serverConfigs.insert("placeOrder",defaultConf); +_serverIndices.insert("placeOrder",0); + + +} + +/** +* returns 0 on success and -1, -2 or -3 on failure. +* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found +*/ +int PFXStoreApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value){ + auto it = _serverConfigs.find(operation); + if(it != _serverConfigs.end() && serverIndex < it.value().size() ){ + return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); + } + return -3; +} +void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex){ + if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() ) + _serverIndices[operation] = serverIndex; +} + void PFXStoreApi::setScheme(const QString &scheme) { _scheme = scheme; } @@ -91,12 +134,7 @@ void PFXStoreApi::abortRequests(){ } void PFXStoreApi::deleteOrder(const QString &order_id) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/store/order/{orderId}"); + QString fullPath = QString(_serverConfigs["deleteOrder"][_serverIndices.value("deleteOrder")].URL()+"/store/order/{orderId}"); QString order_idPathParam("{"); order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); @@ -137,12 +175,7 @@ void PFXStoreApi::deleteOrderCallback(PFXHttpRequestWorker *worker) { } void PFXStoreApi::getInventory() { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/store/inventory"); + QString fullPath = QString(_serverConfigs["getInventory"][_serverIndices.value("getInventory")].URL()+"/store/inventory"); if(_apiKeys.contains("api_key")){ addHeaders("api_key",_apiKeys.find("api_key").value()); @@ -194,12 +227,7 @@ void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) { } void PFXStoreApi::getOrderById(const qint64 &order_id) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/store/order/{orderId}"); + QString fullPath = QString(_serverConfigs["getOrderById"][_serverIndices.value("getOrderById")].URL()+"/store/order/{orderId}"); QString order_idPathParam("{"); order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); @@ -241,12 +269,7 @@ void PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker *worker) { } void PFXStoreApi::placeOrder(const PFXOrder &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/store/order"); + QString fullPath = QString(_serverConfigs["placeOrder"][_serverIndices.value("placeOrder")].URL()+"/store/order"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index 626a0236ee4..d065169e181 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -13,6 +13,7 @@ #define PFX_PFXStoreApi_H #include "PFXHttpRequest.h" +#include "PFXServerConfiguration.h" #include "PFXOrder.h" #include @@ -21,6 +22,7 @@ #include #include #include +#include #include namespace test_namespace { @@ -32,6 +34,9 @@ public: PFXStoreApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString &basePath = "/v2", 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); @@ -56,11 +61,13 @@ public: private: QString _scheme, _host; int _port; + QString _basePath; + QMap _serverIndices; + QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; QString _username; QString _password; - QString _basePath; int _timeOut; QString _workingDirectory; QNetworkAccessManager* _manager; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index 68390407530..21350d76465 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -11,7 +11,7 @@ #include "PFXUserApi.h" #include "PFXHelpers.h" - +#include "PFXServerConfiguration.h" #include #include @@ -25,11 +25,66 @@ PFXUserApi::PFXUserApi(const QString &scheme, const QString &host, int port, con _timeOut(timeOut), _manager(nullptr), isResponseCompressionEnabled(false), - isRequestCompressionEnabled(false) {} + isRequestCompressionEnabled(false) { + initializeServerConfigs(); + } PFXUserApi::~PFXUserApi() { } +void PFXUserApi::initializeServerConfigs(){ + +//Default server +QList defaultConf = QList(); +//varying endpoint server +QList serverConf = QList(); +defaultConf.append(PFXServerConfiguration( + "http://petstore.swagger.io/v2", + "No description provided", + QMap())); +_serverConfigs.insert("createUser",defaultConf); +_serverIndices.insert("createUser",0); + +_serverConfigs.insert("createUsersWithArrayInput",defaultConf); +_serverIndices.insert("createUsersWithArrayInput",0); + +_serverConfigs.insert("createUsersWithListInput",defaultConf); +_serverIndices.insert("createUsersWithListInput",0); + +_serverConfigs.insert("deleteUser",defaultConf); +_serverIndices.insert("deleteUser",0); + +_serverConfigs.insert("getUserByName",defaultConf); +_serverIndices.insert("getUserByName",0); + +_serverConfigs.insert("loginUser",defaultConf); +_serverIndices.insert("loginUser",0); + +_serverConfigs.insert("logoutUser",defaultConf); +_serverIndices.insert("logoutUser",0); + +_serverConfigs.insert("updateUser",defaultConf); +_serverIndices.insert("updateUser",0); + + +} + +/** +* returns 0 on success and -1, -2 or -3 on failure. +* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found +*/ +int PFXUserApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value){ + auto it = _serverConfigs.find(operation); + if(it != _serverConfigs.end() && serverIndex < it.value().size() ){ + return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); + } + return -3; +} +void PFXUserApi::setServerIndex(const QString &operation, int serverIndex){ + if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() ) + _serverIndices[operation] = serverIndex; +} + void PFXUserApi::setScheme(const QString &scheme) { _scheme = scheme; } @@ -91,12 +146,7 @@ void PFXUserApi::abortRequests(){ } void PFXUserApi::createUser(const PFXUser &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user"); + QString fullPath = QString(_serverConfigs["createUser"][_serverIndices.value("createUser")].URL()+"/user"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -137,12 +187,7 @@ void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) { } void PFXUserApi::createUsersWithArrayInput(const QList &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/createWithArray"); + QString fullPath = QString(_serverConfigs["createUsersWithArrayInput"][_serverIndices.value("createUsersWithArrayInput")].URL()+"/user/createWithArray"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -184,12 +229,7 @@ void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker) } void PFXUserApi::createUsersWithListInput(const QList &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/createWithList"); + QString fullPath = QString(_serverConfigs["createUsersWithListInput"][_serverIndices.value("createUsersWithListInput")].URL()+"/user/createWithList"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -231,12 +271,7 @@ void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker) } void PFXUserApi::deleteUser(const QString &username) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/{username}"); + QString fullPath = QString(_serverConfigs["deleteUser"][_serverIndices.value("deleteUser")].URL()+"/user/{username}"); QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); @@ -277,12 +312,7 @@ void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) { } void PFXUserApi::getUserByName(const QString &username) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/{username}"); + QString fullPath = QString(_serverConfigs["getUserByName"][_serverIndices.value("getUserByName")].URL()+"/user/{username}"); QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); @@ -324,12 +354,7 @@ void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) { } void PFXUserApi::loginUser(const QString &username, const QString &password) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/login"); + QString fullPath = QString(_serverConfigs["loginUser"][_serverIndices.value("loginUser")].URL()+"/user/login"); if (fullPath.indexOf("?") > 0) @@ -381,12 +406,7 @@ void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) { } void PFXUserApi::logoutUser() { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/logout"); + QString fullPath = QString(_serverConfigs["logoutUser"][_serverIndices.value("logoutUser")].URL()+"/user/logout"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -424,12 +444,7 @@ void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) { } void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { - QString fullPath = QString("%1://%2%3%4%5") - .arg(_scheme) - .arg(_host) - .arg(_port ? ":" + QString::number(_port) : "") - .arg(_basePath) - .arg("/user/{username}"); + QString fullPath = QString(_serverConfigs["updateUser"][_serverIndices.value("updateUser")].URL()+"/user/{username}"); QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index d6bb21b5a8d..aada5d8f3bf 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -13,6 +13,7 @@ #define PFX_PFXUserApi_H #include "PFXHttpRequest.h" +#include "PFXServerConfiguration.h" #include "PFXUser.h" #include @@ -21,6 +22,7 @@ #include #include #include +#include #include namespace test_namespace { @@ -32,6 +34,9 @@ public: PFXUserApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString &basePath = "/v2", 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); @@ -60,11 +65,13 @@ public: private: QString _scheme, _host; int _port; + QString _basePath; + QMap _serverIndices; + QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; QString _username; QString _password; - QString _basePath; int _timeOut; QString _workingDirectory; QNetworkAccessManager* _manager; diff --git a/samples/client/petstore/cpp-qt5/client/PFXclient.pri b/samples/client/petstore/cpp-qt5/client/PFXclient.pri index c09a32bdf4f..d2a439be269 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXclient.pri +++ b/samples/client/petstore/cpp-qt5/client/PFXclient.pri @@ -17,8 +17,10 @@ HEADERS += \ $${PWD}/PFXHttpRequest.h \ $${PWD}/PFXObject.h \ $${PWD}/PFXEnum.h \ - $${PWD}/PFXHttpFileElement.h - + $${PWD}/PFXHttpFileElement.h \ + $${PWD}/PFXServerConfiguration.h \ + $${PWD}/PFXServerVariable.h + SOURCES += \ # Models $${PWD}/PFXApiResponse.cpp \ diff --git a/samples/client/petstore/cpp-qt5/client/ServerConfiguration.h b/samples/client/petstore/cpp-qt5/client/ServerConfiguration.h new file mode 100644 index 00000000000..339bcd63660 --- /dev/null +++ b/samples/client/petstore/cpp-qt5/client/ServerConfiguration.h @@ -0,0 +1,75 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * Representing a Server configuration. + */ +#ifndef SERVERVCONFIGURATION_H +#define SERVERVCONFIGURATION_H +#include +#include +#include +#include +#include "ServerVariable.h" + +class ServerConfiguration { +public: + /** + * @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. + */ + ServerConfiguration(const QString& URL, const QString& description, const QMap& variables) + : _description(description), + _variables(variables), + _URL(URL){} + ServerConfiguration(){} + ~ServerConfiguration(){} + + /** + * Format URL template using given variables. + * + * @param variables A map between a variable name and its value. + * @return Formatted URL. + */ + QString URL() { + QString url = _URL; + if(!_variables.empty()){ + // go through variables and replace placeholders + for (auto const& v : _variables.keys()) { + QString name = v; + ServerVariable serverVariable = _variables.value(v); + QString value = serverVariable._defaultValue; + + if (!serverVariable._enumValues.empty() && !serverVariable._enumValues.contains(value)) { + throw std::runtime_error(QString("The variable " + name + " in the server URL has invalid value " + value + ".").toUtf8()); + } + QRegularExpression regex(QString("\\{" + name + "\\}")); + url = url.replace(regex, value); + + } + return url; + } + return url; + } + + int setDefaultValue(const QString& variable,const QString& value){ + if(_variables.contains(variable)) + return _variables[variable].setDefaultValue(value); + return -1; + } + + QString _description; + QMap _variables; + QString _URL; + +}; +#endif diff --git a/samples/client/petstore/cpp-qt5/client/ServerVariable.h b/samples/client/petstore/cpp-qt5/client/ServerVariable.h new file mode 100644 index 00000000000..7ba32f75c09 --- /dev/null +++ b/samples/client/petstore/cpp-qt5/client/ServerVariable.h @@ -0,0 +1,53 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#ifndef SERVERVARIABLE_H +#define SERVERVARIABLE_H +#include +#include +#include +/** + * Representing a Server Variable for server URL template substitution. + */ +class ServerVariable { +public: + + /** + * @param description A description for the server variable. + * @param defaultValue The default value to use for substitution. + * @param enumValues An enumeration of string values to be used if the substitution options are from a limited set. + */ + ServerVariable(const QString &description, const QString &defaultValue, const QSet &enumValues) + : _defaultValue(defaultValue), + _description(description), + _enumValues(enumValues){} + + ServerVariable(){} + ~ServerVariable(){} + + int setDefaultValue(const QString& value){ + if( _enumValues.contains(value)){ + _defaultValue = value; + return 0; + } + return -2; + } + + QString getDefaultValue(){return _defaultValue;} + QSet getEnumValues(){return _enumValues;} + + + QString _defaultValue; + QString _description; + QSet _enumValues; + +}; +#endif \ No newline at end of file diff --git a/samples/client/petstore/cpp-tizen/.openapi-generator/FILES b/samples/client/petstore/cpp-tizen/.openapi-generator/FILES new file mode 100644 index 00000000000..5435ced1067 --- /dev/null +++ b/samples/client/petstore/cpp-tizen/.openapi-generator/FILES @@ -0,0 +1,29 @@ +doc/Doxyfile +doc/README.md +doc/generateDocumentation.sh +src/ApiResponse.cpp +src/ApiResponse.h +src/Category.cpp +src/Category.h +src/Error.cpp +src/Error.h +src/Helpers.cpp +src/Helpers.h +src/NetClient.cpp +src/NetClient.h +src/Object.h +src/Order.cpp +src/Order.h +src/Pet.cpp +src/Pet.h +src/PetManager.cpp +src/PetManager.h +src/RequestInfo.h +src/StoreManager.cpp +src/StoreManager.h +src/Tag.cpp +src/Tag.h +src/User.cpp +src/User.h +src/UserManager.cpp +src/UserManager.h diff --git a/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION b/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION index 4395ff59232..d99e7162d01 100644 --- a/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION +++ b/samples/client/petstore/cpp-tizen/.openapi-generator/VERSION @@ -1 +1 @@ -3.2.0-SNAPSHOT \ No newline at end of file +5.0.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/cpp-tizen/src/PetManager.cpp b/samples/client/petstore/cpp-tizen/src/PetManager.cpp index 0c6a57eee3f..2f273a21e10 100644 --- a/samples/client/petstore/cpp-tizen/src/PetManager.cpp +++ b/samples/client/petstore/cpp-tizen/src/PetManager.cpp @@ -82,7 +82,7 @@ static bool addPetProcessor(MemoryStruct_s p_chunk, long code, char* errormsg, v } static bool addPetHelper(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData, bool isAsync) { @@ -105,10 +105,10 @@ static bool addPetHelper(char * accessToken, JsonArray* json_array; if (isprimitive("Pet")) { - node = converttoJson(&pet, "Pet", ""); + node = converttoJson(&body, "Pet", ""); } - char *jsonStr = pet.toJson(); + char *jsonStr = body.toJson(); node = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -167,22 +167,22 @@ static bool addPetHelper(char * accessToken, bool PetManager::addPetAsync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData) { return addPetHelper(accessToken, - pet, + body, handler, userData, true); } bool PetManager::addPetSync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData) { return addPetHelper(accessToken, - pet, + body, handler, userData, false); } @@ -796,7 +796,7 @@ static bool updatePetProcessor(MemoryStruct_s p_chunk, long code, char* errormsg } static bool updatePetHelper(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData, bool isAsync) { @@ -819,10 +819,10 @@ static bool updatePetHelper(char * accessToken, JsonArray* json_array; if (isprimitive("Pet")) { - node = converttoJson(&pet, "Pet", ""); + node = converttoJson(&body, "Pet", ""); } - char *jsonStr = pet.toJson(); + char *jsonStr = body.toJson(); node = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -881,22 +881,22 @@ static bool updatePetHelper(char * accessToken, bool PetManager::updatePetAsync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData) { return updatePetHelper(accessToken, - pet, + body, handler, userData, true); } bool PetManager::updatePetSync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData) { return updatePetHelper(accessToken, - pet, + body, handler, userData, false); } diff --git a/samples/client/petstore/cpp-tizen/src/PetManager.h b/samples/client/petstore/cpp-tizen/src/PetManager.h index e3ab9a775b1..93f09544120 100644 --- a/samples/client/petstore/cpp-tizen/src/PetManager.h +++ b/samples/client/petstore/cpp-tizen/src/PetManager.h @@ -28,26 +28,26 @@ public: /*! \brief Add a new pet to the store. *Synchronous* * * - * \param pet Pet object that needs to be added to the store *Required* + * \param body Pet object that needs to be added to the store *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool addPetSync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData); /*! \brief Add a new pet to the store. *Asynchronous* * * - * \param pet Pet object that needs to be added to the store *Required* + * \param body Pet object that needs to be added to the store *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool addPetAsync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData); @@ -165,26 +165,26 @@ bool getPetByIdAsync(char * accessToken, /*! \brief Update an existing pet. *Synchronous* * * - * \param pet Pet object that needs to be added to the store *Required* + * \param body Pet object that needs to be added to the store *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool updatePetSync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData); /*! \brief Update an existing pet. *Asynchronous* * * - * \param pet Pet object that needs to be added to the store *Required* + * \param body Pet object that needs to be added to the store *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool updatePetAsync(char * accessToken, - Pet pet, + Pet body, void(* handler)(Error, void* ) , void* userData); diff --git a/samples/client/petstore/cpp-tizen/src/StoreManager.cpp b/samples/client/petstore/cpp-tizen/src/StoreManager.cpp index 91958248d70..e107ff84434 100644 --- a/samples/client/petstore/cpp-tizen/src/StoreManager.cpp +++ b/samples/client/petstore/cpp-tizen/src/StoreManager.cpp @@ -510,7 +510,7 @@ static bool placeOrderProcessor(MemoryStruct_s p_chunk, long code, char* errorms } static bool placeOrderHelper(char * accessToken, - Order order, + Order body, void(* handler)(Order, Error, void* ) , void* userData, bool isAsync) { @@ -532,10 +532,10 @@ static bool placeOrderHelper(char * accessToken, JsonArray* json_array; if (isprimitive("Order")) { - node = converttoJson(&order, "Order", ""); + node = converttoJson(&body, "Order", ""); } - char *jsonStr = order.toJson(); + char *jsonStr = body.toJson(); node = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -594,22 +594,22 @@ static bool placeOrderHelper(char * accessToken, bool StoreManager::placeOrderAsync(char * accessToken, - Order order, + Order body, void(* handler)(Order, Error, void* ) , void* userData) { return placeOrderHelper(accessToken, - order, + body, handler, userData, true); } bool StoreManager::placeOrderSync(char * accessToken, - Order order, + Order body, void(* handler)(Order, Error, void* ) , void* userData) { return placeOrderHelper(accessToken, - order, + body, handler, userData, false); } diff --git a/samples/client/petstore/cpp-tizen/src/StoreManager.h b/samples/client/petstore/cpp-tizen/src/StoreManager.h index ac172733f73..9736475b381 100644 --- a/samples/client/petstore/cpp-tizen/src/StoreManager.h +++ b/samples/client/petstore/cpp-tizen/src/StoreManager.h @@ -107,26 +107,26 @@ bool getOrderByIdAsync(char * accessToken, /*! \brief Place an order for a pet. *Synchronous* * * - * \param order order placed for purchasing the pet *Required* + * \param body order placed for purchasing the pet *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool placeOrderSync(char * accessToken, - Order order, + Order body, void(* handler)(Order, Error, void* ) , void* userData); /*! \brief Place an order for a pet. *Asynchronous* * * - * \param order order placed for purchasing the pet *Required* + * \param body order placed for purchasing the pet *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool placeOrderAsync(char * accessToken, - Order order, + Order body, void(* handler)(Order, Error, void* ) , void* userData); diff --git a/samples/client/petstore/cpp-tizen/src/UserManager.cpp b/samples/client/petstore/cpp-tizen/src/UserManager.cpp index bd51f9bc051..ab3a7e40964 100644 --- a/samples/client/petstore/cpp-tizen/src/UserManager.cpp +++ b/samples/client/petstore/cpp-tizen/src/UserManager.cpp @@ -82,7 +82,7 @@ static bool createUserProcessor(MemoryStruct_s p_chunk, long code, char* errorms } static bool createUserHelper(char * accessToken, - User user, + User body, void(* handler)(Error, void* ) , void* userData, bool isAsync) { @@ -104,10 +104,10 @@ static bool createUserHelper(char * accessToken, JsonArray* json_array; if (isprimitive("User")) { - node = converttoJson(&user, "User", ""); + node = converttoJson(&body, "User", ""); } - char *jsonStr = user.toJson(); + char *jsonStr = body.toJson(); node = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -166,22 +166,22 @@ static bool createUserHelper(char * accessToken, bool UserManager::createUserAsync(char * accessToken, - User user, + User body, void(* handler)(Error, void* ) , void* userData) { return createUserHelper(accessToken, - user, + body, handler, userData, true); } bool UserManager::createUserSync(char * accessToken, - User user, + User body, void(* handler)(Error, void* ) , void* userData) { return createUserHelper(accessToken, - user, + body, handler, userData, false); } @@ -219,7 +219,7 @@ static bool createUsersWithArrayInputProcessor(MemoryStruct_s p_chunk, long code } static bool createUsersWithArrayInputHelper(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData, bool isAsync) { @@ -240,14 +240,14 @@ static bool createUsersWithArrayInputHelper(char * accessToken, JsonNode* node; JsonArray* json_array; //TODO: Map Container - if (isprimitive("std::list")) { - node = converttoJson(&user, "std::list", "array"); + if (isprimitive("User")) { + node = converttoJson(&body, "User", "array"); } else { node = json_node_alloc(); json_array = json_array_new(); for (std::list - ::iterator bodyIter = user.begin(); bodyIter != user.end(); ++bodyIter) { - std::list itemAt = (*bodyIter); + ::iterator bodyIter = body.begin(); bodyIter != body.end(); ++bodyIter) { + User itemAt = (*bodyIter); char *jsonStr = itemAt.toJson(); JsonNode *node_temp = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -315,22 +315,22 @@ static bool createUsersWithArrayInputHelper(char * accessToken, bool UserManager::createUsersWithArrayInputAsync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData) { return createUsersWithArrayInputHelper(accessToken, - user, + body, handler, userData, true); } bool UserManager::createUsersWithArrayInputSync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData) { return createUsersWithArrayInputHelper(accessToken, - user, + body, handler, userData, false); } @@ -368,7 +368,7 @@ static bool createUsersWithListInputProcessor(MemoryStruct_s p_chunk, long code, } static bool createUsersWithListInputHelper(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData, bool isAsync) { @@ -389,14 +389,14 @@ static bool createUsersWithListInputHelper(char * accessToken, JsonNode* node; JsonArray* json_array; //TODO: Map Container - if (isprimitive("std::list")) { - node = converttoJson(&user, "std::list", "array"); + if (isprimitive("User")) { + node = converttoJson(&body, "User", "array"); } else { node = json_node_alloc(); json_array = json_array_new(); for (std::list - ::iterator bodyIter = user.begin(); bodyIter != user.end(); ++bodyIter) { - std::list itemAt = (*bodyIter); + ::iterator bodyIter = body.begin(); bodyIter != body.end(); ++bodyIter) { + User itemAt = (*bodyIter); char *jsonStr = itemAt.toJson(); JsonNode *node_temp = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -464,22 +464,22 @@ static bool createUsersWithListInputHelper(char * accessToken, bool UserManager::createUsersWithListInputAsync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData) { return createUsersWithListInputHelper(accessToken, - user, + body, handler, userData, true); } bool UserManager::createUsersWithListInputSync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData) { return createUsersWithListInputHelper(accessToken, - user, + body, handler, userData, false); } @@ -1072,7 +1072,7 @@ static bool updateUserProcessor(MemoryStruct_s p_chunk, long code, char* errorms } static bool updateUserHelper(char * accessToken, - std::string username, User user, + std::string username, User body, void(* handler)(Error, void* ) , void* userData, bool isAsync) { @@ -1094,10 +1094,10 @@ static bool updateUserHelper(char * accessToken, JsonArray* json_array; if (isprimitive("User")) { - node = converttoJson(&user, "User", ""); + node = converttoJson(&body, "User", ""); } - char *jsonStr = user.toJson(); + char *jsonStr = body.toJson(); node = json_from_string(jsonStr, NULL); g_free(static_cast(jsonStr)); @@ -1162,22 +1162,22 @@ static bool updateUserHelper(char * accessToken, bool UserManager::updateUserAsync(char * accessToken, - std::string username, User user, + std::string username, User body, void(* handler)(Error, void* ) , void* userData) { return updateUserHelper(accessToken, - username, user, + username, body, handler, userData, true); } bool UserManager::updateUserSync(char * accessToken, - std::string username, User user, + std::string username, User body, void(* handler)(Error, void* ) , void* userData) { return updateUserHelper(accessToken, - username, user, + username, body, handler, userData, false); } diff --git a/samples/client/petstore/cpp-tizen/src/UserManager.h b/samples/client/petstore/cpp-tizen/src/UserManager.h index 7429af29f3a..0b72c159294 100644 --- a/samples/client/petstore/cpp-tizen/src/UserManager.h +++ b/samples/client/petstore/cpp-tizen/src/UserManager.h @@ -28,26 +28,26 @@ public: /*! \brief Create user. *Synchronous* * * This can only be done by the logged in user. - * \param user Created user object *Required* + * \param body Created user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool createUserSync(char * accessToken, - User user, + User body, void(* handler)(Error, void* ) , void* userData); /*! \brief Create user. *Asynchronous* * * This can only be done by the logged in user. - * \param user Created user object *Required* + * \param body Created user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool createUserAsync(char * accessToken, - User user, + User body, void(* handler)(Error, void* ) , void* userData); @@ -55,26 +55,26 @@ bool createUserAsync(char * accessToken, /*! \brief Creates list of users with given input array. *Synchronous* * * - * \param user List of user object *Required* + * \param body List of user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool createUsersWithArrayInputSync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData); /*! \brief Creates list of users with given input array. *Asynchronous* * * - * \param user List of user object *Required* + * \param body List of user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool createUsersWithArrayInputAsync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData); @@ -82,26 +82,26 @@ bool createUsersWithArrayInputAsync(char * accessToken, /*! \brief Creates list of users with given input array. *Synchronous* * * - * \param user List of user object *Required* + * \param body List of user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool createUsersWithListInputSync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData); /*! \brief Creates list of users with given input array. *Asynchronous* * * - * \param user List of user object *Required* + * \param body List of user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool createUsersWithListInputAsync(char * accessToken, - std::list user, + std::list body, void(* handler)(Error, void* ) , void* userData); @@ -218,13 +218,13 @@ bool logoutUserAsync(char * accessToken, * * This can only be done by the logged in user. * \param username name that need to be deleted *Required* - * \param user Updated user object *Required* + * \param body Updated user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool updateUserSync(char * accessToken, - std::string username, User user, + std::string username, User body, void(* handler)(Error, void* ) , void* userData); @@ -232,13 +232,13 @@ bool updateUserSync(char * accessToken, * * This can only be done by the logged in user. * \param username name that need to be deleted *Required* - * \param user Updated user object *Required* + * \param body Updated user object *Required* * \param handler The callback function to be invoked on completion. *Required* * \param accessToken The Authorization token. *Required* * \param userData The user data to be passed to the callback function. */ bool updateUserAsync(char * accessToken, - std::string username, User user, + std::string username, User body, void(* handler)(Error, void* ) , void* userData); diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApi.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApi.cpp index a0a0cdd962e..5e5602316f7 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApi.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIPetApi.cpp @@ -65,7 +65,11 @@ void OpenAPIPetApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceede FString ContentType = HttpResponse->GetContentType(); FString Content; - if (ContentType == TEXT("application/json")) + if (ContentType.IsEmpty()) + { + return; // Nothing to parse + } + else if (ContentType.StartsWith(TEXT("application/json")) || ContentType.StartsWith("text/json")) { Content = HttpResponse->GetContentAsString(); @@ -78,7 +82,7 @@ void OpenAPIPetApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceede return; // Successfully parsed } } - else if(ContentType == TEXT("text/plain")) + else if(ContentType.StartsWith(TEXT("text/plain"))) { Content = HttpResponse->GetContentAsString(); InOutResponse.SetResponseString(Content); diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIStoreApi.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIStoreApi.cpp index ace92ce8339..293034324c4 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIStoreApi.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIStoreApi.cpp @@ -65,7 +65,11 @@ void OpenAPIStoreApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSuccee FString ContentType = HttpResponse->GetContentType(); FString Content; - if (ContentType == TEXT("application/json")) + if (ContentType.IsEmpty()) + { + return; // Nothing to parse + } + else if (ContentType.StartsWith(TEXT("application/json")) || ContentType.StartsWith("text/json")) { Content = HttpResponse->GetContentAsString(); @@ -78,7 +82,7 @@ void OpenAPIStoreApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSuccee return; // Successfully parsed } } - else if(ContentType == TEXT("text/plain")) + else if(ContentType.StartsWith(TEXT("text/plain"))) { Content = HttpResponse->GetContentAsString(); InOutResponse.SetResponseString(Content); diff --git a/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApi.cpp b/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApi.cpp index c079f042d92..68a6888c669 100644 --- a/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApi.cpp +++ b/samples/client/petstore/cpp-ue4/Private/OpenAPIUserApi.cpp @@ -65,7 +65,11 @@ void OpenAPIUserApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceed FString ContentType = HttpResponse->GetContentType(); FString Content; - if (ContentType == TEXT("application/json")) + if (ContentType.IsEmpty()) + { + return; // Nothing to parse + } + else if (ContentType.StartsWith(TEXT("application/json")) || ContentType.StartsWith("text/json")) { Content = HttpResponse->GetContentAsString(); @@ -78,7 +82,7 @@ void OpenAPIUserApi::HandleResponse(FHttpResponsePtr HttpResponse, bool bSucceed return; // Successfully parsed } } - else if(ContentType == TEXT("text/plain")) + else if(ContentType.StartsWith(TEXT("text/plain"))) { Content = HttpResponse->GetContentAsString(); InOutResponse.SetResponseString(Content); diff --git a/samples/server/petstore/cpp-restbed/.openapi-generator/FILES b/samples/server/petstore/cpp-restbed/.openapi-generator/FILES new file mode 100644 index 00000000000..f4948ccd7a2 --- /dev/null +++ b/samples/server/petstore/cpp-restbed/.openapi-generator/FILES @@ -0,0 +1,21 @@ +.gitignore +README.md +api/PetApi.cpp +api/PetApi.h +api/StoreApi.cpp +api/StoreApi.h +api/UserApi.cpp +api/UserApi.h +git_push.sh +model/ApiResponse.cpp +model/ApiResponse.h +model/Category.cpp +model/Category.h +model/Order.cpp +model/Order.h +model/Pet.cpp +model/Pet.h +model/Tag.cpp +model/Tag.h +model/User.cpp +model/User.h