From 935bdfe6280eea9f32a30d76bee2801b763c3ac9 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 8 Nov 2016 16:17:51 +0800 Subject: [PATCH] better handling of */* --- .../main/java/io/swagger/codegen/DefaultCodegen.java | 12 ++++++++++-- .../src/main/resources/ruby/api_client.mustache | 3 ++- ...store-with-fake-endpoints-models-for-testing.yaml | 4 ++-- samples/client/petstore/ruby/docs/FakeApi.md | 4 ++-- .../petstore/ruby/lib/petstore/api/fake_api.rb | 4 ++-- .../client/petstore/ruby/lib/petstore/api_client.rb | 3 ++- 6 files changed, 20 insertions(+), 10 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index 23bfb825bea..63cad401d02 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1892,7 +1892,11 @@ public class DefaultCodegen { for (String key : consumes) { Map mediaType = new HashMap(); // escape quotation to avoid code injection - mediaType.put("mediaType", escapeText(escapeQuotationMark(key))); + if ("*/*".equals(key)) { // "*/*" is a special case, do nothing + mediaType.put("mediaType", key); + } else { + mediaType.put("mediaType", escapeText(escapeQuotationMark(key))); + } count += 1; if (count < consumes.size()) { mediaType.put("hasMore", "true"); @@ -1926,7 +1930,11 @@ public class DefaultCodegen { for (String key : produces) { Map mediaType = new HashMap(); // escape quotation to avoid code injection - mediaType.put("mediaType", escapeText(escapeQuotationMark(key))); + if ("*/*".equals(key)) { // "*/*" is a special case, do nothing + mediaType.put("mediaType", key); + } else { + mediaType.put("mediaType", escapeText(escapeQuotationMark(key))); + } count += 1; if (count < produces.size()) { mediaType.put("hasMore", "true"); diff --git a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache index fcd4b3eebfa..7fa611e3744 100644 --- a/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache +++ b/modules/swagger-codegen/src/main/resources/ruby/api_client.mustache @@ -125,10 +125,11 @@ module {{moduleName}} # application/json # application/json; charset=UTF8 # APPLICATION/JSON + # */* # @param [String] mime MIME # @return [Boolean] True if the MIME is application/json def json_mime?(mime) - !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil? + (mime == "*/*") || !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil? end # Deserialize the response to the given return type. diff --git a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml index c42dc774a22..4666a0cc167 100644 --- a/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml +++ b/modules/swagger-codegen/src/test/resources/2_0/petstore-with-fake-endpoints-models-for-testing.yaml @@ -590,9 +590,9 @@ paths: descriptions: To test enum parameters operationId: testEnumParameters consumes: - - application/json + - "*/*" produces: - - application/json + - "*/*" parameters: - name: enum_form_string_array type: array diff --git a/samples/client/petstore/ruby/docs/FakeApi.md b/samples/client/petstore/ruby/docs/FakeApi.md index 1524d9c915f..971fdadb1ae 100644 --- a/samples/client/petstore/ruby/docs/FakeApi.md +++ b/samples/client/petstore/ruby/docs/FakeApi.md @@ -191,8 +191,8 @@ No authorization required ### HTTP request headers - - **Content-Type**: application/json - - **Accept**: application/json + - **Content-Type**: */* + - **Accept**: */* diff --git a/samples/client/petstore/ruby/lib/petstore/api/fake_api.rb b/samples/client/petstore/ruby/lib/petstore/api/fake_api.rb index 3500dfbb52f..a9c7cf07710 100644 --- a/samples/client/petstore/ruby/lib/petstore/api/fake_api.rb +++ b/samples/client/petstore/ruby/lib/petstore/api/fake_api.rb @@ -306,11 +306,11 @@ module Petstore header_params = {} # HTTP header 'Accept' (if needed) - local_header_accept = ['application/json'] + local_header_accept = ['*/*'] local_header_accept_result = @api_client.select_header_accept(local_header_accept) and header_params['Accept'] = local_header_accept_result # HTTP header 'Content-Type' - local_header_content_type = ['application/json'] + local_header_content_type = ['*/*'] header_params['Content-Type'] = @api_client.select_header_content_type(local_header_content_type) header_params[:'enum_header_string_array'] = @api_client.build_collection_param(opts[:'enum_header_string_array'], :csv) if !opts[:'enum_header_string_array'].nil? header_params[:'enum_header_string'] = opts[:'enum_header_string'] if !opts[:'enum_header_string'].nil? diff --git a/samples/client/petstore/ruby/lib/petstore/api_client.rb b/samples/client/petstore/ruby/lib/petstore/api_client.rb index 0a95711ce43..64cc2e286c2 100644 --- a/samples/client/petstore/ruby/lib/petstore/api_client.rb +++ b/samples/client/petstore/ruby/lib/petstore/api_client.rb @@ -142,10 +142,11 @@ module Petstore # application/json # application/json; charset=UTF8 # APPLICATION/JSON + # */* # @param [String] mime MIME # @return [Boolean] True if the MIME is application/json def json_mime?(mime) - !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil? + (mime == "*/*") || !(mime =~ /\Aapplication\/json(;.*)?\z/i).nil? end # Deserialize the response to the given return type.