mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-03-24 01:49:11 +00:00
[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:
@@ -26,7 +26,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
protected Set<String> systemIncludes = new HashSet<String>();
|
||||
|
||||
protected Set<String> nonFrameworkPrimitives = new HashSet<String>();
|
||||
|
||||
|
||||
public CppQt5AbstractCodegen() {
|
||||
super();
|
||||
// set modelNamePrefix as default for QHttpEngine Server
|
||||
@@ -61,10 +61,10 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
"double")
|
||||
);
|
||||
nonFrameworkPrimitives.addAll(languageSpecificPrimitives);
|
||||
|
||||
|
||||
foundationClasses.addAll(
|
||||
Arrays.asList(
|
||||
"QString",
|
||||
"QString",
|
||||
"QDate",
|
||||
"QDateTime",
|
||||
"QByteArray")
|
||||
@@ -78,7 +78,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
typeMapping.put("integer", "qint32");
|
||||
typeMapping.put("long", "qint64");
|
||||
typeMapping.put("boolean", "bool");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("number", "double");
|
||||
typeMapping.put("array", "QList");
|
||||
typeMapping.put("map", "QMap");
|
||||
typeMapping.put("object", PREFIX + "Object");
|
||||
@@ -90,8 +90,8 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
// modifications on multiple templates)
|
||||
typeMapping.put("UUID", "QString");
|
||||
typeMapping.put("URI", "QString");
|
||||
typeMapping.put("file", "QIODevice");
|
||||
typeMapping.put("binary", "QIODevice");
|
||||
typeMapping.put("file", "QByteArray");
|
||||
typeMapping.put("binary", "QByteArray");
|
||||
importMapping = 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("QDateTime");
|
||||
systemIncludes.add("QByteArray");
|
||||
systemIncludes.add("QIODevice");
|
||||
}
|
||||
@Override
|
||||
public void processOpts() {
|
||||
@@ -119,7 +118,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
additionalProperties().put("prefix", modelNamePrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
if( name.isEmpty() ) {
|
||||
@@ -140,7 +139,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
|
||||
return "#include \"" + folder + name + ".h\"";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -160,9 +159,9 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
Schema inner = ModelUtils.getAdditionalProperties(p);
|
||||
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">";
|
||||
} else if (ModelUtils.isBinarySchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
return getSchemaType(p);
|
||||
} else if (ModelUtils.isFileSchema(p)) {
|
||||
return getSchemaType(p) + "*";
|
||||
return getSchemaType(p);
|
||||
}
|
||||
if (foundationClasses.contains(openAPIType)) {
|
||||
return openAPIType;
|
||||
@@ -174,7 +173,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String toDefaultValue(Schema p) {
|
||||
if (ModelUtils.isBooleanSchema(p)) {
|
||||
return "false";
|
||||
@@ -211,7 +210,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
public String toModelFilename(String name) {
|
||||
return toModelName(name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -219,7 +218,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
* @return a string value of the type or complex model for this property
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
@SuppressWarnings("rawtypes")
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
@@ -242,7 +241,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
public String toVarName(String name) {
|
||||
// sanitize name
|
||||
String varName = name;
|
||||
varName = sanitizeName(name);
|
||||
varName = sanitizeName(name);
|
||||
|
||||
// if it's all uppper case, convert to lower case
|
||||
if (varName.matches("^[A-Z_]*$")) {
|
||||
@@ -270,7 +269,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
public String getTypeDeclaration(String str) {
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean needToImport(String 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) {
|
||||
Map<String, Object> objectMap = (Map<String, Object>) objs.get("operations");
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
|
||||
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel> ();
|
||||
for(Object moObj : allModels) {
|
||||
@@ -298,7 +297,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
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
|
||||
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||
if(!isIncluded(operation.returnBaseType, imports)) {
|
||||
@@ -308,7 +307,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
List<CodegenParameter> params = new ArrayList<CodegenParameter>();
|
||||
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
|
||||
for(CodegenParameter param : params) {
|
||||
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
|
||||
if(!isIncluded("QString", imports)) {
|
||||
imports.add(createMapping("import", "QString"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(isIncluded("QMap", imports)) {
|
||||
@@ -332,7 +331,7 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
return postProcessModelsEnum(objs);
|
||||
@@ -342,18 +341,18 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
return escapeText(value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDataTypeString(String dataType) {
|
||||
return "QString".equals(dataType);
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> createMapping(String key, String value) {
|
||||
Map<String, String> customImport = new HashMap<String, String>();
|
||||
customImport.put(key, toModelImport(value));
|
||||
return customImport;
|
||||
}
|
||||
|
||||
|
||||
private boolean isIncluded(String type, List<Map<String, String>> imports) {
|
||||
boolean included = false;
|
||||
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("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
||||
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("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
||||
}
|
||||
typeMapping.put("file", PREFIX + "HttpRequestInputFileElement");
|
||||
typeMapping.put("binary", PREFIX +"HttpRequestInputFileElement");
|
||||
importMapping.put(PREFIX + "HttpRequestInputFileElement", "#include \"" + PREFIX + "HttpRequest.h\"");
|
||||
typeMapping.put("file", PREFIX + "HttpFileElement");
|
||||
importMapping.put(PREFIX + "HttpFileElement", "#include \"" + PREFIX + "HttpFileElement.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,7 +96,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
||||
} else {
|
||||
additionalProperties.put(CodegenConstants.OPTIONAL_PROJECT_FILE, optionalProjectFileFlag);
|
||||
}
|
||||
|
||||
|
||||
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||
supportingFiles.clear();
|
||||
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.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
||||
|
||||
typeMapping.put("file", modelNamePrefix + "HttpRequestInputFileElement");
|
||||
typeMapping.put("binary", modelNamePrefix + "HttpRequestInputFileElement");
|
||||
importMapping.put(modelNamePrefix + "HttpRequestInputFileElement", "#include \"" + modelNamePrefix + "HttpRequest.h\"");
|
||||
typeMapping.put("file", modelNamePrefix + "HttpFileElement");
|
||||
importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\"");
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, modelNamePrefix + "client.pri"));
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
||||
apiTemplateFiles.put(
|
||||
"apirequest.h.mustache", // the template to use
|
||||
".h"); // the extension for each file to write
|
||||
|
||||
|
||||
apiTemplateFiles.put(
|
||||
"apirequest.cpp.mustache", // the template to use
|
||||
".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.
|
||||
*/
|
||||
embeddedTemplateDir = templateDir = "cpp-qt5-qhttpengine-server";
|
||||
|
||||
|
||||
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("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("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.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("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||
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("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.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.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("src-CMakeLists.txt.mustache", sourceFolder + SRC_DIR, "CMakeLists.txt"));
|
||||
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("Dockerfile.mustache", sourceFolder, "Dockerfile"));
|
||||
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() {
|
||||
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
|
||||
* instantiated
|
||||
@@ -182,7 +191,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
||||
private String requestFileFolder() {
|
||||
return outputFolder + "/" + sourceFolder + APIREQUEST_DIR + "/" + apiPackage().replace("::", File.separator);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
@@ -193,7 +202,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";
|
||||
|
||||
Reference in New Issue
Block a user