forked from loafle/openapi-generator-original
[C++] [Qt5] Add initial version of File upload and download for Qt5 client (#3853)
* Add initial version of File upload and download for Qt5 client * Update after reviews * Remove unused header
This commit is contained in:
parent
3f9d1b1fec
commit
ba7fc2396b
@ -26,7 +26,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
protected Set<String> systemIncludes = new HashSet<String>();
|
protected Set<String> systemIncludes = new HashSet<String>();
|
||||||
|
|
||||||
protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
|
protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
|
||||||
|
|
||||||
public CppQt5AbstractCodegen() {
|
public CppQt5AbstractCodegen() {
|
||||||
super();
|
super();
|
||||||
// set modelNamePrefix as default for QHttpEngine Server
|
// set modelNamePrefix as default for QHttpEngine Server
|
||||||
@ -61,10 +61,10 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
"double")
|
"double")
|
||||||
);
|
);
|
||||||
nonFrameworkPrimitives.addAll(languageSpecificPrimitives);
|
nonFrameworkPrimitives.addAll(languageSpecificPrimitives);
|
||||||
|
|
||||||
foundationClasses.addAll(
|
foundationClasses.addAll(
|
||||||
Arrays.asList(
|
Arrays.asList(
|
||||||
"QString",
|
"QString",
|
||||||
"QDate",
|
"QDate",
|
||||||
"QDateTime",
|
"QDateTime",
|
||||||
"QByteArray")
|
"QByteArray")
|
||||||
@ -78,7 +78,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
typeMapping.put("integer", "qint32");
|
typeMapping.put("integer", "qint32");
|
||||||
typeMapping.put("long", "qint64");
|
typeMapping.put("long", "qint64");
|
||||||
typeMapping.put("boolean", "bool");
|
typeMapping.put("boolean", "bool");
|
||||||
typeMapping.put("number", "double");
|
typeMapping.put("number", "double");
|
||||||
typeMapping.put("array", "QList");
|
typeMapping.put("array", "QList");
|
||||||
typeMapping.put("map", "QMap");
|
typeMapping.put("map", "QMap");
|
||||||
typeMapping.put("object", PREFIX + "Object");
|
typeMapping.put("object", PREFIX + "Object");
|
||||||
@ -90,8 +90,8 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
// modifications on multiple templates)
|
// modifications on multiple templates)
|
||||||
typeMapping.put("UUID", "QString");
|
typeMapping.put("UUID", "QString");
|
||||||
typeMapping.put("URI", "QString");
|
typeMapping.put("URI", "QString");
|
||||||
typeMapping.put("file", "QIODevice");
|
typeMapping.put("file", "QByteArray");
|
||||||
typeMapping.put("binary", "QIODevice");
|
typeMapping.put("binary", "QByteArray");
|
||||||
importMapping = new HashMap<String, String>();
|
importMapping = new HashMap<String, String>();
|
||||||
namespaces = new HashMap<String, String>();
|
namespaces = new HashMap<String, String>();
|
||||||
|
|
||||||
@ -101,7 +101,6 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
systemIncludes.add("QDate");
|
systemIncludes.add("QDate");
|
||||||
systemIncludes.add("QDateTime");
|
systemIncludes.add("QDateTime");
|
||||||
systemIncludes.add("QByteArray");
|
systemIncludes.add("QByteArray");
|
||||||
systemIncludes.add("QIODevice");
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void processOpts() {
|
public void processOpts() {
|
||||||
@ -119,7 +118,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
additionalProperties().put("prefix", modelNamePrefix);
|
additionalProperties().put("prefix", modelNamePrefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toModelImport(String name) {
|
public String toModelImport(String name) {
|
||||||
if( name.isEmpty() ) {
|
if( name.isEmpty() ) {
|
||||||
@ -140,7 +139,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
|
|
||||||
return "#include \"" + folder + name + ".h\"";
|
return "#include \"" + folder + name + ".h\"";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
* Optional - type declaration. This is a String which is used by the templates to instantiate your
|
||||||
* types. There is typically special handling for different property types
|
* types. There is typically special handling for different property types
|
||||||
@ -160,9 +159,9 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||||
} else if (ModelUtils.isBinarySchema(p)) {
|
} else if (ModelUtils.isBinarySchema(p)) {
|
||||||
return getSchemaType(p) + "*";
|
return getSchemaType(p);
|
||||||
} else if (ModelUtils.isFileSchema(p)) {
|
} else if (ModelUtils.isFileSchema(p)) {
|
||||||
return getSchemaType(p) + "*";
|
return getSchemaType(p);
|
||||||
}
|
}
|
||||||
if (foundationClasses.contains(openAPIType)) {
|
if (foundationClasses.contains(openAPIType)) {
|
||||||
return openAPIType;
|
return openAPIType;
|
||||||
@ -174,7 +173,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public String toDefaultValue(Schema p) {
|
public String toDefaultValue(Schema p) {
|
||||||
if (ModelUtils.isBooleanSchema(p)) {
|
if (ModelUtils.isBooleanSchema(p)) {
|
||||||
return "false";
|
return "false";
|
||||||
@ -211,7 +210,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public String toModelFilename(String name) {
|
public String toModelFilename(String name) {
|
||||||
return toModelName(name);
|
return toModelName(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Schema` into
|
* Optional - OpenAPI type conversion. This is used to map OpenAPI types in a `Schema` into
|
||||||
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
* either language specific types via `typeMapping` or into complex models if there is not a mapping.
|
||||||
@ -219,7 +218,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
* @return a string value of the type or complex model for this property
|
* @return a string value of the type or complex model for this property
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("rawtypes")
|
@SuppressWarnings("rawtypes")
|
||||||
public String getSchemaType(Schema p) {
|
public String getSchemaType(Schema p) {
|
||||||
String openAPIType = super.getSchemaType(p);
|
String openAPIType = super.getSchemaType(p);
|
||||||
|
|
||||||
@ -242,7 +241,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public String toVarName(String name) {
|
public String toVarName(String name) {
|
||||||
// sanitize name
|
// sanitize name
|
||||||
String varName = name;
|
String varName = name;
|
||||||
varName = sanitizeName(name);
|
varName = sanitizeName(name);
|
||||||
|
|
||||||
// if it's all uppper case, convert to lower case
|
// if it's all uppper case, convert to lower case
|
||||||
if (varName.matches("^[A-Z_]*$")) {
|
if (varName.matches("^[A-Z_]*$")) {
|
||||||
@ -270,7 +269,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public String getTypeDeclaration(String str) {
|
public String getTypeDeclaration(String str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean needToImport(String type) {
|
protected boolean needToImport(String type) {
|
||||||
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
|
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
|
||||||
@ -283,7 +282,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> objs, List<Object> allModels) {
|
||||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||||
|
|
||||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||||
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel> ();
|
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel> ();
|
||||||
for(Object moObj : allModels) {
|
for(Object moObj : allModels) {
|
||||||
@ -298,7 +297,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
operation.vendorExtensions.put("returnsEnum", true);
|
operation.vendorExtensions.put("returnsEnum", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check all return parameter baseType if there is a necessity to include, include it if not
|
// Check all return parameter baseType if there is a necessity to include, include it if not
|
||||||
// already done
|
// already done
|
||||||
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||||
if(!isIncluded(operation.returnBaseType, imports)) {
|
if(!isIncluded(operation.returnBaseType, imports)) {
|
||||||
@ -308,7 +307,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
|
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
|
||||||
if (operation.allParams != null)params.addAll(operation.allParams);
|
if (operation.allParams != null)params.addAll(operation.allParams);
|
||||||
|
|
||||||
// Check all parameter baseType if there is a necessity to include, include it if not
|
// Check all parameter baseType if there is a necessity to include, include it if not
|
||||||
// already done
|
// already done
|
||||||
for(CodegenParameter param : params) {
|
for(CodegenParameter param : params) {
|
||||||
if(param.isPrimitiveType && needToImport(param.baseType)) {
|
if(param.isPrimitiveType && needToImport(param.baseType)) {
|
||||||
@ -321,7 +320,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
// We use QString to pass path params, add it to include
|
// We use QString to pass path params, add it to include
|
||||||
if(!isIncluded("QString", imports)) {
|
if(!isIncluded("QString", imports)) {
|
||||||
imports.add(createMapping("import", "QString"));
|
imports.add(createMapping("import", "QString"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(isIncluded("QMap", imports)) {
|
if(isIncluded("QMap", imports)) {
|
||||||
@ -332,7 +331,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
}
|
}
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
return postProcessModelsEnum(objs);
|
return postProcessModelsEnum(objs);
|
||||||
@ -342,18 +341,18 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
|||||||
public String toEnumValue(String value, String datatype) {
|
public String toEnumValue(String value, String datatype) {
|
||||||
return escapeText(value);
|
return escapeText(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDataTypeString(String dataType) {
|
public boolean isDataTypeString(String dataType) {
|
||||||
return "QString".equals(dataType);
|
return "QString".equals(dataType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, String> createMapping(String key, String value) {
|
private Map<String, String> createMapping(String key, String value) {
|
||||||
Map<String, String> customImport = new HashMap<String, String>();
|
Map<String, String> customImport = new HashMap<String, String>();
|
||||||
customImport.put(key, toModelImport(value));
|
customImport.put(key, toModelImport(value));
|
||||||
return customImport;
|
return customImport;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isIncluded(String type, List<Map<String, String>> imports) {
|
private boolean isIncluded(String type, List<Map<String, String>> imports) {
|
||||||
boolean included = false;
|
boolean included = false;
|
||||||
String inclStr = toModelImport(type);
|
String inclStr = toModelImport(type);
|
||||||
|
@ -76,14 +76,15 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, PREFIX + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
||||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp"));
|
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp"));
|
||||||
|
supportingFiles.add(new SupportingFile("HttpFileElement.h.mustache", sourceFolder, PREFIX + "HttpFileElement.h"));
|
||||||
|
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("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
||||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
||||||
if (optionalProjectFileFlag) {
|
if (optionalProjectFileFlag) {
|
||||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
||||||
}
|
}
|
||||||
typeMapping.put("file", PREFIX + "HttpRequestInputFileElement");
|
typeMapping.put("file", PREFIX + "HttpFileElement");
|
||||||
typeMapping.put("binary", PREFIX +"HttpRequestInputFileElement");
|
importMapping.put(PREFIX + "HttpFileElement", "#include \"" + PREFIX + "HttpFileElement.h\"");
|
||||||
importMapping.put(PREFIX + "HttpRequestInputFileElement", "#include \"" + PREFIX + "HttpRequest.h\"");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -95,7 +96,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
} else {
|
} else {
|
||||||
additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag);
|
additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||||
supportingFiles.clear();
|
supportingFiles.clear();
|
||||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, modelNamePrefix + "Helpers.h"));
|
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, modelNamePrefix + "Helpers.h"));
|
||||||
@ -103,11 +104,10 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
|||||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, modelNamePrefix + "HttpRequest.h"));
|
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, modelNamePrefix + "HttpRequest.h"));
|
||||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
||||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
||||||
|
|
||||||
typeMapping.put("file", modelNamePrefix + "HttpRequestInputFileElement");
|
typeMapping.put("file", modelNamePrefix + "HttpFileElement");
|
||||||
typeMapping.put("binary", modelNamePrefix + "HttpRequestInputFileElement");
|
importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\"");
|
||||||
importMapping.put(modelNamePrefix + "HttpRequestInputFileElement", "#include \"" + modelNamePrefix + "HttpRequest.h\"");
|
|
||||||
if (optionalProjectFileFlag) {
|
if (optionalProjectFileFlag) {
|
||||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, modelNamePrefix + "client.pri"));
|
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, modelNamePrefix + "client.pri"));
|
||||||
}
|
}
|
||||||
|
@ -76,7 +76,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
apiTemplateFiles.put(
|
apiTemplateFiles.put(
|
||||||
"apirequest.h.mustache", // the template to use
|
"apirequest.h.mustache", // the template to use
|
||||||
".h"); // the extension for each file to write
|
".h"); // the extension for each file to write
|
||||||
|
|
||||||
apiTemplateFiles.put(
|
apiTemplateFiles.put(
|
||||||
"apirequest.cpp.mustache", // the template to use
|
"apirequest.cpp.mustache", // the template to use
|
||||||
".cpp"); // the extension for each file to write
|
".cpp"); // the extension for each file to write
|
||||||
@ -86,11 +86,13 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
* will use the resource stream to attempt to read the templates.
|
* will use the resource stream to attempt to read the templates.
|
||||||
*/
|
*/
|
||||||
embeddedTemplateDir = templateDir = "cpp-qt5-qhttpengine-server";
|
embeddedTemplateDir = templateDir = "cpp-qt5-qhttpengine-server";
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
||||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
||||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, PREFIX + "Enum.h"));
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, PREFIX + "Enum.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("HttpFileElement.h.mustache", sourceFolder + MODEL_DIR, PREFIX + "HttpFileElement.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder + MODEL_DIR, PREFIX + "HttpFileElement.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.h"));
|
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.h"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.cpp"));
|
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.cpp"));
|
||||||
|
|
||||||
@ -102,6 +104,8 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||||
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
||||||
|
typeMapping.put("file", PREFIX + "HttpFileElement");
|
||||||
|
importMapping.put(PREFIX + "HttpFileElement", "#include \"" + PREFIX + "HttpFileElement.h\"");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,9 +119,12 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.h"));
|
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.h"));
|
||||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Enum.h"));
|
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Enum.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("HttpFileElement.h.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "HttpFileElement.h"));
|
||||||
|
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "HttpFileElement.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.h"));
|
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.h"));
|
||||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.cpp"));
|
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.cpp"));
|
||||||
|
|
||||||
|
|
||||||
supportingFiles.add(new SupportingFile("main.cpp.mustache", sourceFolder + SRC_DIR, "main.cpp"));
|
supportingFiles.add(new SupportingFile("main.cpp.mustache", sourceFolder + SRC_DIR, "main.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("src-CMakeLists.txt.mustache", sourceFolder + SRC_DIR, "CMakeLists.txt"));
|
supportingFiles.add(new SupportingFile("src-CMakeLists.txt.mustache", sourceFolder + SRC_DIR, "CMakeLists.txt"));
|
||||||
supportingFiles.add(new SupportingFile("README.md.mustache", sourceFolder, "README.MD"));
|
supportingFiles.add(new SupportingFile("README.md.mustache", sourceFolder, "README.MD"));
|
||||||
@ -125,6 +132,8 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt"));
|
||||||
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
supportingFiles.add(new SupportingFile("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||||
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
supportingFiles.add(new SupportingFile("LICENSE.txt.mustache", sourceFolder, "LICENSE.txt"));
|
||||||
|
typeMapping.put("file", modelNamePrefix + "HttpFileElement");
|
||||||
|
importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +169,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
public String getHelp() {
|
public String getHelp() {
|
||||||
return "Generates a Qt5 C++ Server using the QHTTPEngine HTTP Library.";
|
return "Generates a Qt5 C++ Server using the QHTTPEngine HTTP Library.";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Location to write model files. You can use the modelPackage() as defined when the class is
|
* Location to write model files. You can use the modelPackage() as defined when the class is
|
||||||
* instantiated
|
* instantiated
|
||||||
@ -182,7 +191,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
private String requestFileFolder() {
|
private String requestFileFolder() {
|
||||||
return outputFolder + "/" + sourceFolder + APIREQUEST_DIR + "/" + apiPackage().replace("::", File.separator);
|
return outputFolder + "/" + sourceFolder + APIREQUEST_DIR + "/" + apiPackage().replace("::", File.separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String apiFilename(String templateName, String tag) {
|
public String apiFilename(String templateName, String tag) {
|
||||||
String result = super.apiFilename(templateName, tag);
|
String result = super.apiFilename(templateName, tag);
|
||||||
@ -193,7 +202,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toApiFilename(String name) {
|
public String toApiFilename(String name) {
|
||||||
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";
|
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";
|
||||||
|
155
modules/openapi-generator/src/main/resources/cpp-qt5-client/HttpFileElement.cpp.mustache
vendored
Normal file
155
modules/openapi-generator/src/main/resources/cpp-qt5-client/HttpFileElement.cpp.mustache
vendored
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
{{>licenseInfo}}
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "{{prefix}}HttpFileElement.h"
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
namespace {{this}} {
|
||||||
|
{{/cppNamespaceDeclarations}}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setMimeType(const QString &mime){
|
||||||
|
mime_type = mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setFileName(const QString &name){
|
||||||
|
local_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setVariableName(const QString &name){
|
||||||
|
variable_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setRequestFileName(const QString &name){
|
||||||
|
request_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::isSet() const {
|
||||||
|
return !local_filename.isEmpty() || !request_filename.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
{{prefix}}HttpFileElement::asJson() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QString(bArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
{{prefix}}HttpFileElement::asJsonValue() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QJsonDocument::fromBinaryData(bArray.data()).object();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::fromStringValue(const QString &instr){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(instr.toUtf8());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::fromJsonValue(const QJsonValue &jval) {
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(QJsonDocument(jval.toObject()).toBinaryData());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
{{prefix}}HttpFileElement::asByteArray() const {
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return bArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::fromByteArray(const QByteArray& bytes){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()){
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(bytes);
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray& bytes){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return fromByteArray(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
{{prefix}}HttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return asByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
}
|
||||||
|
{{/cppNamespaceDeclarations}}
|
42
modules/openapi-generator/src/main/resources/cpp-qt5-client/HttpFileElement.h.mustache
vendored
Normal file
42
modules/openapi-generator/src/main/resources/cpp-qt5-client/HttpFileElement.h.mustache
vendored
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
{{>licenseInfo}}
|
||||||
|
#ifndef {{prefix}}_HTTP_FILE_ELEMENT_H
|
||||||
|
#define {{prefix}}_HTTP_FILE_ELEMENT_H
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
namespace {{this}} {
|
||||||
|
{{/cppNamespaceDeclarations}}
|
||||||
|
|
||||||
|
class {{prefix}}HttpFileElement {
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString variable_name;
|
||||||
|
QString local_filename;
|
||||||
|
QString request_filename;
|
||||||
|
QString mime_type;
|
||||||
|
void setMimeType(const QString &mime);
|
||||||
|
void setFileName(const QString &name);
|
||||||
|
void setVariableName(const QString &name);
|
||||||
|
void setRequestFileName(const QString &name);
|
||||||
|
bool isSet() const;
|
||||||
|
bool fromStringValue(const QString &instr);
|
||||||
|
bool fromJsonValue(const QJsonValue &jval);
|
||||||
|
bool fromByteArray(const QByteArray& bytes);
|
||||||
|
bool saveToFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime, const QByteArray& bytes);
|
||||||
|
QString asJson() const;
|
||||||
|
QJsonValue asJsonValue() const;
|
||||||
|
QByteArray asByteArray() const;
|
||||||
|
QByteArray loadFromFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime);
|
||||||
|
};
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
}
|
||||||
|
{{/cppNamespaceDeclarations}}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE({{#cppNamespaceDeclarations}}{{this}}::{{/cppNamespaceDeclarations}}{{prefix}}HttpFileElement)
|
||||||
|
|
||||||
|
#endif // {{prefix}}_HTTP_FILE_ELEMENT_H
|
@ -1,11 +1,16 @@
|
|||||||
{{>licenseInfo}}
|
{{>licenseInfo}}
|
||||||
#include "{{prefix}}HttpRequest.h"
|
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QUuid>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include "{{prefix}}HttpRequest.h"
|
||||||
|
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
@ -32,7 +37,7 @@ void {{prefix}}HttpRequestInput::add_var(QString key, QString value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
|
void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
|
||||||
{{prefix}}HttpRequestInputFileElement file;
|
{{prefix}}HttpFileElement file;
|
||||||
file.variable_name = variable_name;
|
file.variable_name = variable_name;
|
||||||
file.local_filename = local_filename;
|
file.local_filename = local_filename;
|
||||||
file.request_filename = request_filename;
|
file.request_filename = request_filename;
|
||||||
@ -48,6 +53,7 @@ void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_f
|
|||||||
timeout = 0;
|
timeout = 0;
|
||||||
timer = new QTimer();
|
timer = new QTimer();
|
||||||
manager = new QNetworkAccessManager(this);
|
manager = new QNetworkAccessManager(this);
|
||||||
|
workingDirectory = QDir::currentPath();
|
||||||
connect(manager, &QNetworkAccessManager::finished, this, &{{prefix}}HttpRequestWorker::on_manager_finished);
|
connect(manager, &QNetworkAccessManager::finished, this, &{{prefix}}HttpRequestWorker::on_manager_finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,16 +64,50 @@ void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_f
|
|||||||
}
|
}
|
||||||
timer->deleteLater();
|
timer->deleteLater();
|
||||||
}
|
}
|
||||||
|
for (const auto & item: multiPartFields) {
|
||||||
|
if(item != nullptr) {
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> {{prefix}}HttpRequestWorker::getResponseHeaders() const {
|
QMap<QString, QString> {{prefix}}HttpRequestWorker::getResponseHeaders() const {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{prefix}}HttpFileElement {{prefix}}HttpRequestWorker::getHttpFileElement(const QString &fieldname){
|
||||||
|
if(!files.isEmpty()){
|
||||||
|
if(fieldname.isEmpty()){
|
||||||
|
return files.first();
|
||||||
|
}else if (files.contains(fieldname)){
|
||||||
|
return files[fieldname];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OAIHttpFileElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray *{{prefix}}HttpRequestWorker::getMultiPartField(const QString &fieldname){
|
||||||
|
if(!multiPartFields.isEmpty()){
|
||||||
|
if(fieldname.isEmpty()){
|
||||||
|
return multiPartFields.first();
|
||||||
|
}else if (multiPartFields.contains(fieldname)){
|
||||||
|
return multiPartFields[fieldname];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void {{prefix}}HttpRequestWorker::setTimeOut(int tout){
|
void {{prefix}}HttpRequestWorker::setTimeOut(int tout){
|
||||||
timeout = tout;
|
timeout = tout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void {{prefix}}HttpRequestWorker::setWorkingDirectory(const QString &path){
|
||||||
|
if(!path.isEmpty()){
|
||||||
|
workingDirectory = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString {{prefix}}HttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
|
QString {{prefix}}HttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
|
||||||
// result structure follows RFC 5987
|
// result structure follows RFC 5987
|
||||||
bool need_utf_encoding = false;
|
bool need_utf_encoding = false;
|
||||||
@ -196,7 +236,7 @@ void {{prefix}}HttpRequestWorker::execute({{prefix}}HttpRequestInput *input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add files
|
// add files
|
||||||
for (QList<{{prefix}}HttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
|
for (QList<{{prefix}}HttpFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
|
||||||
QFileInfo fi(file_info->local_filename);
|
QFileInfo fi(file_info->local_filename);
|
||||||
|
|
||||||
// ensure necessary variables are available
|
// ensure necessary variables are available
|
||||||
@ -276,8 +316,13 @@ void {{prefix}}HttpRequestWorker::execute({{prefix}}HttpRequestInput *input) {
|
|||||||
request.setRawHeader(key.toStdString().c_str(), input->headers.value(key).toStdString().c_str());
|
request.setRawHeader(key.toStdString().c_str(), input->headers.value(key).toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_content.size() > 0 && !isFormData) {
|
if (request_content.size() > 0 && !isFormData && (input->var_layout != MULTIPART)) {
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
if(!input->headers.contains("Content-Type")){
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, input->headers.value("Content-Type"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (input->var_layout == URL_ENCODED) {
|
else if (input->var_layout == URL_ENCODED) {
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
@ -331,9 +376,10 @@ void {{prefix}}HttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
process_form_response();
|
||||||
emit on_execution_finished(this);
|
emit on_execution_finished(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void {{prefix}}HttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
void {{prefix}}HttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
||||||
error_type = QNetworkReply::TimeoutError;
|
error_type = QNetworkReply::TimeoutError;
|
||||||
response = "";
|
response = "";
|
||||||
@ -341,9 +387,37 @@ void {{prefix}}HttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
|||||||
disconnect(manager, nullptr, nullptr, nullptr);
|
disconnect(manager, nullptr, nullptr, nullptr);
|
||||||
reply->abort();
|
reply->abort();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
emit on_execution_finished(this);
|
emit on_execution_finished(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void {{prefix}}HttpRequestWorker::process_form_response() {
|
||||||
|
if(getResponseHeaders().contains(QString("Content-Disposition")) ) {
|
||||||
|
auto contentDisposition = getResponseHeaders().value(QString("Content-Disposition").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||||
|
auto contentType = getResponseHeaders().contains(QString("Content-Type")) ? getResponseHeaders().value(QString("Content-Type").toUtf8()).split(QString(";"), QString::SkipEmptyParts).first() : QString();
|
||||||
|
if((contentDisposition.count() > 0) && (contentDisposition.first() == QString("attachment"))){
|
||||||
|
QString filename = QUuid::createUuid().toString();
|
||||||
|
for(const auto &file : contentDisposition){
|
||||||
|
if(file.contains(QString("filename"))){
|
||||||
|
filename = file.split(QString("="), QString::SkipEmptyParts).at(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{{prefix}}HttpFileElement felement;
|
||||||
|
felement.saveToFile(QString(), workingDirectory + QDir::separator() + filename, filename, contentType, response.data());
|
||||||
|
files.insert(filename, felement);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(getResponseHeaders().contains(QString("Content-Type")) ) {
|
||||||
|
auto contentType = getResponseHeaders().value(QString("Content-Type").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||||
|
if((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))){
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QSslConfiguration* {{prefix}}HttpRequestWorker::sslDefaultConfiguration;
|
QSslConfiguration* {{prefix}}HttpRequestWorker::sslDefaultConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
|
|
||||||
|
#include "{{prefix}}HttpFileElement.h"
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
@ -23,16 +24,6 @@ namespace {{this}} {
|
|||||||
|
|
||||||
enum {{prefix}}HttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
|
enum {{prefix}}HttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
|
||||||
|
|
||||||
class {{prefix}}HttpRequestInputFileElement {
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString variable_name;
|
|
||||||
QString local_filename;
|
|
||||||
QString request_filename;
|
|
||||||
QString mime_type;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class {{prefix}}HttpRequestInput {
|
class {{prefix}}HttpRequestInput {
|
||||||
|
|
||||||
@ -42,7 +33,7 @@ public:
|
|||||||
{{prefix}}HttpRequestVarLayout var_layout;
|
{{prefix}}HttpRequestVarLayout var_layout;
|
||||||
QMap<QString, QString> vars;
|
QMap<QString, QString> vars;
|
||||||
QMap<QString, QString> headers;
|
QMap<QString, QString> headers;
|
||||||
QList<{{prefix}}HttpRequestInputFileElement> files;
|
QList<{{prefix}}HttpFileElement> files;
|
||||||
QByteArray request_body;
|
QByteArray request_body;
|
||||||
|
|
||||||
{{prefix}}HttpRequestInput();
|
{{prefix}}HttpRequestInput();
|
||||||
@ -65,19 +56,26 @@ public:
|
|||||||
explicit {{prefix}}HttpRequestWorker(QObject *parent = nullptr);
|
explicit {{prefix}}HttpRequestWorker(QObject *parent = nullptr);
|
||||||
virtual ~{{prefix}}HttpRequestWorker();
|
virtual ~{{prefix}}HttpRequestWorker();
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> getResponseHeaders() const;
|
QMap<QString, QString> getResponseHeaders() const;
|
||||||
QString http_attribute_encode(QString attribute_name, QString input);
|
QString http_attribute_encode(QString attribute_name, QString input);
|
||||||
void execute({{prefix}}HttpRequestInput *input);
|
void execute({{prefix}}HttpRequestInput *input);
|
||||||
static QSslConfiguration* sslDefaultConfiguration;
|
static QSslConfiguration* sslDefaultConfiguration;
|
||||||
void setTimeOut(int tout);
|
void setTimeOut(int tout);
|
||||||
|
void setWorkingDirectory(const QString &path);
|
||||||
|
{{prefix}}HttpFileElement getHttpFileElement(const QString &fieldname = QString());
|
||||||
|
QByteArray* getMultiPartField(const QString &fieldname = QString());
|
||||||
signals:
|
signals:
|
||||||
void on_execution_finished({{prefix}}HttpRequestWorker *worker);
|
void on_execution_finished({{prefix}}HttpRequestWorker *worker);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *manager;
|
||||||
QMap<QByteArray, QByteArray> headers;
|
QMap<QString, QString> headers;
|
||||||
|
QMap<QString, OAIHttpFileElement> files;
|
||||||
|
QMap<QString, QByteArray*> multiPartFields;
|
||||||
|
QString workingDirectory;
|
||||||
int timeout;
|
int timeout;
|
||||||
void on_manager_timeout(QNetworkReply *reply);
|
void on_manager_timeout(QNetworkReply *reply);
|
||||||
|
void process_form_response();
|
||||||
private slots:
|
private slots:
|
||||||
void on_manager_finished(QNetworkReply *reply);
|
void on_manager_finished(QNetworkReply *reply);
|
||||||
};
|
};
|
||||||
|
@ -18,8 +18,9 @@ HEADERS += \
|
|||||||
# Others
|
# Others
|
||||||
$${PWD}/{{prefix}}Helpers.h \
|
$${PWD}/{{prefix}}Helpers.h \
|
||||||
$${PWD}/{{prefix}}HttpRequest.h \
|
$${PWD}/{{prefix}}HttpRequest.h \
|
||||||
$${PWD}/{{prefix}}Object.h
|
$${PWD}/{{prefix}}Object.h \
|
||||||
$${PWD}/{{prefix}}Enum.h
|
$${PWD}/{{prefix}}Enum.h \
|
||||||
|
$${PWD}/{{prefix}}HttpFileElement.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
# Models
|
# Models
|
||||||
@ -38,5 +39,6 @@ SOURCES += \
|
|||||||
{{/apiInfo}}
|
{{/apiInfo}}
|
||||||
# Others
|
# Others
|
||||||
$${PWD}/{{prefix}}Helpers.cpp \
|
$${PWD}/{{prefix}}Helpers.cpp \
|
||||||
$${PWD}/{{prefix}}HttpRequest.cpp
|
$${PWD}/{{prefix}}HttpRequest.cpp \
|
||||||
|
$${PWD}/{{prefix}}HttpFileElement.cpp
|
||||||
|
|
||||||
|
@ -37,6 +37,10 @@ void {{classname}}::setApiTimeOutMs(const int tout){
|
|||||||
timeout = tout;
|
timeout = tout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void {{classname}}::setWorkingDirectory(const QString& path){
|
||||||
|
workingDirectory = path;
|
||||||
|
}
|
||||||
|
|
||||||
void {{classname}}::addHeaders(const QString& key, const QString& value){
|
void {{classname}}::addHeaders(const QString& key, const QString& value){
|
||||||
defaultHeaders.insert(key, value);
|
defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
@ -104,20 +108,21 @@ void
|
|||||||
{{/collectionFormat}}{{/queryParams}}
|
{{/collectionFormat}}{{/queryParams}}
|
||||||
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this);
|
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
{{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}");
|
{{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}");
|
||||||
{{#formParams}}
|
{{#formParams}}{{^isFile}}
|
||||||
if ({{paramName}} != nullptr) {
|
input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}));{{/isFile}}{{#isFile}}
|
||||||
{{^isFile}}input.add_var("{{baseName}}", {{paramName}});{{/isFile}}{{#isFile}}input.add_file("{{baseName}}", (*{{paramName}}).local_filename, (*{{paramName}}).request_filename, (*{{paramName}}).mime_type);{{/isFile}}
|
input.add_file("{{baseName}}", {{paramName}}.local_filename, {{paramName}}.request_filename, {{paramName}}.mime_type);{{/isFile}}{{/formParams}}
|
||||||
}
|
{{#bodyParams}}
|
||||||
{{/formParams}}{{#bodyParams}}
|
|
||||||
{{#isContainer}}{{#isListContainer}}
|
{{#isContainer}}{{#isListContainer}}
|
||||||
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toArray());{{/isListContainer}}{{#isMapContainer}}
|
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toArray());{{/isListContainer}}{{#isMapContainer}}
|
||||||
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toObject());{{/isMapContainer}}
|
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toObject());{{/isMapContainer}}
|
||||||
QByteArray bytes = doc.toJson();
|
QByteArray bytes = doc.toJson();
|
||||||
input.request_body.append(bytes);
|
input.request_body.append(bytes);
|
||||||
{{/isContainer}}{{^isContainer}}{{#isString}}
|
{{/isContainer}}{{^isContainer}}{{#isString}}
|
||||||
QString output({{paramName}});{{/isString}}{{#isByteArray}}QString output({{paramName}});{{/isByteArray}}{{^isString}}{{^isByteArray}}
|
QString output({{paramName}});{{/isString}}{{#isByteArray}}QString output({{paramName}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}}
|
||||||
QString output = {{paramName}}.asJson();{{/isByteArray}}{{/isString}}
|
QString output = {{paramName}}.asJson();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}}
|
||||||
|
QByteArray output = {{paramName}}.asByteArray();{{/isFile}}
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
{{/isContainer}}{{/bodyParams}}
|
{{/isContainer}}{{/bodyParams}}
|
||||||
{{#headerParams}}
|
{{#headerParams}}
|
||||||
@ -184,7 +189,7 @@ void
|
|||||||
{{/isMapContainer}}
|
{{/isMapContainer}}
|
||||||
{{^isMapContainer}}
|
{{^isMapContainer}}
|
||||||
{{^returnTypeIsPrimitive}}
|
{{^returnTypeIsPrimitive}}
|
||||||
{{{returnType}}} output(QString(worker->response));
|
{{{returnType}}} output{{^isResponseFile}}(QString(worker->response)){{/isResponseFile}}{{#isResponseFile}} = worker->getHttpFileElement(){{/isResponseFile}};
|
||||||
{{/returnTypeIsPrimitive}}
|
{{/returnTypeIsPrimitive}}
|
||||||
{{/isMapContainer}}
|
{{/isMapContainer}}
|
||||||
{{/isListContainer}}
|
{{/isListContainer}}
|
||||||
|
@ -24,6 +24,7 @@ public:
|
|||||||
void setBasePath(const QString& basePath);
|
void setBasePath(const QString& basePath);
|
||||||
void setHost(const QString& host);
|
void setHost(const QString& host);
|
||||||
void setApiTimeOutMs(const int tout);
|
void setApiTimeOutMs(const int tout);
|
||||||
|
void setWorkingDirectory(const QString& path);
|
||||||
void addHeaders(const QString& key, const QString& value);
|
void addHeaders(const QString& key, const QString& value);
|
||||||
|
|
||||||
{{#operations}}{{#operation}}void {{nickname}}({{#allParams}}const {{{dataType}}}& {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
{{#operations}}{{#operation}}void {{nickname}}({{#allParams}}const {{{dataType}}}& {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});
|
||||||
@ -31,6 +32,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QString basePath;
|
QString basePath;
|
||||||
QString host;
|
QString host;
|
||||||
|
QString workingDirectory;
|
||||||
int timeout;
|
int timeout;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> defaultHeaders;
|
||||||
{{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker);
|
{{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker);
|
||||||
|
@ -55,11 +55,23 @@ toStringValue(const double &value){
|
|||||||
return QString::number(value);
|
return QString::number(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const {{prefix}}Object &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
toStringValue(const {{prefix}}Enum &value){
|
toStringValue(const {{prefix}}Enum &value){
|
||||||
return value.asJson();
|
return value.asJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const {{prefix}}HttpFileElement &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonValue
|
QJsonValue
|
||||||
toJsonValue(const QString &value){
|
toJsonValue(const QString &value){
|
||||||
return QJsonValue(value);
|
return QJsonValue(value);
|
||||||
@ -115,6 +127,12 @@ toJsonValue(const {{prefix}}Enum &value){
|
|||||||
return value.asJsonValue();
|
return value.asJsonValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
toJsonValue(const {{prefix}}HttpFileElement &value){
|
||||||
|
return value.asJsonValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromStringValue(const QString &inStr, QString &value){
|
fromStringValue(const QString &inStr, QString &value){
|
||||||
value.clear();
|
value.clear();
|
||||||
@ -209,6 +227,11 @@ fromStringValue(const QString &inStr, {{prefix}}Enum &value){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromStringValue(const QString &inStr, OAIHttpFileElement &value){
|
||||||
|
return value.fromStringValue(inStr);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
@ -337,6 +360,11 @@ fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval){
|
||||||
|
return value.fromJsonValue(jval);
|
||||||
|
}
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
}
|
}
|
||||||
{{/cppNamespaceDeclarations}}
|
{{/cppNamespaceDeclarations}}
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "{{prefix}}Object.h"
|
#include "{{prefix}}Object.h"
|
||||||
#include "{{prefix}}Enum.h"
|
#include "{{prefix}}Enum.h"
|
||||||
|
#include "{{prefix}}HttpFileElement.h"
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
@ -27,7 +29,9 @@ namespace {{this}} {
|
|||||||
QString toStringValue(const bool &value);
|
QString toStringValue(const bool &value);
|
||||||
QString toStringValue(const float &value);
|
QString toStringValue(const float &value);
|
||||||
QString toStringValue(const double &value);
|
QString toStringValue(const double &value);
|
||||||
QString toStringValue(const {{prefix}}Enum &value);
|
QString toStringValue(const {{prefix}}Object &value);
|
||||||
|
QString toStringValue(const {{prefix}}Enum &value);
|
||||||
|
QString toStringValue(const {{prefix}}HttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QString toStringValue(const QList<T> &val) {
|
QString toStringValue(const QList<T> &val) {
|
||||||
@ -52,6 +56,7 @@ namespace {{this}} {
|
|||||||
QJsonValue toJsonValue(const double &value);
|
QJsonValue toJsonValue(const double &value);
|
||||||
QJsonValue toJsonValue(const {{prefix}}Object &value);
|
QJsonValue toJsonValue(const {{prefix}}Object &value);
|
||||||
QJsonValue toJsonValue(const {{prefix}}Enum &value);
|
QJsonValue toJsonValue(const {{prefix}}Enum &value);
|
||||||
|
QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QJsonValue toJsonValue(const QList<T> &val) {
|
QJsonValue toJsonValue(const QList<T> &val) {
|
||||||
@ -80,7 +85,9 @@ namespace {{this}} {
|
|||||||
bool fromStringValue(const QString &inStr, bool &value);
|
bool fromStringValue(const QString &inStr, bool &value);
|
||||||
bool fromStringValue(const QString &inStr, float &value);
|
bool fromStringValue(const QString &inStr, float &value);
|
||||||
bool fromStringValue(const QString &inStr, double &value);
|
bool fromStringValue(const QString &inStr, double &value);
|
||||||
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
|
bool fromStringValue(const QString &inStr, {{prefix}}Object &value);
|
||||||
|
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
|
||||||
|
bool fromStringValue(const QString &inStr, {{prefix}}HttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||||
@ -115,6 +122,7 @@ namespace {{this}} {
|
|||||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
|
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
|
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
|
||||||
|
bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
{{#models}}{{#model}}
|
{{#models}}{{#model}}
|
||||||
#include "{{classname}}.h"
|
#include "{{classname}}.h"
|
||||||
|
|
||||||
#include "{{prefix}}Helpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "{{prefix}}Helpers.h"
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
{{/cppNamespaceDeclarations}}
|
{{/cppNamespaceDeclarations}}
|
||||||
@ -70,7 +70,7 @@ void
|
|||||||
if(varmap.count() > 0){
|
if(varmap.count() > 0){
|
||||||
for(auto val : varmap.keys()){
|
for(auto val : varmap.keys()){
|
||||||
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
|
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
|
||||||
auto jval = QJsonValue::fromVariant(varmap.value(val));
|
auto jval = QJsonValue::fromVariant(varmap.value(val));
|
||||||
m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval);
|
m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval);
|
||||||
{{name}}.insert({{name}}.end(), val, item);
|
{{name}}.insert({{name}}.end(), val, item);
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ QString
|
|||||||
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}
|
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}
|
||||||
{{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
|
{{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
|
||||||
{{^isEnum}}QJsonObject obj;{{#vars}}
|
{{^isEnum}}QJsonObject obj;{{#vars}}
|
||||||
{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{
|
{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{
|
||||||
obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));
|
obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));
|
||||||
}{{/isContainer}}{{#isContainer}}
|
}{{/isContainer}}{{#isContainer}}
|
||||||
if({{name}}.size() > 0){
|
if({{name}}.size() > 0){
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "{{prefix}}Object.h"
|
#include "{{prefix}}Object.h"
|
||||||
#include "{{prefix}}Enum.h"
|
#include "{{prefix}}Enum.h"
|
||||||
|
|
||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
|
155
modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/HttpFileElement.cpp.mustache
vendored
Normal file
155
modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/HttpFileElement.cpp.mustache
vendored
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
{{>licenseInfo}}
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "{{prefix}}HttpFileElement.h"
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
namespace {{this}} {
|
||||||
|
{{/cppNamespaceDeclarations}}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setMimeType(const QString &mime){
|
||||||
|
mime_type = mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setFileName(const QString &name){
|
||||||
|
local_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setVariableName(const QString &name){
|
||||||
|
variable_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
{{prefix}}HttpFileElement::setRequestFileName(const QString &name){
|
||||||
|
request_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::isSet() const {
|
||||||
|
return !local_filename.isEmpty() || !request_filename.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
{{prefix}}HttpFileElement::asJson() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QString(bArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
{{prefix}}HttpFileElement::asJsonValue() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QJsonDocument::fromBinaryData(bArray.data()).object();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::fromStringValue(const QString &instr){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(instr.toUtf8());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::fromJsonValue(const QJsonValue &jval) {
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(QJsonDocument(jval.toObject()).toBinaryData());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
{{prefix}}HttpFileElement::asByteArray() const {
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return bArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::fromByteArray(const QByteArray& bytes){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()){
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(bytes);
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
{{prefix}}HttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray& bytes){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return fromByteArray(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
{{prefix}}HttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return asByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
}
|
||||||
|
{{/cppNamespaceDeclarations}}
|
@ -0,0 +1,42 @@
|
|||||||
|
{{>licenseInfo}}
|
||||||
|
#ifndef {{prefix}}_HTTP_FILE_ELEMENT_H
|
||||||
|
#define {{prefix}}_HTTP_FILE_ELEMENT_H
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
namespace {{this}} {
|
||||||
|
{{/cppNamespaceDeclarations}}
|
||||||
|
|
||||||
|
class {{prefix}}HttpFileElement {
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString variable_name;
|
||||||
|
QString local_filename;
|
||||||
|
QString request_filename;
|
||||||
|
QString mime_type;
|
||||||
|
void setMimeType(const QString &mime);
|
||||||
|
void setFileName(const QString &name);
|
||||||
|
void setVariableName(const QString &name);
|
||||||
|
void setRequestFileName(const QString &name);
|
||||||
|
bool isSet() const;
|
||||||
|
bool fromStringValue(const QString &instr);
|
||||||
|
bool fromJsonValue(const QJsonValue &jval);
|
||||||
|
bool fromByteArray(const QByteArray& bytes);
|
||||||
|
bool saveToFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime, const QByteArray& bytes);
|
||||||
|
QString asJson() const;
|
||||||
|
QJsonValue asJsonValue() const;
|
||||||
|
QByteArray asByteArray() const;
|
||||||
|
QByteArray loadFromFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime);
|
||||||
|
};
|
||||||
|
|
||||||
|
{{#cppNamespaceDeclarations}}
|
||||||
|
}
|
||||||
|
{{/cppNamespaceDeclarations}}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE({{#cppNamespaceDeclarations}}{{this}}::{{/cppNamespaceDeclarations}}{{prefix}}HttpFileElement)
|
||||||
|
|
||||||
|
#endif // {{prefix}}_HTTP_FILE_ELEMENT_H
|
@ -15,7 +15,7 @@ class {{prefix}}Enum {
|
|||||||
{{prefix}}Enum() {
|
{{prefix}}Enum() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{{prefix}}Enum(QString jsonString) {
|
{{prefix}}Enum(QString jsonString) {
|
||||||
fromJson(jsonString);
|
fromJson(jsonString);
|
||||||
}
|
}
|
||||||
@ -48,7 +48,7 @@ class {{prefix}}Enum {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private :
|
private :
|
||||||
QString jstr;
|
QString jstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
|
@ -55,11 +55,23 @@ toStringValue(const double &value){
|
|||||||
return QString::number(value);
|
return QString::number(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const {{prefix}}Object &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
toStringValue(const {{prefix}}Enum &value){
|
toStringValue(const {{prefix}}Enum &value){
|
||||||
return value.asJson();
|
return value.asJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const {{prefix}}HttpFileElement &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonValue
|
QJsonValue
|
||||||
toJsonValue(const QString &value){
|
toJsonValue(const QString &value){
|
||||||
return QJsonValue(value);
|
return QJsonValue(value);
|
||||||
@ -115,6 +127,12 @@ toJsonValue(const {{prefix}}Enum &value){
|
|||||||
return value.asJsonValue();
|
return value.asJsonValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
toJsonValue(const {{prefix}}HttpFileElement &value){
|
||||||
|
return value.asJsonValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromStringValue(const QString &inStr, QString &value){
|
fromStringValue(const QString &inStr, QString &value){
|
||||||
value.clear();
|
value.clear();
|
||||||
@ -209,6 +227,11 @@ fromStringValue(const QString &inStr, {{prefix}}Enum &value){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromStringValue(const QString &inStr, OAIHttpFileElement &value){
|
||||||
|
return value.fromStringValue(inStr);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
@ -220,7 +243,7 @@ fromJsonValue(QString &value, const QJsonValue &jval){
|
|||||||
} else if(jval.isDouble()){
|
} else if(jval.isDouble()){
|
||||||
value = QString::number(jval.toDouble());
|
value = QString::number(jval.toDouble());
|
||||||
} else {
|
} else {
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ok = false;
|
ok = false;
|
||||||
@ -230,7 +253,7 @@ fromJsonValue(QString &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QDateTime &value, const QJsonValue &jval){
|
fromJsonValue(QDateTime &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
||||||
value = QDateTime::fromString(jval.toString(), Qt::ISODate);
|
value = QDateTime::fromString(jval.toString(), Qt::ISODate);
|
||||||
ok = value.isValid();
|
ok = value.isValid();
|
||||||
@ -254,7 +277,7 @@ fromJsonValue(QByteArray &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QDate &value, const QJsonValue &jval){
|
fromJsonValue(QDate &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
||||||
value = QDate::fromString(jval.toString(), Qt::ISODate);
|
value = QDate::fromString(jval.toString(), Qt::ISODate);
|
||||||
ok = value.isValid();
|
ok = value.isValid();
|
||||||
@ -266,7 +289,7 @@ fromJsonValue(QDate &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(qint32 &value, const QJsonValue &jval){
|
fromJsonValue(qint32 &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
||||||
value = jval.toInt();
|
value = jval.toInt();
|
||||||
} else {
|
} else {
|
||||||
@ -277,7 +300,7 @@ fromJsonValue(qint32 &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(qint64 &value, const QJsonValue &jval){
|
fromJsonValue(qint64 &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
||||||
value = jval.toVariant().toLongLong();
|
value = jval.toVariant().toLongLong();
|
||||||
} else {
|
} else {
|
||||||
@ -288,7 +311,7 @@ fromJsonValue(qint64 &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(bool &value, const QJsonValue &jval){
|
fromJsonValue(bool &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isBool()){
|
if(jval.isBool()){
|
||||||
value = jval.toBool();
|
value = jval.toBool();
|
||||||
} else {
|
} else {
|
||||||
@ -299,7 +322,7 @@ fromJsonValue(bool &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(float &value, const QJsonValue &jval){
|
fromJsonValue(float &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isDouble()){
|
if(jval.isDouble()){
|
||||||
value = static_cast<float>(jval.toDouble());
|
value = static_cast<float>(jval.toDouble());
|
||||||
} else {
|
} else {
|
||||||
@ -310,7 +333,7 @@ fromJsonValue(float &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(double &value, const QJsonValue &jval){
|
fromJsonValue(double &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isDouble()){
|
if(jval.isDouble()){
|
||||||
value = jval.toDouble();
|
value = jval.toDouble();
|
||||||
} else {
|
} else {
|
||||||
@ -321,7 +344,7 @@ fromJsonValue(double &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){
|
fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isObject()){
|
if(jval.isObject()){
|
||||||
value.fromJsonObject(jval.toObject());
|
value.fromJsonObject(jval.toObject());
|
||||||
ok = value.isValid();
|
ok = value.isValid();
|
||||||
@ -337,6 +360,11 @@ fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval){
|
||||||
|
return value.fromJsonValue(jval);
|
||||||
|
}
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
}
|
}
|
||||||
{{/cppNamespaceDeclarations}}
|
{{/cppNamespaceDeclarations}}
|
||||||
|
@ -11,8 +11,10 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "{{prefix}}Object.h"
|
#include "{{prefix}}Object.h"
|
||||||
#include "{{prefix}}Enum.h"
|
#include "{{prefix}}Enum.h"
|
||||||
|
#include "{{prefix}}HttpFileElement.h"
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
@ -27,7 +29,9 @@ namespace {{this}} {
|
|||||||
QString toStringValue(const bool &value);
|
QString toStringValue(const bool &value);
|
||||||
QString toStringValue(const float &value);
|
QString toStringValue(const float &value);
|
||||||
QString toStringValue(const double &value);
|
QString toStringValue(const double &value);
|
||||||
QString toStringValue(const {{prefix}}Enum &value);
|
QString toStringValue(const {{prefix}}Object &value);
|
||||||
|
QString toStringValue(const {{prefix}}Enum &value);
|
||||||
|
QString toStringValue(const {{prefix}}HttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QString toStringValue(const QList<T> &val) {
|
QString toStringValue(const QList<T> &val) {
|
||||||
@ -52,6 +56,7 @@ namespace {{this}} {
|
|||||||
QJsonValue toJsonValue(const double &value);
|
QJsonValue toJsonValue(const double &value);
|
||||||
QJsonValue toJsonValue(const {{prefix}}Object &value);
|
QJsonValue toJsonValue(const {{prefix}}Object &value);
|
||||||
QJsonValue toJsonValue(const {{prefix}}Enum &value);
|
QJsonValue toJsonValue(const {{prefix}}Enum &value);
|
||||||
|
QJsonValue toJsonValue(const {{prefix}}HttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QJsonValue toJsonValue(const QList<T> &val) {
|
QJsonValue toJsonValue(const QList<T> &val) {
|
||||||
@ -80,7 +85,9 @@ namespace {{this}} {
|
|||||||
bool fromStringValue(const QString &inStr, bool &value);
|
bool fromStringValue(const QString &inStr, bool &value);
|
||||||
bool fromStringValue(const QString &inStr, float &value);
|
bool fromStringValue(const QString &inStr, float &value);
|
||||||
bool fromStringValue(const QString &inStr, double &value);
|
bool fromStringValue(const QString &inStr, double &value);
|
||||||
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
|
bool fromStringValue(const QString &inStr, {{prefix}}Object &value);
|
||||||
|
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
|
||||||
|
bool fromStringValue(const QString &inStr, {{prefix}}HttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||||
@ -115,6 +122,7 @@ namespace {{this}} {
|
|||||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
|
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
|
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
|
||||||
|
bool fromJsonValue({{prefix}}HttpFileElement &value, const QJsonValue &jval);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||||
@ -129,7 +137,7 @@ namespace {{this}} {
|
|||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
|
bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
|
||||||
|
@ -2,13 +2,13 @@
|
|||||||
{{#models}}{{#model}}
|
{{#models}}{{#model}}
|
||||||
#include "{{classname}}.h"
|
#include "{{classname}}.h"
|
||||||
|
|
||||||
#include "{{prefix}}Helpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "{{prefix}}Helpers.h"
|
||||||
|
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
{{/cppNamespaceDeclarations}}
|
{{/cppNamespaceDeclarations}}
|
||||||
@ -43,7 +43,7 @@ void
|
|||||||
{{^isEnum}}QByteArray array (jsonString.toStdString().c_str());
|
{{^isEnum}}QByteArray array (jsonString.toStdString().c_str());
|
||||||
QJsonDocument doc = QJsonDocument::fromJson(array);
|
QJsonDocument doc = QJsonDocument::fromJson(array);
|
||||||
QJsonObject jsonObject = doc.object();
|
QJsonObject jsonObject = doc.object();
|
||||||
this->fromJsonObject(jsonObject);{{/isEnum}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}
|
this->fromJsonObject(jsonObject);{{/isEnum}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}
|
||||||
{{#-first}}if{{/-first}}{{^-first}}else if{{/-first}} ( jsonString.compare({{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}}, Qt::CaseInsensitive) == 0) {
|
{{#-first}}if{{/-first}}{{^-first}}else if{{/-first}} ( jsonString.compare({{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}}, Qt::CaseInsensitive) == 0) {
|
||||||
m_value = e{{classname}}::{{name}};
|
m_value = e{{classname}}::{{name}};
|
||||||
m_value_isValid = true;
|
m_value_isValid = true;
|
||||||
@ -70,7 +70,7 @@ void
|
|||||||
if(varmap.count() > 0){
|
if(varmap.count() > 0){
|
||||||
for(auto val : varmap.keys()){
|
for(auto val : varmap.keys()){
|
||||||
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
|
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
|
||||||
auto jval = QJsonValue::fromVariant(varmap.value(val));
|
auto jval = QJsonValue::fromVariant(varmap.value(val));
|
||||||
m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval);
|
m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval);
|
||||||
{{name}}.insert({{name}}.end(), val, item);
|
{{name}}.insert({{name}}.end(), val, item);
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ QString
|
|||||||
{{#enumVars}}
|
{{#enumVars}}
|
||||||
case e{{classname}}::{{name}}:
|
case e{{classname}}::{{name}}:
|
||||||
val = {{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}};
|
val = {{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}};
|
||||||
break;{{#-last}}
|
break;{{#-last}}
|
||||||
default:
|
default:
|
||||||
break;{{/-last}}
|
break;{{/-last}}
|
||||||
{{/enumVars}}
|
{{/enumVars}}
|
||||||
@ -103,7 +103,7 @@ QString
|
|||||||
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}
|
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}
|
||||||
{{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
|
{{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
|
||||||
{{^isEnum}}QJsonObject obj;{{#vars}}
|
{{^isEnum}}QJsonObject obj;{{#vars}}
|
||||||
{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{
|
{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{
|
||||||
obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));
|
obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));
|
||||||
}{{/isContainer}}{{#isContainer}}
|
}{{/isContainer}}{{#isContainer}}
|
||||||
if({{name}}.size() > 0){
|
if({{name}}.size() > 0){
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "{{prefix}}Object.h"
|
#include "{{prefix}}Object.h"
|
||||||
#include "{{prefix}}Enum.h"
|
#include "{{prefix}}Enum.h"
|
||||||
|
|
||||||
|
|
||||||
{{#models}}
|
{{#models}}
|
||||||
{{#model}}
|
{{#model}}
|
||||||
{{#cppNamespaceDeclarations}}
|
{{#cppNamespaceDeclarations}}
|
||||||
@ -53,7 +54,7 @@ public:
|
|||||||
|
|
||||||
{{classname}}::e{{classname}} getValue() const;
|
{{classname}}::e{{classname}} getValue() const;
|
||||||
void setValue(const {{classname}}::e{{classname}}& value);{{/isEnum}}
|
void setValue(const {{classname}}::e{{classname}}& value);{{/isEnum}}
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ class {{prefix}}Object {
|
|||||||
{{prefix}}Object() {
|
{{prefix}}Object() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{{prefix}}Object(QString jsonString) {
|
{{prefix}}Object(QString jsonString) {
|
||||||
fromJson(jsonString);
|
fromJson(jsonString);
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
4.1.0-SNAPSHOT
|
4.1.2-SNAPSHOT
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIApiResponse.h"
|
#include "OAIApiResponse.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIApiResponse::OAIApiResponse(QString json) {
|
OAIApiResponse::OAIApiResponse(QString json) {
|
||||||
@ -81,13 +81,13 @@ OAIApiResponse::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIApiResponse::asJsonObject() const {
|
OAIApiResponse::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_code_isSet){
|
if(m_code_isSet){
|
||||||
obj.insert(QString("code"), ::OpenAPI::toJsonValue(code));
|
obj.insert(QString("code"), ::OpenAPI::toJsonValue(code));
|
||||||
}
|
}
|
||||||
if(m_type_isSet){
|
if(m_type_isSet){
|
||||||
obj.insert(QString("type"), ::OpenAPI::toJsonValue(type));
|
obj.insert(QString("type"), ::OpenAPI::toJsonValue(type));
|
||||||
}
|
}
|
||||||
if(m_message_isSet){
|
if(m_message_isSet){
|
||||||
obj.insert(QString("message"), ::OpenAPI::toJsonValue(message));
|
obj.insert(QString("message"), ::OpenAPI::toJsonValue(message));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIApiResponse: public OAIObject {
|
class OAIApiResponse: public OAIObject {
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAICategory.h"
|
#include "OAICategory.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAICategory::OAICategory(QString json) {
|
OAICategory::OAICategory(QString json) {
|
||||||
@ -75,10 +75,10 @@ OAICategory::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAICategory::asJsonObject() const {
|
OAICategory::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_name_isSet){
|
if(m_name_isSet){
|
||||||
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAICategory: public OAIObject {
|
class OAICategory: public OAIObject {
|
||||||
|
@ -64,11 +64,23 @@ toStringValue(const double &value){
|
|||||||
return QString::number(value);
|
return QString::number(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const OAIObject &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
toStringValue(const OAIEnum &value){
|
toStringValue(const OAIEnum &value){
|
||||||
return value.asJson();
|
return value.asJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const OAIHttpFileElement &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonValue
|
QJsonValue
|
||||||
toJsonValue(const QString &value){
|
toJsonValue(const QString &value){
|
||||||
return QJsonValue(value);
|
return QJsonValue(value);
|
||||||
@ -124,6 +136,12 @@ toJsonValue(const OAIEnum &value){
|
|||||||
return value.asJsonValue();
|
return value.asJsonValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
toJsonValue(const OAIHttpFileElement &value){
|
||||||
|
return value.asJsonValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromStringValue(const QString &inStr, QString &value){
|
fromStringValue(const QString &inStr, QString &value){
|
||||||
value.clear();
|
value.clear();
|
||||||
@ -218,6 +236,11 @@ fromStringValue(const QString &inStr, OAIEnum &value){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromStringValue(const QString &inStr, OAIHttpFileElement &value){
|
||||||
|
return value.fromStringValue(inStr);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
@ -346,4 +369,9 @@ fromJsonValue(OAIEnum &value, const QJsonValue &jval){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromJsonValue(OAIHttpFileElement &value, const QJsonValue &jval){
|
||||||
|
return value.fromJsonValue(jval);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
@ -36,7 +38,9 @@ namespace OpenAPI {
|
|||||||
QString toStringValue(const bool &value);
|
QString toStringValue(const bool &value);
|
||||||
QString toStringValue(const float &value);
|
QString toStringValue(const float &value);
|
||||||
QString toStringValue(const double &value);
|
QString toStringValue(const double &value);
|
||||||
QString toStringValue(const OAIEnum &value);
|
QString toStringValue(const OAIObject &value);
|
||||||
|
QString toStringValue(const OAIEnum &value);
|
||||||
|
QString toStringValue(const OAIHttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QString toStringValue(const QList<T> &val) {
|
QString toStringValue(const QList<T> &val) {
|
||||||
@ -61,6 +65,7 @@ namespace OpenAPI {
|
|||||||
QJsonValue toJsonValue(const double &value);
|
QJsonValue toJsonValue(const double &value);
|
||||||
QJsonValue toJsonValue(const OAIObject &value);
|
QJsonValue toJsonValue(const OAIObject &value);
|
||||||
QJsonValue toJsonValue(const OAIEnum &value);
|
QJsonValue toJsonValue(const OAIEnum &value);
|
||||||
|
QJsonValue toJsonValue(const OAIHttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QJsonValue toJsonValue(const QList<T> &val) {
|
QJsonValue toJsonValue(const QList<T> &val) {
|
||||||
@ -89,7 +94,9 @@ namespace OpenAPI {
|
|||||||
bool fromStringValue(const QString &inStr, bool &value);
|
bool fromStringValue(const QString &inStr, bool &value);
|
||||||
bool fromStringValue(const QString &inStr, float &value);
|
bool fromStringValue(const QString &inStr, float &value);
|
||||||
bool fromStringValue(const QString &inStr, double &value);
|
bool fromStringValue(const QString &inStr, double &value);
|
||||||
bool fromStringValue(const QString &inStr, OAIEnum &value);
|
bool fromStringValue(const QString &inStr, OAIObject &value);
|
||||||
|
bool fromStringValue(const QString &inStr, OAIEnum &value);
|
||||||
|
bool fromStringValue(const QString &inStr, OAIHttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||||
@ -124,6 +131,7 @@ namespace OpenAPI {
|
|||||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
|
bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue(OAIEnum &value, const QJsonValue &jval);
|
bool fromJsonValue(OAIEnum &value, const QJsonValue &jval);
|
||||||
|
bool fromJsonValue(OAIHttpFileElement &value, const QJsonValue &jval);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||||
|
162
samples/client/petstore/cpp-qt5/client/OAIHttpFileElement.cpp
Normal file
162
samples/client/petstore/cpp-qt5/client/OAIHttpFileElement.cpp
Normal file
@ -0,0 +1,162 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
|
|
||||||
|
namespace OpenAPI {
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setMimeType(const QString &mime){
|
||||||
|
mime_type = mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setFileName(const QString &name){
|
||||||
|
local_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setVariableName(const QString &name){
|
||||||
|
variable_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setRequestFileName(const QString &name){
|
||||||
|
request_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::isSet() const {
|
||||||
|
return !local_filename.isEmpty() || !request_filename.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
OAIHttpFileElement::asJson() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QString(bArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
OAIHttpFileElement::asJsonValue() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QJsonDocument::fromBinaryData(bArray.data()).object();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::fromStringValue(const QString &instr){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(instr.toUtf8());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::fromJsonValue(const QJsonValue &jval) {
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(QJsonDocument(jval.toObject()).toBinaryData());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
OAIHttpFileElement::asByteArray() const {
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return bArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::fromByteArray(const QByteArray& bytes){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()){
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(bytes);
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray& bytes){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return fromByteArray(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
OAIHttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return asByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
49
samples/client/petstore/cpp-qt5/client/OAIHttpFileElement.h
Normal file
49
samples/client/petstore/cpp-qt5/client/OAIHttpFileElement.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* 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 OAI_HTTP_FILE_ELEMENT_H
|
||||||
|
#define OAI_HTTP_FILE_ELEMENT_H
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
namespace OpenAPI {
|
||||||
|
|
||||||
|
class OAIHttpFileElement {
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString variable_name;
|
||||||
|
QString local_filename;
|
||||||
|
QString request_filename;
|
||||||
|
QString mime_type;
|
||||||
|
void setMimeType(const QString &mime);
|
||||||
|
void setFileName(const QString &name);
|
||||||
|
void setVariableName(const QString &name);
|
||||||
|
void setRequestFileName(const QString &name);
|
||||||
|
bool isSet() const;
|
||||||
|
bool fromStringValue(const QString &instr);
|
||||||
|
bool fromJsonValue(const QJsonValue &jval);
|
||||||
|
bool fromByteArray(const QByteArray& bytes);
|
||||||
|
bool saveToFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime, const QByteArray& bytes);
|
||||||
|
QString asJson() const;
|
||||||
|
QJsonValue asJsonValue() const;
|
||||||
|
QByteArray asByteArray() const;
|
||||||
|
QByteArray loadFromFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(OpenAPI::OAIHttpFileElement)
|
||||||
|
|
||||||
|
#endif // OAI_HTTP_FILE_ELEMENT_H
|
@ -10,13 +10,18 @@
|
|||||||
* Do not edit the class manually.
|
* Do not edit the class manually.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "OAIHttpRequest.h"
|
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QUuid>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#include "OAIHttpRequest.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
@ -41,7 +46,7 @@ void OAIHttpRequestInput::add_var(QString key, QString value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OAIHttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
|
void OAIHttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
|
||||||
OAIHttpRequestInputFileElement file;
|
OAIHttpFileElement file;
|
||||||
file.variable_name = variable_name;
|
file.variable_name = variable_name;
|
||||||
file.local_filename = local_filename;
|
file.local_filename = local_filename;
|
||||||
file.request_filename = request_filename;
|
file.request_filename = request_filename;
|
||||||
@ -57,6 +62,7 @@ OAIHttpRequestWorker::OAIHttpRequestWorker(QObject *parent)
|
|||||||
timeout = 0;
|
timeout = 0;
|
||||||
timer = new QTimer();
|
timer = new QTimer();
|
||||||
manager = new QNetworkAccessManager(this);
|
manager = new QNetworkAccessManager(this);
|
||||||
|
workingDirectory = QDir::currentPath();
|
||||||
connect(manager, &QNetworkAccessManager::finished, this, &OAIHttpRequestWorker::on_manager_finished);
|
connect(manager, &QNetworkAccessManager::finished, this, &OAIHttpRequestWorker::on_manager_finished);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,16 +73,50 @@ OAIHttpRequestWorker::~OAIHttpRequestWorker() {
|
|||||||
}
|
}
|
||||||
timer->deleteLater();
|
timer->deleteLater();
|
||||||
}
|
}
|
||||||
|
for (const auto & item: multiPartFields) {
|
||||||
|
if(item != nullptr) {
|
||||||
|
delete item;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> OAIHttpRequestWorker::getResponseHeaders() const {
|
QMap<QString, QString> OAIHttpRequestWorker::getResponseHeaders() const {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OAIHttpFileElement OAIHttpRequestWorker::getHttpFileElement(const QString &fieldname){
|
||||||
|
if(!files.isEmpty()){
|
||||||
|
if(fieldname.isEmpty()){
|
||||||
|
return files.first();
|
||||||
|
}else if (files.contains(fieldname)){
|
||||||
|
return files[fieldname];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return OAIHttpFileElement();
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray *OAIHttpRequestWorker::getMultiPartField(const QString &fieldname){
|
||||||
|
if(!multiPartFields.isEmpty()){
|
||||||
|
if(fieldname.isEmpty()){
|
||||||
|
return multiPartFields.first();
|
||||||
|
}else if (multiPartFields.contains(fieldname)){
|
||||||
|
return multiPartFields[fieldname];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void OAIHttpRequestWorker::setTimeOut(int tout){
|
void OAIHttpRequestWorker::setTimeOut(int tout){
|
||||||
timeout = tout;
|
timeout = tout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OAIHttpRequestWorker::setWorkingDirectory(const QString &path){
|
||||||
|
if(!path.isEmpty()){
|
||||||
|
workingDirectory = path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString OAIHttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
|
QString OAIHttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
|
||||||
// result structure follows RFC 5987
|
// result structure follows RFC 5987
|
||||||
bool need_utf_encoding = false;
|
bool need_utf_encoding = false;
|
||||||
@ -205,7 +245,7 @@ void OAIHttpRequestWorker::execute(OAIHttpRequestInput *input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add files
|
// add files
|
||||||
for (QList<OAIHttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
|
for (QList<OAIHttpFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
|
||||||
QFileInfo fi(file_info->local_filename);
|
QFileInfo fi(file_info->local_filename);
|
||||||
|
|
||||||
// ensure necessary variables are available
|
// ensure necessary variables are available
|
||||||
@ -285,8 +325,13 @@ void OAIHttpRequestWorker::execute(OAIHttpRequestInput *input) {
|
|||||||
request.setRawHeader(key.toStdString().c_str(), input->headers.value(key).toStdString().c_str());
|
request.setRawHeader(key.toStdString().c_str(), input->headers.value(key).toStdString().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request_content.size() > 0 && !isFormData) {
|
if (request_content.size() > 0 && !isFormData && (input->var_layout != MULTIPART)) {
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
if(!input->headers.contains("Content-Type")){
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
request.setHeader(QNetworkRequest::ContentTypeHeader, input->headers.value("Content-Type"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (input->var_layout == URL_ENCODED) {
|
else if (input->var_layout == URL_ENCODED) {
|
||||||
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
|
||||||
@ -340,9 +385,10 @@ void OAIHttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
process_form_response();
|
||||||
emit on_execution_finished(this);
|
emit on_execution_finished(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OAIHttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
void OAIHttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
||||||
error_type = QNetworkReply::TimeoutError;
|
error_type = QNetworkReply::TimeoutError;
|
||||||
response = "";
|
response = "";
|
||||||
@ -350,9 +396,37 @@ void OAIHttpRequestWorker::on_manager_timeout(QNetworkReply *reply) {
|
|||||||
disconnect(manager, nullptr, nullptr, nullptr);
|
disconnect(manager, nullptr, nullptr, nullptr);
|
||||||
reply->abort();
|
reply->abort();
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
|
||||||
emit on_execution_finished(this);
|
emit on_execution_finished(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OAIHttpRequestWorker::process_form_response() {
|
||||||
|
if(getResponseHeaders().contains(QString("Content-Disposition")) ) {
|
||||||
|
auto contentDisposition = getResponseHeaders().value(QString("Content-Disposition").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||||
|
auto contentType = getResponseHeaders().contains(QString("Content-Type")) ? getResponseHeaders().value(QString("Content-Type").toUtf8()).split(QString(";"), QString::SkipEmptyParts).first() : QString();
|
||||||
|
if((contentDisposition.count() > 0) && (contentDisposition.first() == QString("attachment"))){
|
||||||
|
QString filename = QUuid::createUuid().toString();
|
||||||
|
for(const auto &file : contentDisposition){
|
||||||
|
if(file.contains(QString("filename"))){
|
||||||
|
filename = file.split(QString("="), QString::SkipEmptyParts).at(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OAIHttpFileElement felement;
|
||||||
|
felement.saveToFile(QString(), workingDirectory + QDir::separator() + filename, filename, contentType, response.data());
|
||||||
|
files.insert(filename, felement);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(getResponseHeaders().contains(QString("Content-Type")) ) {
|
||||||
|
auto contentType = getResponseHeaders().value(QString("Content-Type").toUtf8()).split(QString(";"), QString::SkipEmptyParts);
|
||||||
|
if((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))){
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QSslConfiguration* OAIHttpRequestWorker::sslDefaultConfiguration;
|
QSslConfiguration* OAIHttpRequestWorker::sslDefaultConfiguration;
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,21 +27,12 @@
|
|||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
|
||||||
|
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
enum OAIHttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
|
enum OAIHttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
|
||||||
|
|
||||||
class OAIHttpRequestInputFileElement {
|
|
||||||
|
|
||||||
public:
|
|
||||||
QString variable_name;
|
|
||||||
QString local_filename;
|
|
||||||
QString request_filename;
|
|
||||||
QString mime_type;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class OAIHttpRequestInput {
|
class OAIHttpRequestInput {
|
||||||
|
|
||||||
@ -51,7 +42,7 @@ public:
|
|||||||
OAIHttpRequestVarLayout var_layout;
|
OAIHttpRequestVarLayout var_layout;
|
||||||
QMap<QString, QString> vars;
|
QMap<QString, QString> vars;
|
||||||
QMap<QString, QString> headers;
|
QMap<QString, QString> headers;
|
||||||
QList<OAIHttpRequestInputFileElement> files;
|
QList<OAIHttpFileElement> files;
|
||||||
QByteArray request_body;
|
QByteArray request_body;
|
||||||
|
|
||||||
OAIHttpRequestInput();
|
OAIHttpRequestInput();
|
||||||
@ -74,19 +65,26 @@ public:
|
|||||||
explicit OAIHttpRequestWorker(QObject *parent = nullptr);
|
explicit OAIHttpRequestWorker(QObject *parent = nullptr);
|
||||||
virtual ~OAIHttpRequestWorker();
|
virtual ~OAIHttpRequestWorker();
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> getResponseHeaders() const;
|
QMap<QString, QString> getResponseHeaders() const;
|
||||||
QString http_attribute_encode(QString attribute_name, QString input);
|
QString http_attribute_encode(QString attribute_name, QString input);
|
||||||
void execute(OAIHttpRequestInput *input);
|
void execute(OAIHttpRequestInput *input);
|
||||||
static QSslConfiguration* sslDefaultConfiguration;
|
static QSslConfiguration* sslDefaultConfiguration;
|
||||||
void setTimeOut(int tout);
|
void setTimeOut(int tout);
|
||||||
|
void setWorkingDirectory(const QString &path);
|
||||||
|
OAIHttpFileElement getHttpFileElement(const QString &fieldname = QString());
|
||||||
|
QByteArray* getMultiPartField(const QString &fieldname = QString());
|
||||||
signals:
|
signals:
|
||||||
void on_execution_finished(OAIHttpRequestWorker *worker);
|
void on_execution_finished(OAIHttpRequestWorker *worker);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QNetworkAccessManager *manager;
|
QNetworkAccessManager *manager;
|
||||||
QMap<QByteArray, QByteArray> headers;
|
QMap<QString, QString> headers;
|
||||||
|
QMap<QString, OAIHttpFileElement> files;
|
||||||
|
QMap<QString, QByteArray*> multiPartFields;
|
||||||
|
QString workingDirectory;
|
||||||
int timeout;
|
int timeout;
|
||||||
void on_manager_timeout(QNetworkReply *reply);
|
void on_manager_timeout(QNetworkReply *reply);
|
||||||
|
void process_form_response();
|
||||||
private slots:
|
private slots:
|
||||||
void on_manager_finished(QNetworkReply *reply);
|
void on_manager_finished(QNetworkReply *reply);
|
||||||
};
|
};
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIOrder.h"
|
#include "OAIOrder.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIOrder::OAIOrder(QString json) {
|
OAIOrder::OAIOrder(QString json) {
|
||||||
@ -99,22 +99,22 @@ OAIOrder::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIOrder::asJsonObject() const {
|
OAIOrder::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_pet_id_isSet){
|
if(m_pet_id_isSet){
|
||||||
obj.insert(QString("petId"), ::OpenAPI::toJsonValue(pet_id));
|
obj.insert(QString("petId"), ::OpenAPI::toJsonValue(pet_id));
|
||||||
}
|
}
|
||||||
if(m_quantity_isSet){
|
if(m_quantity_isSet){
|
||||||
obj.insert(QString("quantity"), ::OpenAPI::toJsonValue(quantity));
|
obj.insert(QString("quantity"), ::OpenAPI::toJsonValue(quantity));
|
||||||
}
|
}
|
||||||
if(m_ship_date_isSet){
|
if(m_ship_date_isSet){
|
||||||
obj.insert(QString("shipDate"), ::OpenAPI::toJsonValue(ship_date));
|
obj.insert(QString("shipDate"), ::OpenAPI::toJsonValue(ship_date));
|
||||||
}
|
}
|
||||||
if(m_status_isSet){
|
if(m_status_isSet){
|
||||||
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
||||||
}
|
}
|
||||||
if(m_complete_isSet){
|
if(m_complete_isSet){
|
||||||
obj.insert(QString("complete"), ::OpenAPI::toJsonValue(complete));
|
obj.insert(QString("complete"), ::OpenAPI::toJsonValue(complete));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIOrder: public OAIObject {
|
class OAIOrder: public OAIObject {
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIPet.h"
|
#include "OAIPet.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIPet::OAIPet(QString json) {
|
OAIPet::OAIPet(QString json) {
|
||||||
@ -99,24 +99,24 @@ OAIPet::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIPet::asJsonObject() const {
|
OAIPet::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(category.isSet()){
|
if(category.isSet()){
|
||||||
obj.insert(QString("category"), ::OpenAPI::toJsonValue(category));
|
obj.insert(QString("category"), ::OpenAPI::toJsonValue(category));
|
||||||
}
|
}
|
||||||
if(m_name_isSet){
|
if(m_name_isSet){
|
||||||
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(photo_urls.size() > 0){
|
if(photo_urls.size() > 0){
|
||||||
obj.insert(QString("photoUrls"), ::OpenAPI::toJsonValue(photo_urls));
|
obj.insert(QString("photoUrls"), ::OpenAPI::toJsonValue(photo_urls));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tags.size() > 0){
|
if(tags.size() > 0){
|
||||||
obj.insert(QString("tags"), ::OpenAPI::toJsonValue(tags));
|
obj.insert(QString("tags"), ::OpenAPI::toJsonValue(tags));
|
||||||
}
|
}
|
||||||
if(m_status_isSet){
|
if(m_status_isSet){
|
||||||
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIPet: public OAIObject {
|
class OAIPet: public OAIObject {
|
||||||
|
@ -46,6 +46,10 @@ void OAIPetApi::setApiTimeOutMs(const int tout){
|
|||||||
timeout = tout;
|
timeout = tout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OAIPetApi::setWorkingDirectory(const QString& path){
|
||||||
|
workingDirectory = path;
|
||||||
|
}
|
||||||
|
|
||||||
void OAIPetApi::addHeaders(const QString& key, const QString& value){
|
void OAIPetApi::addHeaders(const QString& key, const QString& value){
|
||||||
defaultHeaders.insert(key, value);
|
defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
@ -58,8 +62,9 @@ OAIPetApi::addPet(const OAIPet& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
|
|
||||||
|
|
||||||
QString output = body.asJson();
|
QString output = body.asJson();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
@ -110,7 +115,9 @@ OAIPetApi::deletePet(const qint64& pet_id, const QString& api_key) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "DELETE");
|
OAIHttpRequestInput input(fullPath, "DELETE");
|
||||||
|
|
||||||
|
|
||||||
if (api_key != nullptr) {
|
if (api_key != nullptr) {
|
||||||
input.headers.insert("api_key", api_key);
|
input.headers.insert("api_key", api_key);
|
||||||
@ -198,7 +205,9 @@ OAIPetApi::findPetsByStatus(const QList<QString>& status) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -293,7 +302,9 @@ OAIPetApi::findPetsByTags(const QList<QString>& tags) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -351,7 +362,9 @@ OAIPetApi::getPetById(const qint64& pet_id) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -397,8 +410,9 @@ OAIPetApi::updatePet(const OAIPet& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "PUT");
|
OAIHttpRequestInput input(fullPath, "PUT");
|
||||||
|
|
||||||
|
|
||||||
QString output = body.asJson();
|
QString output = body.asJson();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
@ -449,14 +463,12 @@ OAIPetApi::updatePetWithForm(const qint64& pet_id, const QString& name, const QS
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
if (name != nullptr) {
|
|
||||||
input.add_var("name", name);
|
|
||||||
}
|
|
||||||
if (status != nullptr) {
|
|
||||||
input.add_var("status", status);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
input.add_var("name", ::OpenAPI::toStringValue(name));
|
||||||
|
input.add_var("status", ::OpenAPI::toStringValue(status));
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
input.headers.insert(key, this->defaultHeaders.value(key));
|
input.headers.insert(key, this->defaultHeaders.value(key));
|
||||||
@ -494,7 +506,7 @@ OAIPetApi::updatePetWithFormCallback(OAIHttpRequestWorker * worker) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
OAIPetApi::uploadFile(const qint64& pet_id, const QString& additional_metadata, const OAIHttpRequestInputFileElement*& file) {
|
OAIPetApi::uploadFile(const qint64& pet_id, const QString& additional_metadata, const OAIHttpFileElement& file) {
|
||||||
QString fullPath;
|
QString fullPath;
|
||||||
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage");
|
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage");
|
||||||
QString pet_idPathParam("{");
|
QString pet_idPathParam("{");
|
||||||
@ -503,14 +515,12 @@ OAIPetApi::uploadFile(const qint64& pet_id, const QString& additional_metadata,
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
if (additional_metadata != nullptr) {
|
|
||||||
input.add_var("additionalMetadata", additional_metadata);
|
|
||||||
}
|
|
||||||
if (file != nullptr) {
|
|
||||||
input.add_file("file", (*file).local_filename, (*file).request_filename, (*file).mime_type);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
input.add_var("additionalMetadata", ::OpenAPI::toStringValue(additional_metadata));
|
||||||
|
input.add_file("file", file.local_filename, file.request_filename, file.mime_type);
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
input.headers.insert(key, this->defaultHeaders.value(key));
|
input.headers.insert(key, this->defaultHeaders.value(key));
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
#include "OAIHttpRequest.h"
|
#include "OAIHttpRequest.h"
|
||||||
|
|
||||||
#include "OAIApiResponse.h"
|
#include "OAIApiResponse.h"
|
||||||
#include "OAIHttpRequest.h"
|
#include "OAIHttpFileElement.h"
|
||||||
#include "OAIPet.h"
|
#include "OAIPet.h"
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
@ -35,6 +35,7 @@ public:
|
|||||||
void setBasePath(const QString& basePath);
|
void setBasePath(const QString& basePath);
|
||||||
void setHost(const QString& host);
|
void setHost(const QString& host);
|
||||||
void setApiTimeOutMs(const int tout);
|
void setApiTimeOutMs(const int tout);
|
||||||
|
void setWorkingDirectory(const QString& path);
|
||||||
void addHeaders(const QString& key, const QString& value);
|
void addHeaders(const QString& key, const QString& value);
|
||||||
|
|
||||||
void addPet(const OAIPet& body);
|
void addPet(const OAIPet& body);
|
||||||
@ -44,11 +45,12 @@ public:
|
|||||||
void getPetById(const qint64& pet_id);
|
void getPetById(const qint64& pet_id);
|
||||||
void updatePet(const OAIPet& body);
|
void updatePet(const OAIPet& body);
|
||||||
void updatePetWithForm(const qint64& pet_id, const QString& name, const QString& status);
|
void updatePetWithForm(const qint64& pet_id, const QString& name, const QString& status);
|
||||||
void uploadFile(const qint64& pet_id, const QString& additional_metadata, const OAIHttpRequestInputFileElement*& file);
|
void uploadFile(const qint64& pet_id, const QString& additional_metadata, const OAIHttpFileElement& file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString basePath;
|
QString basePath;
|
||||||
QString host;
|
QString host;
|
||||||
|
QString workingDirectory;
|
||||||
int timeout;
|
int timeout;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> defaultHeaders;
|
||||||
void addPetCallback (OAIHttpRequestWorker * worker);
|
void addPetCallback (OAIHttpRequestWorker * worker);
|
||||||
|
@ -46,6 +46,10 @@ void OAIStoreApi::setApiTimeOutMs(const int tout){
|
|||||||
timeout = tout;
|
timeout = tout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OAIStoreApi::setWorkingDirectory(const QString& path){
|
||||||
|
workingDirectory = path;
|
||||||
|
}
|
||||||
|
|
||||||
void OAIStoreApi::addHeaders(const QString& key, const QString& value){
|
void OAIStoreApi::addHeaders(const QString& key, const QString& value){
|
||||||
defaultHeaders.insert(key, value);
|
defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
@ -61,7 +65,9 @@ OAIStoreApi::deleteOrder(const QString& order_id) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "DELETE");
|
OAIHttpRequestInput input(fullPath, "DELETE");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -106,7 +112,9 @@ OAIStoreApi::getInventory() {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -164,7 +172,9 @@ OAIStoreApi::getOrderById(const qint64& order_id) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -210,8 +220,9 @@ OAIStoreApi::placeOrder(const OAIOrder& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
|
|
||||||
|
|
||||||
QString output = body.asJson();
|
QString output = body.asJson();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
void setBasePath(const QString& basePath);
|
void setBasePath(const QString& basePath);
|
||||||
void setHost(const QString& host);
|
void setHost(const QString& host);
|
||||||
void setApiTimeOutMs(const int tout);
|
void setApiTimeOutMs(const int tout);
|
||||||
|
void setWorkingDirectory(const QString& path);
|
||||||
void addHeaders(const QString& key, const QString& value);
|
void addHeaders(const QString& key, const QString& value);
|
||||||
|
|
||||||
void deleteOrder(const QString& order_id);
|
void deleteOrder(const QString& order_id);
|
||||||
@ -44,6 +45,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QString basePath;
|
QString basePath;
|
||||||
QString host;
|
QString host;
|
||||||
|
QString workingDirectory;
|
||||||
int timeout;
|
int timeout;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> defaultHeaders;
|
||||||
void deleteOrderCallback (OAIHttpRequestWorker * worker);
|
void deleteOrderCallback (OAIHttpRequestWorker * worker);
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAITag.h"
|
#include "OAITag.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAITag::OAITag(QString json) {
|
OAITag::OAITag(QString json) {
|
||||||
@ -75,10 +75,10 @@ OAITag::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAITag::asJsonObject() const {
|
OAITag::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_name_isSet){
|
if(m_name_isSet){
|
||||||
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAITag: public OAIObject {
|
class OAITag: public OAIObject {
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIUser.h"
|
#include "OAIUser.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIUser::OAIUser(QString json) {
|
OAIUser::OAIUser(QString json) {
|
||||||
@ -111,28 +111,28 @@ OAIUser::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIUser::asJsonObject() const {
|
OAIUser::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_username_isSet){
|
if(m_username_isSet){
|
||||||
obj.insert(QString("username"), ::OpenAPI::toJsonValue(username));
|
obj.insert(QString("username"), ::OpenAPI::toJsonValue(username));
|
||||||
}
|
}
|
||||||
if(m_first_name_isSet){
|
if(m_first_name_isSet){
|
||||||
obj.insert(QString("firstName"), ::OpenAPI::toJsonValue(first_name));
|
obj.insert(QString("firstName"), ::OpenAPI::toJsonValue(first_name));
|
||||||
}
|
}
|
||||||
if(m_last_name_isSet){
|
if(m_last_name_isSet){
|
||||||
obj.insert(QString("lastName"), ::OpenAPI::toJsonValue(last_name));
|
obj.insert(QString("lastName"), ::OpenAPI::toJsonValue(last_name));
|
||||||
}
|
}
|
||||||
if(m_email_isSet){
|
if(m_email_isSet){
|
||||||
obj.insert(QString("email"), ::OpenAPI::toJsonValue(email));
|
obj.insert(QString("email"), ::OpenAPI::toJsonValue(email));
|
||||||
}
|
}
|
||||||
if(m_password_isSet){
|
if(m_password_isSet){
|
||||||
obj.insert(QString("password"), ::OpenAPI::toJsonValue(password));
|
obj.insert(QString("password"), ::OpenAPI::toJsonValue(password));
|
||||||
}
|
}
|
||||||
if(m_phone_isSet){
|
if(m_phone_isSet){
|
||||||
obj.insert(QString("phone"), ::OpenAPI::toJsonValue(phone));
|
obj.insert(QString("phone"), ::OpenAPI::toJsonValue(phone));
|
||||||
}
|
}
|
||||||
if(m_user_status_isSet){
|
if(m_user_status_isSet){
|
||||||
obj.insert(QString("userStatus"), ::OpenAPI::toJsonValue(user_status));
|
obj.insert(QString("userStatus"), ::OpenAPI::toJsonValue(user_status));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIUser: public OAIObject {
|
class OAIUser: public OAIObject {
|
||||||
|
@ -46,6 +46,10 @@ void OAIUserApi::setApiTimeOutMs(const int tout){
|
|||||||
timeout = tout;
|
timeout = tout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OAIUserApi::setWorkingDirectory(const QString& path){
|
||||||
|
workingDirectory = path;
|
||||||
|
}
|
||||||
|
|
||||||
void OAIUserApi::addHeaders(const QString& key, const QString& value){
|
void OAIUserApi::addHeaders(const QString& key, const QString& value){
|
||||||
defaultHeaders.insert(key, value);
|
defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
@ -58,8 +62,9 @@ OAIUserApi::createUser(const OAIUser& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
|
|
||||||
|
|
||||||
QString output = body.asJson();
|
QString output = body.asJson();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
@ -107,8 +112,9 @@ OAIUserApi::createUsersWithArrayInput(const QList<OAIUser>& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
|
|
||||||
|
|
||||||
QJsonDocument doc(::OpenAPI::toJsonValue(body).toArray());
|
QJsonDocument doc(::OpenAPI::toJsonValue(body).toArray());
|
||||||
QByteArray bytes = doc.toJson();
|
QByteArray bytes = doc.toJson();
|
||||||
@ -157,8 +163,9 @@ OAIUserApi::createUsersWithListInput(const QList<OAIUser>& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "POST");
|
OAIHttpRequestInput input(fullPath, "POST");
|
||||||
|
|
||||||
|
|
||||||
QJsonDocument doc(::OpenAPI::toJsonValue(body).toArray());
|
QJsonDocument doc(::OpenAPI::toJsonValue(body).toArray());
|
||||||
QByteArray bytes = doc.toJson();
|
QByteArray bytes = doc.toJson();
|
||||||
@ -210,7 +217,9 @@ OAIUserApi::deleteUser(const QString& username) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "DELETE");
|
OAIHttpRequestInput input(fullPath, "DELETE");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -258,7 +267,9 @@ OAIUserApi::getUserByName(const QString& username) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -320,7 +331,9 @@ OAIUserApi::loginUser(const QString& username, const QString& password) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -367,7 +380,9 @@ OAIUserApi::logoutUser() {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "GET");
|
OAIHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(QString key, this->defaultHeaders.keys()) {
|
foreach(QString key, this->defaultHeaders.keys()) {
|
||||||
@ -415,8 +430,9 @@ OAIUserApi::updateUser(const QString& username, const OAIUser& body) {
|
|||||||
|
|
||||||
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
OAIHttpRequestWorker *worker = new OAIHttpRequestWorker(this);
|
||||||
worker->setTimeOut(timeout);
|
worker->setTimeOut(timeout);
|
||||||
|
worker->setWorkingDirectory(workingDirectory);
|
||||||
OAIHttpRequestInput input(fullPath, "PUT");
|
OAIHttpRequestInput input(fullPath, "PUT");
|
||||||
|
|
||||||
|
|
||||||
QString output = body.asJson();
|
QString output = body.asJson();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
|
@ -34,6 +34,7 @@ public:
|
|||||||
void setBasePath(const QString& basePath);
|
void setBasePath(const QString& basePath);
|
||||||
void setHost(const QString& host);
|
void setHost(const QString& host);
|
||||||
void setApiTimeOutMs(const int tout);
|
void setApiTimeOutMs(const int tout);
|
||||||
|
void setWorkingDirectory(const QString& path);
|
||||||
void addHeaders(const QString& key, const QString& value);
|
void addHeaders(const QString& key, const QString& value);
|
||||||
|
|
||||||
void createUser(const OAIUser& body);
|
void createUser(const OAIUser& body);
|
||||||
@ -48,6 +49,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
QString basePath;
|
QString basePath;
|
||||||
QString host;
|
QString host;
|
||||||
|
QString workingDirectory;
|
||||||
int timeout;
|
int timeout;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> defaultHeaders;
|
||||||
void createUserCallback (OAIHttpRequestWorker * worker);
|
void createUserCallback (OAIHttpRequestWorker * worker);
|
||||||
|
@ -15,8 +15,9 @@ HEADERS += \
|
|||||||
# Others
|
# Others
|
||||||
$${PWD}/OAIHelpers.h \
|
$${PWD}/OAIHelpers.h \
|
||||||
$${PWD}/OAIHttpRequest.h \
|
$${PWD}/OAIHttpRequest.h \
|
||||||
$${PWD}/OAIObject.h
|
$${PWD}/OAIObject.h \
|
||||||
$${PWD}/OAIEnum.h
|
$${PWD}/OAIEnum.h \
|
||||||
|
$${PWD}/OAIHttpFileElement.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
# Models
|
# Models
|
||||||
@ -32,5 +33,6 @@ SOURCES += \
|
|||||||
$${PWD}/OAIUserApi.cpp \
|
$${PWD}/OAIUserApi.cpp \
|
||||||
# Others
|
# Others
|
||||||
$${PWD}/OAIHelpers.cpp \
|
$${PWD}/OAIHelpers.cpp \
|
||||||
$${PWD}/OAIHttpRequest.cpp
|
$${PWD}/OAIHttpRequest.cpp \
|
||||||
|
$${PWD}/OAIHttpFileElement.cpp
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ void OAIPetApiHandler::updatePetWithForm(qint64 pet_id, QString name, QString st
|
|||||||
reqObj->updatePetWithFormResponse();
|
reqObj->updatePetWithFormResponse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void OAIPetApiHandler::uploadFile(qint64 pet_id, QString additional_metadata, QIODevice* file) {
|
void OAIPetApiHandler::uploadFile(qint64 pet_id, QString additional_metadata, OAIHttpFileElement file) {
|
||||||
Q_UNUSED(pet_id);
|
Q_UNUSED(pet_id);
|
||||||
Q_UNUSED(additional_metadata);
|
Q_UNUSED(additional_metadata);
|
||||||
Q_UNUSED(file);
|
Q_UNUSED(file);
|
||||||
|
@ -16,8 +16,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
#include "OAIApiResponse.h"
|
#include "OAIApiResponse.h"
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
#include "OAIPet.h"
|
#include "OAIPet.h"
|
||||||
#include <QIODevice>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
@ -39,7 +39,7 @@ public slots:
|
|||||||
virtual void getPetById(qint64 pet_id);
|
virtual void getPetById(qint64 pet_id);
|
||||||
virtual void updatePet(OAIPet body);
|
virtual void updatePet(OAIPet body);
|
||||||
virtual void updatePetWithForm(qint64 pet_id, QString name, QString status);
|
virtual void updatePetWithForm(qint64 pet_id, QString name, QString status);
|
||||||
virtual void uploadFile(qint64 pet_id, QString additional_metadata, QIODevice* file);
|
virtual void uploadFile(qint64 pet_id, QString additional_metadata, OAIHttpFileElement file);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIApiResponse.h"
|
#include "OAIApiResponse.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIApiResponse::OAIApiResponse(QString json) {
|
OAIApiResponse::OAIApiResponse(QString json) {
|
||||||
@ -81,13 +81,13 @@ OAIApiResponse::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIApiResponse::asJsonObject() const {
|
OAIApiResponse::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_code_isSet){
|
if(m_code_isSet){
|
||||||
obj.insert(QString("code"), ::OpenAPI::toJsonValue(code));
|
obj.insert(QString("code"), ::OpenAPI::toJsonValue(code));
|
||||||
}
|
}
|
||||||
if(m_type_isSet){
|
if(m_type_isSet){
|
||||||
obj.insert(QString("type"), ::OpenAPI::toJsonValue(type));
|
obj.insert(QString("type"), ::OpenAPI::toJsonValue(type));
|
||||||
}
|
}
|
||||||
if(m_message_isSet){
|
if(m_message_isSet){
|
||||||
obj.insert(QString("message"), ::OpenAPI::toJsonValue(message));
|
obj.insert(QString("message"), ::OpenAPI::toJsonValue(message));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIApiResponse: public OAIObject {
|
class OAIApiResponse: public OAIObject {
|
||||||
@ -53,7 +54,7 @@ public:
|
|||||||
void setMessage(const QString &message);
|
void setMessage(const QString &message);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAICategory.h"
|
#include "OAICategory.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAICategory::OAICategory(QString json) {
|
OAICategory::OAICategory(QString json) {
|
||||||
@ -75,10 +75,10 @@ OAICategory::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAICategory::asJsonObject() const {
|
OAICategory::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_name_isSet){
|
if(m_name_isSet){
|
||||||
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAICategory: public OAIObject {
|
class OAICategory: public OAIObject {
|
||||||
@ -49,7 +50,7 @@ public:
|
|||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ class OAIEnum {
|
|||||||
OAIEnum() {
|
OAIEnum() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OAIEnum(QString jsonString) {
|
OAIEnum(QString jsonString) {
|
||||||
fromJson(jsonString);
|
fromJson(jsonString);
|
||||||
}
|
}
|
||||||
@ -57,7 +57,7 @@ class OAIEnum {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private :
|
private :
|
||||||
QString jstr;
|
QString jstr;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -64,11 +64,23 @@ toStringValue(const double &value){
|
|||||||
return QString::number(value);
|
return QString::number(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const OAIObject &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString
|
QString
|
||||||
toStringValue(const OAIEnum &value){
|
toStringValue(const OAIEnum &value){
|
||||||
return value.asJson();
|
return value.asJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
toStringValue(const OAIHttpFileElement &value){
|
||||||
|
return value.asJson();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QJsonValue
|
QJsonValue
|
||||||
toJsonValue(const QString &value){
|
toJsonValue(const QString &value){
|
||||||
return QJsonValue(value);
|
return QJsonValue(value);
|
||||||
@ -124,6 +136,12 @@ toJsonValue(const OAIEnum &value){
|
|||||||
return value.asJsonValue();
|
return value.asJsonValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
toJsonValue(const OAIHttpFileElement &value){
|
||||||
|
return value.asJsonValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromStringValue(const QString &inStr, QString &value){
|
fromStringValue(const QString &inStr, QString &value){
|
||||||
value.clear();
|
value.clear();
|
||||||
@ -218,6 +236,11 @@ fromStringValue(const QString &inStr, OAIEnum &value){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromStringValue(const QString &inStr, OAIHttpFileElement &value){
|
||||||
|
return value.fromStringValue(inStr);
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
@ -229,7 +252,7 @@ fromJsonValue(QString &value, const QJsonValue &jval){
|
|||||||
} else if(jval.isDouble()){
|
} else if(jval.isDouble()){
|
||||||
value = QString::number(jval.toDouble());
|
value = QString::number(jval.toDouble());
|
||||||
} else {
|
} else {
|
||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ok = false;
|
ok = false;
|
||||||
@ -239,7 +262,7 @@ fromJsonValue(QString &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QDateTime &value, const QJsonValue &jval){
|
fromJsonValue(QDateTime &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
||||||
value = QDateTime::fromString(jval.toString(), Qt::ISODate);
|
value = QDateTime::fromString(jval.toString(), Qt::ISODate);
|
||||||
ok = value.isValid();
|
ok = value.isValid();
|
||||||
@ -263,7 +286,7 @@ fromJsonValue(QByteArray &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(QDate &value, const QJsonValue &jval){
|
fromJsonValue(QDate &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
|
||||||
value = QDate::fromString(jval.toString(), Qt::ISODate);
|
value = QDate::fromString(jval.toString(), Qt::ISODate);
|
||||||
ok = value.isValid();
|
ok = value.isValid();
|
||||||
@ -275,7 +298,7 @@ fromJsonValue(QDate &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(qint32 &value, const QJsonValue &jval){
|
fromJsonValue(qint32 &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
||||||
value = jval.toInt();
|
value = jval.toInt();
|
||||||
} else {
|
} else {
|
||||||
@ -286,7 +309,7 @@ fromJsonValue(qint32 &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(qint64 &value, const QJsonValue &jval){
|
fromJsonValue(qint64 &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
|
||||||
value = jval.toVariant().toLongLong();
|
value = jval.toVariant().toLongLong();
|
||||||
} else {
|
} else {
|
||||||
@ -297,7 +320,7 @@ fromJsonValue(qint64 &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(bool &value, const QJsonValue &jval){
|
fromJsonValue(bool &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isBool()){
|
if(jval.isBool()){
|
||||||
value = jval.toBool();
|
value = jval.toBool();
|
||||||
} else {
|
} else {
|
||||||
@ -308,7 +331,7 @@ fromJsonValue(bool &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(float &value, const QJsonValue &jval){
|
fromJsonValue(float &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isDouble()){
|
if(jval.isDouble()){
|
||||||
value = static_cast<float>(jval.toDouble());
|
value = static_cast<float>(jval.toDouble());
|
||||||
} else {
|
} else {
|
||||||
@ -319,7 +342,7 @@ fromJsonValue(float &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(double &value, const QJsonValue &jval){
|
fromJsonValue(double &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isDouble()){
|
if(jval.isDouble()){
|
||||||
value = jval.toDouble();
|
value = jval.toDouble();
|
||||||
} else {
|
} else {
|
||||||
@ -330,7 +353,7 @@ fromJsonValue(double &value, const QJsonValue &jval){
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
fromJsonValue(OAIObject &value, const QJsonValue &jval){
|
fromJsonValue(OAIObject &value, const QJsonValue &jval){
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
if(jval.isObject()){
|
if(jval.isObject()){
|
||||||
value.fromJsonObject(jval.toObject());
|
value.fromJsonObject(jval.toObject());
|
||||||
ok = value.isValid();
|
ok = value.isValid();
|
||||||
@ -346,4 +369,9 @@ fromJsonValue(OAIEnum &value, const QJsonValue &jval){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
fromJsonValue(OAIHttpFileElement &value, const QJsonValue &jval){
|
||||||
|
return value.fromJsonValue(jval);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,10 @@
|
|||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
@ -36,7 +38,9 @@ namespace OpenAPI {
|
|||||||
QString toStringValue(const bool &value);
|
QString toStringValue(const bool &value);
|
||||||
QString toStringValue(const float &value);
|
QString toStringValue(const float &value);
|
||||||
QString toStringValue(const double &value);
|
QString toStringValue(const double &value);
|
||||||
QString toStringValue(const OAIEnum &value);
|
QString toStringValue(const OAIObject &value);
|
||||||
|
QString toStringValue(const OAIEnum &value);
|
||||||
|
QString toStringValue(const OAIHttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QString toStringValue(const QList<T> &val) {
|
QString toStringValue(const QList<T> &val) {
|
||||||
@ -61,6 +65,7 @@ namespace OpenAPI {
|
|||||||
QJsonValue toJsonValue(const double &value);
|
QJsonValue toJsonValue(const double &value);
|
||||||
QJsonValue toJsonValue(const OAIObject &value);
|
QJsonValue toJsonValue(const OAIObject &value);
|
||||||
QJsonValue toJsonValue(const OAIEnum &value);
|
QJsonValue toJsonValue(const OAIEnum &value);
|
||||||
|
QJsonValue toJsonValue(const OAIHttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
QJsonValue toJsonValue(const QList<T> &val) {
|
QJsonValue toJsonValue(const QList<T> &val) {
|
||||||
@ -89,7 +94,9 @@ namespace OpenAPI {
|
|||||||
bool fromStringValue(const QString &inStr, bool &value);
|
bool fromStringValue(const QString &inStr, bool &value);
|
||||||
bool fromStringValue(const QString &inStr, float &value);
|
bool fromStringValue(const QString &inStr, float &value);
|
||||||
bool fromStringValue(const QString &inStr, double &value);
|
bool fromStringValue(const QString &inStr, double &value);
|
||||||
bool fromStringValue(const QString &inStr, OAIEnum &value);
|
bool fromStringValue(const QString &inStr, OAIObject &value);
|
||||||
|
bool fromStringValue(const QString &inStr, OAIEnum &value);
|
||||||
|
bool fromStringValue(const QString &inStr, OAIHttpFileElement &value);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||||
@ -124,6 +131,7 @@ namespace OpenAPI {
|
|||||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
|
bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
|
||||||
bool fromJsonValue(OAIEnum &value, const QJsonValue &jval);
|
bool fromJsonValue(OAIEnum &value, const QJsonValue &jval);
|
||||||
|
bool fromJsonValue(OAIHttpFileElement &value, const QJsonValue &jval);
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||||
@ -138,7 +146,7 @@ namespace OpenAPI {
|
|||||||
ok = false;
|
ok = false;
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
|
bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
|
||||||
|
@ -0,0 +1,162 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
|
|
||||||
|
namespace OpenAPI {
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setMimeType(const QString &mime){
|
||||||
|
mime_type = mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setFileName(const QString &name){
|
||||||
|
local_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setVariableName(const QString &name){
|
||||||
|
variable_name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
OAIHttpFileElement::setRequestFileName(const QString &name){
|
||||||
|
request_filename = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::isSet() const {
|
||||||
|
return !local_filename.isEmpty() || !request_filename.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString
|
||||||
|
OAIHttpFileElement::asJson() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QString(bArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonValue
|
||||||
|
OAIHttpFileElement::asJsonValue() const{
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return QJsonDocument::fromBinaryData(bArray.data()).object();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::fromStringValue(const QString &instr){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(instr.toUtf8());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::fromJsonValue(const QJsonValue &jval) {
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(QJsonDocument(jval.toObject()).toBinaryData());
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
OAIHttpFileElement::asByteArray() const {
|
||||||
|
QFile file(local_filename);
|
||||||
|
QByteArray bArray;
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()) {
|
||||||
|
result = file.open(QIODevice::ReadOnly);
|
||||||
|
bArray = file.readAll();
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error opening file " << local_filename;
|
||||||
|
}
|
||||||
|
return bArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::fromByteArray(const QByteArray& bytes){
|
||||||
|
QFile file(local_filename);
|
||||||
|
bool result = false;
|
||||||
|
if(file.exists()){
|
||||||
|
file.remove();
|
||||||
|
}
|
||||||
|
result = file.open(QIODevice::WriteOnly);
|
||||||
|
file.write(bytes);
|
||||||
|
file.close();
|
||||||
|
if(!result) {
|
||||||
|
qDebug() << "Error creating file " << local_filename;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
OAIHttpFileElement::saveToFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime, const QByteArray& bytes){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return fromByteArray(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray
|
||||||
|
OAIHttpFileElement::loadFromFile(const QString &varName, const QString &localFName, const QString &reqFname, const QString &mime){
|
||||||
|
setMimeType(mime);
|
||||||
|
setFileName(localFName);
|
||||||
|
setVariableName(varName);
|
||||||
|
setRequestFileName(reqFname);
|
||||||
|
return asByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
* 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 OAI_HTTP_FILE_ELEMENT_H
|
||||||
|
#define OAI_HTTP_FILE_ELEMENT_H
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QMetaType>
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
|
||||||
|
namespace OpenAPI {
|
||||||
|
|
||||||
|
class OAIHttpFileElement {
|
||||||
|
|
||||||
|
public:
|
||||||
|
QString variable_name;
|
||||||
|
QString local_filename;
|
||||||
|
QString request_filename;
|
||||||
|
QString mime_type;
|
||||||
|
void setMimeType(const QString &mime);
|
||||||
|
void setFileName(const QString &name);
|
||||||
|
void setVariableName(const QString &name);
|
||||||
|
void setRequestFileName(const QString &name);
|
||||||
|
bool isSet() const;
|
||||||
|
bool fromStringValue(const QString &instr);
|
||||||
|
bool fromJsonValue(const QJsonValue &jval);
|
||||||
|
bool fromByteArray(const QByteArray& bytes);
|
||||||
|
bool saveToFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime, const QByteArray& bytes);
|
||||||
|
QString asJson() const;
|
||||||
|
QJsonValue asJsonValue() const;
|
||||||
|
QByteArray asByteArray() const;
|
||||||
|
QByteArray loadFromFile(const QString &variable_name, const QString &local_filename, const QString &request_filename, const QString &mime);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(OpenAPI::OAIHttpFileElement)
|
||||||
|
|
||||||
|
#endif // OAI_HTTP_FILE_ELEMENT_H
|
@ -24,7 +24,7 @@ class OAIObject {
|
|||||||
OAIObject() {
|
OAIObject() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OAIObject(QString jsonString) {
|
OAIObject(QString jsonString) {
|
||||||
fromJson(jsonString);
|
fromJson(jsonString);
|
||||||
}
|
}
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIOrder.h"
|
#include "OAIOrder.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIOrder::OAIOrder(QString json) {
|
OAIOrder::OAIOrder(QString json) {
|
||||||
@ -99,22 +99,22 @@ OAIOrder::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIOrder::asJsonObject() const {
|
OAIOrder::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_pet_id_isSet){
|
if(m_pet_id_isSet){
|
||||||
obj.insert(QString("petId"), ::OpenAPI::toJsonValue(pet_id));
|
obj.insert(QString("petId"), ::OpenAPI::toJsonValue(pet_id));
|
||||||
}
|
}
|
||||||
if(m_quantity_isSet){
|
if(m_quantity_isSet){
|
||||||
obj.insert(QString("quantity"), ::OpenAPI::toJsonValue(quantity));
|
obj.insert(QString("quantity"), ::OpenAPI::toJsonValue(quantity));
|
||||||
}
|
}
|
||||||
if(m_ship_date_isSet){
|
if(m_ship_date_isSet){
|
||||||
obj.insert(QString("shipDate"), ::OpenAPI::toJsonValue(ship_date));
|
obj.insert(QString("shipDate"), ::OpenAPI::toJsonValue(ship_date));
|
||||||
}
|
}
|
||||||
if(m_status_isSet){
|
if(m_status_isSet){
|
||||||
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
||||||
}
|
}
|
||||||
if(m_complete_isSet){
|
if(m_complete_isSet){
|
||||||
obj.insert(QString("complete"), ::OpenAPI::toJsonValue(complete));
|
obj.insert(QString("complete"), ::OpenAPI::toJsonValue(complete));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIOrder: public OAIObject {
|
class OAIOrder: public OAIObject {
|
||||||
@ -66,7 +67,7 @@ public:
|
|||||||
void setComplete(const bool &complete);
|
void setComplete(const bool &complete);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIPet.h"
|
#include "OAIPet.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIPet::OAIPet(QString json) {
|
OAIPet::OAIPet(QString json) {
|
||||||
@ -99,24 +99,24 @@ OAIPet::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIPet::asJsonObject() const {
|
OAIPet::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(category.isSet()){
|
if(category.isSet()){
|
||||||
obj.insert(QString("category"), ::OpenAPI::toJsonValue(category));
|
obj.insert(QString("category"), ::OpenAPI::toJsonValue(category));
|
||||||
}
|
}
|
||||||
if(m_name_isSet){
|
if(m_name_isSet){
|
||||||
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(photo_urls.size() > 0){
|
if(photo_urls.size() > 0){
|
||||||
obj.insert(QString("photoUrls"), ::OpenAPI::toJsonValue(photo_urls));
|
obj.insert(QString("photoUrls"), ::OpenAPI::toJsonValue(photo_urls));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tags.size() > 0){
|
if(tags.size() > 0){
|
||||||
obj.insert(QString("tags"), ::OpenAPI::toJsonValue(tags));
|
obj.insert(QString("tags"), ::OpenAPI::toJsonValue(tags));
|
||||||
}
|
}
|
||||||
if(m_status_isSet){
|
if(m_status_isSet){
|
||||||
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
obj.insert(QString("status"), ::OpenAPI::toJsonValue(status));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIPet: public OAIObject {
|
class OAIPet: public OAIObject {
|
||||||
@ -68,7 +69,7 @@ public:
|
|||||||
void setStatus(const QString &status);
|
void setStatus(const QString &status);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAITag.h"
|
#include "OAITag.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAITag::OAITag(QString json) {
|
OAITag::OAITag(QString json) {
|
||||||
@ -75,10 +75,10 @@ OAITag::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAITag::asJsonObject() const {
|
OAITag::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_name_isSet){
|
if(m_name_isSet){
|
||||||
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
obj.insert(QString("name"), ::OpenAPI::toJsonValue(name));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAITag: public OAIObject {
|
class OAITag: public OAIObject {
|
||||||
@ -49,7 +50,7 @@ public:
|
|||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -13,13 +13,13 @@
|
|||||||
|
|
||||||
#include "OAIUser.h"
|
#include "OAIUser.h"
|
||||||
|
|
||||||
#include "OAIHelpers.h"
|
|
||||||
|
|
||||||
#include <QJsonDocument>
|
#include <QJsonDocument>
|
||||||
#include <QJsonArray>
|
#include <QJsonArray>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "OAIHelpers.h"
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
OAIUser::OAIUser(QString json) {
|
OAIUser::OAIUser(QString json) {
|
||||||
@ -111,28 +111,28 @@ OAIUser::asJson () const {
|
|||||||
QJsonObject
|
QJsonObject
|
||||||
OAIUser::asJsonObject() const {
|
OAIUser::asJsonObject() const {
|
||||||
QJsonObject obj;
|
QJsonObject obj;
|
||||||
if(m_id_isSet){
|
if(m_id_isSet){
|
||||||
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
obj.insert(QString("id"), ::OpenAPI::toJsonValue(id));
|
||||||
}
|
}
|
||||||
if(m_username_isSet){
|
if(m_username_isSet){
|
||||||
obj.insert(QString("username"), ::OpenAPI::toJsonValue(username));
|
obj.insert(QString("username"), ::OpenAPI::toJsonValue(username));
|
||||||
}
|
}
|
||||||
if(m_first_name_isSet){
|
if(m_first_name_isSet){
|
||||||
obj.insert(QString("firstName"), ::OpenAPI::toJsonValue(first_name));
|
obj.insert(QString("firstName"), ::OpenAPI::toJsonValue(first_name));
|
||||||
}
|
}
|
||||||
if(m_last_name_isSet){
|
if(m_last_name_isSet){
|
||||||
obj.insert(QString("lastName"), ::OpenAPI::toJsonValue(last_name));
|
obj.insert(QString("lastName"), ::OpenAPI::toJsonValue(last_name));
|
||||||
}
|
}
|
||||||
if(m_email_isSet){
|
if(m_email_isSet){
|
||||||
obj.insert(QString("email"), ::OpenAPI::toJsonValue(email));
|
obj.insert(QString("email"), ::OpenAPI::toJsonValue(email));
|
||||||
}
|
}
|
||||||
if(m_password_isSet){
|
if(m_password_isSet){
|
||||||
obj.insert(QString("password"), ::OpenAPI::toJsonValue(password));
|
obj.insert(QString("password"), ::OpenAPI::toJsonValue(password));
|
||||||
}
|
}
|
||||||
if(m_phone_isSet){
|
if(m_phone_isSet){
|
||||||
obj.insert(QString("phone"), ::OpenAPI::toJsonValue(phone));
|
obj.insert(QString("phone"), ::OpenAPI::toJsonValue(phone));
|
||||||
}
|
}
|
||||||
if(m_user_status_isSet){
|
if(m_user_status_isSet){
|
||||||
obj.insert(QString("userStatus"), ::OpenAPI::toJsonValue(user_status));
|
obj.insert(QString("userStatus"), ::OpenAPI::toJsonValue(user_status));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "OAIObject.h"
|
#include "OAIObject.h"
|
||||||
#include "OAIEnum.h"
|
#include "OAIEnum.h"
|
||||||
|
|
||||||
|
|
||||||
namespace OpenAPI {
|
namespace OpenAPI {
|
||||||
|
|
||||||
class OAIUser: public OAIObject {
|
class OAIUser: public OAIObject {
|
||||||
@ -73,7 +74,7 @@ public:
|
|||||||
void setUserStatus(const qint32 &user_status);
|
void setUserStatus(const qint32 &user_status);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
virtual bool isSet() const override;
|
virtual bool isSet() const override;
|
||||||
virtual bool isValid() const override;
|
virtual bool isValid() const override;
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ void OAIPetApiRequest::uploadFileRequest(const QString& pet_idstr){
|
|||||||
fromStringValue(pet_idstr, pet_id);
|
fromStringValue(pet_idstr, pet_id);
|
||||||
|
|
||||||
QString additional_metadata;
|
QString additional_metadata;
|
||||||
QIODevice* file;
|
OAIHttpFileElement file;
|
||||||
|
|
||||||
emit uploadFile(pet_id, additional_metadata, file);
|
emit uploadFile(pet_id, additional_metadata, file);
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
|
|
||||||
#include <qhttpengine/socket.h>
|
#include <qhttpengine/socket.h>
|
||||||
#include "OAIApiResponse.h"
|
#include "OAIApiResponse.h"
|
||||||
|
#include "OAIHttpFileElement.h"
|
||||||
#include "OAIPet.h"
|
#include "OAIPet.h"
|
||||||
#include <QIODevice>
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "OAIPetApiHandler.h"
|
#include "OAIPetApiHandler.h"
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ signals:
|
|||||||
void getPetById(qint64 pet_id);
|
void getPetById(qint64 pet_id);
|
||||||
void updatePet(OAIPet body);
|
void updatePet(OAIPet body);
|
||||||
void updatePetWithForm(qint64 pet_id, QString name, QString status);
|
void updatePetWithForm(qint64 pet_id, QString name, QString status);
|
||||||
void uploadFile(qint64 pet_id, QString additional_metadata, QIODevice* file);
|
void uploadFile(qint64 pet_id, QString additional_metadata, OAIHttpFileElement file);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user