From ebfddd0a5829c3b4d6817fd5c2acfbe4b63696a3 Mon Sep 17 00:00:00 2001 From: wing328 Date: Wed, 31 Aug 2016 15:49:22 +0800 Subject: [PATCH] remove unnecessary changes for python codegen --- .../io/swagger/codegen/CodegenConstants.java | 2 ++ .../io/swagger/codegen/DefaultGenerator.java | 7 +++++++ .../languages/PythonClientCodegen.java | 7 +++++++ .../src/main/resources/python/README.mustache | 2 ++ .../options/PythonClientOptionsProvider.java | 1 + samples/client/petstore/python/README.md | 21 +++++++++---------- .../python/petstore_api/configuration.py | 18 ++++++++-------- 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java index df62dcc19378..65bf8e32db5c 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/CodegenConstants.java @@ -127,4 +127,6 @@ public class CodegenConstants { public static final String GENERATE_MODEL_TESTS = "generateModelTests"; public static final String GENERATE_MODEL_TESTS_DESC = "Specifies that model tests are to be generated."; + public static final String HIDE_GENERATION_TIMESTAMP = "hideGenerationTimestamp"; + public static final String HIDE_GENERATION_TIMESTAMP_DESC = "Hides the generation timestamp."; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java index 90059a85b572..664d70d46c43 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java @@ -507,6 +507,13 @@ public class DefaultGenerator extends AbstractGenerator implements Generator { bundle.put("modelPackage", config.modelPackage()); List authMethods = config.fromSecurity(swagger.getSecurityDefinitions()); if (authMethods != null && !authMethods.isEmpty()) { + // sort auth methods to maintain the same order + Collections.sort(authMethods, new Comparator() { + @Override + public int compare(CodegenSecurity one, CodegenSecurity another) { + return ObjectUtils.compare(one.name, another.name); + } + }); bundle.put("authMethods", authMethods); bundle.put("hasAuthMethods", true); } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java index 6877e7e24a0e..328968a553ff 100755 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/PythonClientCodegen.java @@ -114,6 +114,8 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig .defaultValue("1.0.0")); cliOptions.add(CliOption.newBoolean(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, 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())); } @Override @@ -139,6 +141,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig setPackageVersion("1.0.0"); } + // default HIDE_GENERATION_TIMESTAMP to true + if (!additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) { + additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, Boolean.TRUE.toString()); + } + additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName); additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion); diff --git a/modules/swagger-codegen/src/main/resources/python/README.mustache b/modules/swagger-codegen/src/main/resources/python/README.mustache index d483fc3662a1..9f592946b061 100644 --- a/modules/swagger-codegen/src/main/resources/python/README.mustache +++ b/modules/swagger-codegen/src/main/resources/python/README.mustache @@ -7,7 +7,9 @@ This Python package is automatically generated by the [Swagger Codegen](https:// - API version: {{appVersion}} - Package version: {{packageVersion}} +{{^hideGenerationTimestamp}} - Build date: {{generatedDate}} +{{/hideGenerationTimestamp}} - Build package: {{generatorClass}} {{#infoUrl}} For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/PythonClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/PythonClientOptionsProvider.java index ec62e3f2b7c6..ccdb38d7bab9 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/PythonClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/PythonClientOptionsProvider.java @@ -21,6 +21,7 @@ public class PythonClientOptionsProvider implements OptionsProvider { return builder.put(CodegenConstants.PACKAGE_NAME, PACKAGE_NAME_VALUE) .put(CodegenConstants.PACKAGE_VERSION, PACKAGE_VERSION_VALUE) .put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "true") + .put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, "true") .build(); } diff --git a/samples/client/petstore/python/README.md b/samples/client/petstore/python/README.md index 1269b2f00295..ec654c5190e6 100644 --- a/samples/client/petstore/python/README.md +++ b/samples/client/petstore/python/README.md @@ -5,7 +5,6 @@ This Python package is automatically generated by the [Swagger Codegen](https:// - API version: 1.0.0 - Package version: 1.0.0 -- Build date: 2016-08-30T08:06:49.587+03:00 - Build package: class io.swagger.codegen.languages.PythonClientCodegen ## Requirements. @@ -131,6 +130,16 @@ Class | Method | HTTP request | Description ## Documentation For Authorization +## api_key + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + +## http_basic_test + +- **Type**: HTTP basic authentication + ## petstore_auth - **Type**: OAuth @@ -140,16 +149,6 @@ Class | Method | HTTP request | Description - **write:pets**: modify pets in your account - **read:pets**: read your pets -## http_basic_test - -- **Type**: HTTP basic authentication - -## api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - ## Author diff --git a/samples/client/petstore/python/petstore_api/configuration.py b/samples/client/petstore/python/petstore_api/configuration.py index 6cea276204a6..d2f3b06a5586 100644 --- a/samples/client/petstore/python/petstore_api/configuration.py +++ b/samples/client/petstore/python/petstore_api/configuration.py @@ -216,13 +216,12 @@ class Configuration(object): :return: The Auth Settings information dict. """ return { - - 'petstore_auth': + 'api_key': { - 'type': 'oauth2', + 'type': 'api_key', 'in': 'header', - 'key': 'Authorization', - 'value': 'Bearer ' + self.access_token + 'key': 'api_key', + 'value': self.get_api_key_with_prefix('api_key') }, 'http_basic_test': { @@ -231,12 +230,13 @@ class Configuration(object): 'key': 'Authorization', 'value': self.get_basic_auth_token() }, - 'api_key': + + 'petstore_auth': { - 'type': 'api_key', + 'type': 'oauth2', 'in': 'header', - 'key': 'api_key', - 'value': self.get_api_key_with_prefix('api_key') + 'key': 'Authorization', + 'value': 'Bearer ' + self.access_token }, }