Skip to content

Commit

Permalink
Update after reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
etherealjoy committed Sep 13, 2019
1 parent e4c656a commit b1431c7
Show file tree
Hide file tree
Showing 13 changed files with 253 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,10 +61,10 @@ public CppQt5AbstractCodegen() {
"double")
);
nonFrameworkPrimitives.addAll(languageSpecificPrimitives);

foundationClasses.addAll(
Arrays.asList(
"QString",
"QString",
"QDate",
"QDateTime",
"QByteArray")
Expand All @@ -78,7 +78,7 @@ public CppQt5AbstractCodegen() {
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");
Expand All @@ -90,7 +90,7 @@ public CppQt5AbstractCodegen() {
// modifications on multiple templates)
typeMapping.put("UUID", "QString");
typeMapping.put("URI", "QString");
typeMapping.put("file", "QIODevice");
typeMapping.put("file", "QByteArray");
typeMapping.put("binary", "QByteArray");
importMapping = new HashMap<String, String>();
namespaces = new HashMap<String, String>();
Expand All @@ -101,7 +101,6 @@ public CppQt5AbstractCodegen() {
systemIncludes.add("QDate");
systemIncludes.add("QDateTime");
systemIncludes.add("QByteArray");
systemIncludes.add("QIODevice");
}
@Override
public void processOpts() {
Expand All @@ -119,7 +118,7 @@ public void processOpts() {
additionalProperties().put("prefix", modelNamePrefix);
}
}

@Override
public String toModelImport(String name) {
if( name.isEmpty() ) {
Expand All @@ -140,7 +139,7 @@ public String toModelImport(String name) {

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
Expand Down Expand Up @@ -174,7 +173,7 @@ public String getTypeDeclaration(Schema p) {
}

@Override
@SuppressWarnings("rawtypes")
@SuppressWarnings("rawtypes")
public String toDefaultValue(Schema p) {
if (ModelUtils.isBooleanSchema(p)) {
return "false";
Expand Down Expand Up @@ -211,15 +210,15 @@ public String toDefaultValue(Schema p) {
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.
*
* @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);

Expand All @@ -242,7 +241,7 @@ public String getSchemaType(Schema p) {
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_]*$")) {
Expand Down Expand Up @@ -270,7 +269,7 @@ public String toParamName(String name) {
public String getTypeDeclaration(String str) {
return str;
}

@Override
protected boolean needToImport(String type) {
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
Expand All @@ -283,7 +282,7 @@ protected boolean needToImport(String type) {
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) {
Expand All @@ -298,7 +297,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
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)) {
Expand All @@ -308,7 +307,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
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)) {
Expand All @@ -321,7 +320,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
// We use QString to pass path params, add it to include
if(!isIncluded("QString", imports)) {
imports.add(createMapping("import", "QString"));
}
}
}
}
if(isIncluded("QMap", imports)) {
Expand All @@ -332,7 +331,7 @@ public Map<String, Object> postProcessOperationsWithModels(Map<String, Object> o
}
return objs;
}

@Override
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
return postProcessModelsEnum(objs);
Expand All @@ -342,18 +341,18 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public CppQt5ClientCodegen() {
addSwitch(CodegenConstants.OPTIONAL_PROJECT_FILE, OPTIONAL_PROJECT_FILE_DESC, this.optionalProjectFileFlag);
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder, PREFIX + "Helpers.h"));
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("HttpFileElement.h.mustache", sourceFolder, PREFIX + "HttpFileElement.h"));
supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, PREFIX + "HttpFileElement.cpp"));
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"));
}
Expand All @@ -96,15 +96,15 @@ public void processOpts() {
} 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"));
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder, modelNamePrefix + "Helpers.cpp"));
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("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));

typeMapping.put("file", modelNamePrefix + "HttpFileElement");
importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public CppQt5QHttpEngineServerCodegen() {
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
Expand All @@ -86,13 +86,13 @@ public CppQt5QHttpEngineServerCodegen() {
* 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("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"));

Expand All @@ -105,7 +105,7 @@ public CppQt5QHttpEngineServerCodegen() {
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\"");
importMapping.put(PREFIX + "HttpFileElement", "#include \"" + PREFIX + "HttpFileElement.h\"");

}

Expand All @@ -120,11 +120,11 @@ public void processOpts() {
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("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"));
Expand All @@ -133,7 +133,7 @@ public void processOpts() {
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\"");
importMapping.put(modelNamePrefix + "HttpFileElement", "#include \"" + modelNamePrefix + "HttpFileElement.h\"");
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ public String getName() {
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
Expand All @@ -191,7 +191,7 @@ public String apiFileFolder() {
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);
Expand All @@ -202,7 +202,7 @@ public String apiFilename(String templateName, String tag) {
}
return result;
}

@Override
public String toApiFilename(String name) {
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";
Expand Down
Loading

0 comments on commit b1431c7

Please sign in to comment.