Skip to content

Commit 81cdc82

Browse files
authored
fix(ruby-client): fix incorrect Date parsing in OneOf (#21364)
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.
1 parent 9ebc630 commit 81cdc82

File tree

6 files changed

+6
-6
lines changed

6 files changed

+6
-6
lines changed

modules/openapi-generator/src/main/resources/ruby-client/partial_anyof_module.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
when 'Time'
5757
return Time.parse(data)
5858
when 'Date'
59-
return Date.parse(data)
59+
return Date.iso8601(data)
6060
when 'String'
6161
return data if data.instance_of?(String)
6262
when 'Object' # "type: object"

modules/openapi-generator/src/main/resources/ruby-client/partial_oneof_module.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
when 'Time'
9999
return Time.parse(data)
100100
when 'Date'
101-
return Date.parse(data)
101+
return Date.iso8601(data)
102102
when 'String'
103103
return data if data.instance_of?(String)
104104
when 'Object' # "type: object"

samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_anyof.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def find_and_cast_into_type(klass, data)
6464
when 'Time'
6565
return Time.parse(data)
6666
when 'Date'
67-
return Date.parse(data)
67+
return Date.iso8601(data)
6868
when 'String'
6969
return data if data.instance_of?(String)
7070
when 'Object' # "type: object"

samples/client/petstore/ruby-httpx/lib/petstore/models/mammal_without_discriminator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def find_and_cast_into_type(klass, data)
6565
when 'Time'
6666
return Time.parse(data)
6767
when 'Date'
68-
return Date.parse(data)
68+
return Date.iso8601(data)
6969
when 'String'
7070
return data if data.instance_of?(String)
7171
when 'Object' # "type: object"

samples/client/petstore/ruby/lib/petstore/models/mammal_anyof.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def find_and_cast_into_type(klass, data)
6464
when 'Time'
6565
return Time.parse(data)
6666
when 'Date'
67-
return Date.parse(data)
67+
return Date.iso8601(data)
6868
when 'String'
6969
return data if data.instance_of?(String)
7070
when 'Object' # "type: object"

samples/client/petstore/ruby/lib/petstore/models/mammal_without_discriminator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def find_and_cast_into_type(klass, data)
6565
when 'Time'
6666
return Time.parse(data)
6767
when 'Date'
68-
return Date.parse(data)
68+
return Date.iso8601(data)
6969
when 'String'
7070
return data if data.instance_of?(String)
7171
when 'Object' # "type: object"

0 commit comments

Comments
 (0)