forked from loafle/openapi-generator-original
[python] asyncio support (#6245)
* trying an approach with providing asyncio as a framework. * adding example of asyncio. * removing sample client to help PR look more manageable. * possibly fixing a unit test * getting unit test to pass again. * addressing comments.
This commit is contained in:
@@ -21,8 +21,11 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
|
||||
public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public static final String PACKAGE_URL = "packageUrl";
|
||||
public static final String DEFAULT_LIBRARY = "urllib3";
|
||||
|
||||
protected String packageName; // e.g. petstore_api
|
||||
protected String packageVersion;
|
||||
@@ -124,6 +127,13 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG_DESC).defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "hides the timestamp when files were generated")
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
|
||||
supportedLibraries.put("urllib3", "urllib3-based client");
|
||||
supportedLibraries.put("asyncio", "Asyncio-based client (python 3.5+)");
|
||||
CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
libraryOption.setDefault(DEFAULT_LIBRARY);
|
||||
cliOptions.add(libraryOption);
|
||||
setLibrary(DEFAULT_LIBRARY);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,13 +195,10 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
supportingFiles.add(new SupportingFile("setup.mustache", "", "setup.py"));
|
||||
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("api_client.mustache", swaggerFolder, "api_client.py"));
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", swaggerFolder, "rest.py"));
|
||||
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"));
|
||||
@@ -203,6 +210,15 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh"));
|
||||
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"));
|
||||
|
||||
if ("asyncio".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("asyncio/rest.mustache", swaggerFolder, "rest.py"));
|
||||
additionalProperties.put("asyncio", "true");
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("rest.mustache", swaggerFolder, "rest.py"));
|
||||
}
|
||||
}
|
||||
|
||||
private static String dropDots(String str) {
|
||||
|
||||
Reference in New Issue
Block a user