[C] Resolve some issues from #1473 (#1497)

* change folder structure for external and added list as primitive type

* modified gitignore for C generator

* change include statement as per directory structure

* added projectname variable for using in cmakelists

* modified cmakefile:compile files irrespective of testfiles and add support for make install

* updated readme with how to compile and how to use

* CMakeLists change curl to 7.58.0

* fix indentation

* add remove as reserved word
This commit is contained in:
Hemant Zope
2018-12-06 04:39:30 +01:00
committed by William Cheng
parent 32d228c33a
commit df19c13347
14 changed files with 130 additions and 85 deletions

View File

@@ -18,6 +18,8 @@ package org.openapitools.codegen.languages;
import io.swagger.v3.oas.models.media.ArraySchema;
import io.swagger.v3.oas.models.media.Schema;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.utils.ModelUtils;
@@ -38,7 +40,10 @@ import java.util.Set;
public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(CLibcurlClientCodegen.class);
public static final String PROJECT_NAME = "projectName";
protected String moduleName;
protected String projectName;
protected static final String defaultProjectName = "openapi_client";
protected String specFolder = "spec";
protected String libFolder = "lib";
protected String apiDocPath = "docs/";
@@ -93,6 +98,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
"int",
"long",
"register",
"remove",
"restrict",
"return",
"short",
@@ -135,6 +141,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
languageSpecificPrimitives.add("FILE");
languageSpecificPrimitives.add("Object");
languageSpecificPrimitives.add("list_t*");
languageSpecificPrimitives.add("list");
typeMapping.put("string", "char");
typeMapping.put("char", "char");
@@ -200,8 +207,8 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
supportingFiles.add(new SupportingFile("list.h.mustache", "include", "list.h"));
// external folder
supportingFiles.add(new SupportingFile("cJSON.licence.mustache", "external", "cJSON.licence"));
supportingFiles.add(new SupportingFile("cJSON.c.mustache", "external" + File.separator + "src", "cJSON.c"));
supportingFiles.add(new SupportingFile("cJSON.h.mustache", "external" + File.separator + "include", "cJSON.h"));
supportingFiles.add(new SupportingFile("cJSON.c.mustache", "external", "cJSON.c"));
supportingFiles.add(new SupportingFile("cJSON.h.mustache", "external", "cJSON.h"));
}
@@ -500,7 +507,7 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
@Override
public String toModelImport(String name) {
return "#include \"" + name + ".h\"";
return "#include \"" +"../model/" + name + ".h\"";
}
@Override
@@ -567,6 +574,21 @@ public class CLibcurlClientCodegen extends DefaultCodegen implements CodegenConf
p.example = example;
}
@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
if (openAPI.getInfo() != null) {
Info info = openAPI.getInfo();
setProjectName((escapeText(info.getTitle())));
} else {
setProjectName(defaultProjectName);
}
additionalProperties.put(PROJECT_NAME, projectName);
}
public void setProjectName(String projectName) {
this.projectName = underscore(projectName.toLowerCase(Locale.ROOT));
}
@Override
public boolean shouldOverwrite(String filename) {
// skip spec file as the file might have been updated with new test cases