From 8924da5a6595cf65cb2f56651ddd7bd553eee1ab Mon Sep 17 00:00:00 2001 From: LuukvH Date: Mon, 2 Jun 2025 23:40:19 +0200 Subject: [PATCH] fix(ruby-client): fix incorrect Date parsing in OneOf Changes Date.parse to Date.iso8601 to fix incorrect type coercion in OneOf contexts. Previously, arbitrary strings matching Date.parse's lenient pattern (e.g., "ABC1") were incorrectly coerced to dates (2025-06-01), when they should have remained as strings. For example: - "ABC1" was parsed as Date(2025-06-01) instead of remaining "ABC1" - This occurred because Date.parse treats the first char as month ('A'=1) and remaining digits as day The fix ensures only ISO8601 formatted strings (e.g. "2025-06-02") are parsed as dates, improving type safety and preventing unexpected coercion of string values. --- .../main/resources/ruby-client/partial_anyof_module.mustache | 2 +- .../main/resources/ruby-client/partial_oneof_module.mustache | 2 +- .../petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb | 2 +- .../lib/petstore/models/mammal_without_discriminator.rb | 2 +- .../client/petstore/ruby/lib/petstore/models/mammal_anyof.rb | 2 +- .../ruby/lib/petstore/models/mammal_without_discriminator.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ruby-client/partial_anyof_module.mustache b/modules/openapi-generator/src/main/resources/ruby-client/partial_anyof_module.mustache index 778568c2c31c..f979fdd3100e 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/partial_anyof_module.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/partial_anyof_module.mustache @@ -56,7 +56,7 @@ when 'Time' return Time.parse(data) when 'Date' - return Date.parse(data) + return Date.iso8601(data) when 'String' return data if data.instance_of?(String) when 'Object' # "type: object" diff --git a/modules/openapi-generator/src/main/resources/ruby-client/partial_oneof_module.mustache b/modules/openapi-generator/src/main/resources/ruby-client/partial_oneof_module.mustache index d3a25f69ed5e..8dd7b381d2bd 100644 --- a/modules/openapi-generator/src/main/resources/ruby-client/partial_oneof_module.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-client/partial_oneof_module.mustache @@ -98,7 +98,7 @@ when 'Time' return Time.parse(data) when 'Date' - return Date.parse(data) + return Date.iso8601(data) when 'String' return data if data.instance_of?(String) when 'Object' # "type: object" diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb index e15e001c7ccd..c5ef0a052ce6 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb @@ -64,7 +64,7 @@ def find_and_cast_into_type(klass, data) when 'Time' return Time.parse(data) when 'Date' - return Date.parse(data) + return Date.iso8601(data) when 'String' return data if data.instance_of?(String) when 'Object' # "type: object" diff --git a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb index 7c37e6492dd6..9042380114e5 100644 --- a/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb +++ b/samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb @@ -65,7 +65,7 @@ def find_and_cast_into_type(klass, data) when 'Time' return Time.parse(data) when 'Date' - return Date.parse(data) + return Date.iso8601(data) when 'String' return data if data.instance_of?(String) when 'Object' # "type: object" diff --git a/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb b/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb index e15e001c7ccd..c5ef0a052ce6 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb @@ -64,7 +64,7 @@ def find_and_cast_into_type(klass, data) when 'Time' return Time.parse(data) when 'Date' - return Date.parse(data) + return Date.iso8601(data) when 'String' return data if data.instance_of?(String) when 'Object' # "type: object" diff --git a/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb b/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb index 7c37e6492dd6..9042380114e5 100644 --- a/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb +++ b/samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb @@ -65,7 +65,7 @@ def find_and_cast_into_type(klass, data) when 'Time' return Time.parse(data) when 'Date' - return Date.parse(data) + return Date.iso8601(data) when 'String' return data if data.instance_of?(String) when 'Object' # "type: object"