forked from loafle/openapi-generator-original
[python-client] Modify python templates to resolve linting errors (#6839)
The linting results for the generated samples are as follows where the first number is the BEFORE and the second is AFTER. pyclient 7714 vs. 120 pyclient3 7717 vs. 120 pyclient3-asyncio 7584 vs. 120 pyclient-tornado 7633 vs. 120 pyclient3-tornado 7633 vs. 120 For the complete details please see the following gist. https://gist.github.com/kenjones-cisco/2eb69a7e8db75e9fd53789f01570d9f2 Enforces linting for python clients by running flake8 for the generated python client.
This commit is contained in:
@@ -67,6 +67,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
languageSpecificPrimitives.add("int");
|
||||
languageSpecificPrimitives.add("float");
|
||||
languageSpecificPrimitives.add("list");
|
||||
languageSpecificPrimitives.add("dict");
|
||||
languageSpecificPrimitives.add("bool");
|
||||
languageSpecificPrimitives.add("str");
|
||||
languageSpecificPrimitives.add("datetime");
|
||||
@@ -189,21 +190,16 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
setPackageUrl((String) additionalProperties.get(PACKAGE_URL));
|
||||
}
|
||||
|
||||
String swaggerFolder = packageName;
|
||||
|
||||
modelPackage = swaggerFolder + File.separatorChar + "models";
|
||||
apiPackage = swaggerFolder + File.separatorChar + "apis";
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("tox.mustache", "", "tox.ini"));
|
||||
supportingFiles.add(new SupportingFile("test-requirements.mustache", "", "test-requirements.txt"));
|
||||
supportingFiles.add(new SupportingFile("requirements.mustache", "", "requirements.txt"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", swaggerFolder, "configuration.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__package.mustache", swaggerFolder, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__model.mustache", modelPackage, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__api.mustache", apiPackage, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("configuration.mustache", packageName, "configuration.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__package.mustache", packageName, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__model.mustache", packageName + File.separatorChar + modelPackage, "__init__.py"));
|
||||
supportingFiles.add(new SupportingFile("__init__api.mustache", packageName + File.separatorChar + apiPackage, "__init__.py"));
|
||||
|
||||
if(Boolean.FALSE.equals(excludeTests)) {
|
||||
supportingFiles.add(new SupportingFile("__init__test.mustache", testFolder, "__init__.py"));
|
||||
@@ -212,23 +208,42 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile("gitignore.mustache", "", ".gitignore"));
|
||||
supportingFiles.add(new SupportingFile("travis.mustache", "", ".travis.yml"));
|
||||
supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", swaggerFolder, "api_client.py"));
|
||||
supportingFiles.add(new SupportingFile("api_client.mustache", packageName, "api_client.py"));
|
||||
|
||||
if ("asyncio".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("asyncio/rest.mustache", swaggerFolder, "rest.py"));
|
||||
supportingFiles.add(new SupportingFile("asyncio/rest.mustache", packageName, "rest.py"));
|
||||
additionalProperties.put("asyncio", "true");
|
||||
} else if ("tornado".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("tornado/rest.mustache", swaggerFolder, "rest.py"));
|
||||
supportingFiles.add(new SupportingFile("tornado/rest.mustache", packageName, "rest.py"));
|
||||
additionalProperties.put("tornado", "true");
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", swaggerFolder, "rest.py"));
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", packageName, "rest.py"));
|
||||
}
|
||||
|
||||
modelPackage = packageName + "." + modelPackage;
|
||||
apiPackage = packageName + "." + apiPackage;
|
||||
|
||||
}
|
||||
|
||||
private static String dropDots(String str) {
|
||||
return str.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toModelImport(String name) {
|
||||
String modelImport;
|
||||
if (StringUtils.startsWithAny(name,"import", "from")) {
|
||||
modelImport = name;
|
||||
} else {
|
||||
modelImport = "from ";
|
||||
if (!"".equals(modelPackage())) {
|
||||
modelImport += modelPackage() + ".";
|
||||
}
|
||||
modelImport += toModelFilename(name)+ " import " + name;
|
||||
}
|
||||
return modelImport;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// process enum in models
|
||||
|
||||
Reference in New Issue
Block a user