From bb7419b20d591048a97908155aec424ca1af2ecf Mon Sep 17 00:00:00 2001 From: Inf1mum Date: Thu, 19 Nov 2026 16:26:29 +0300 Subject: [PATCH] Fix #25721: add Date branch to ruby-nextgen Polymorphism cast/coerce format: date properties are declared as Date in ruby-nextgen, but Polymorphism.cast_raw and Polymorphism.coerce only had a Time branch. from_hash left such properties as String, and a Date candidate of an anyOf/oneOf never matched. Add cast_date/coerce_date mirroring the existing Time handling and require 'date' in the generated gem entry. Signed-off-by: Inf1mum --- .../main/resources/ruby-nextgen/gem.mustache | 1 + .../ruby-nextgen/polymorphism.mustache | 24 +++++++++++++++++++ .../others/ruby-nextgen-qdrant/lib/qdrant.rb | 1 + .../lib/qdrant/polymorphism.rb | 24 +++++++++++++++++++ .../petstore/ruby-nextgen/lib/petstore.rb | 1 + .../ruby-nextgen/lib/petstore/polymorphism.rb | 24 +++++++++++++++++++ 6 files changed, 75 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache b/modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache index e411a4277681..25f35216530e 100644 --- a/modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-nextgen/gem.mustache @@ -2,6 +2,7 @@ {{> api_info}} +require 'date' require 'erb' require 'forwardable' require 'json' diff --git a/modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache b/modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache index cda9a2866e55..9adcf90dcea6 100644 --- a/modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache +++ b/modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache @@ -40,6 +40,8 @@ module {{moduleName}} data.is_a?(String) ? data : NO_MATCH when 'Time' cast_time(data) + when 'Date' + cast_date(data) when 'Object', 'Hash' data.is_a?(Hash) ? data : NO_MATCH when ARRAY_TYPE @@ -61,6 +63,15 @@ module {{moduleName}} end private_class_method :cast_time + def self.cast_date(data) + return NO_MATCH unless data.is_a?(String) + + Date.parse(data) + rescue ArgumentError, TypeError + NO_MATCH + end + private_class_method :cast_date + def self.cast_array(sub_type, data) return NO_MATCH unless data.is_a?(Array) @@ -121,6 +132,8 @@ module {{moduleName}} data.is_a?(Numeric) ? data.to_f : data when 'Time' coerce_time(data) + when 'Date' + coerce_date(data) when ARRAY_TYPE sub_type = Regexp.last_match[:sub_type] data.is_a?(Array) ? data.map { |item| coerce(sub_type, item) } : data @@ -143,6 +156,17 @@ module {{moduleName}} end private_class_method :coerce_time + def self.coerce_date(data) + return data unless data.is_a?(String) + + begin + Date.parse(data) + rescue ArgumentError, TypeError + data + end + end + private_class_method :coerce_date + # Resolves a bare model name under Models:: and dispatches according to # what kind of generated constant it is, without any `valid?` gating: # - a real model class (Serializable/Validations): `from_hash` (recurses) diff --git a/samples/client/others/ruby-nextgen-qdrant/lib/qdrant.rb b/samples/client/others/ruby-nextgen-qdrant/lib/qdrant.rb index 5be13f72f31e..a27f81d674f1 100644 --- a/samples/client/others/ruby-nextgen-qdrant/lib/qdrant.rb +++ b/samples/client/others/ruby-nextgen-qdrant/lib/qdrant.rb @@ -6,6 +6,7 @@ # Contact: andrey@vasnetsov.com # Generated by OpenAPI Generator (https://openapi-generator.tech) +require 'date' require 'erb' require 'forwardable' require 'json' diff --git a/samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb b/samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb index 427dcbda2a4c..a2a7c8ecd3c9 100644 --- a/samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb +++ b/samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb @@ -40,6 +40,8 @@ def self.cast_raw(type_name, data) data.is_a?(String) ? data : NO_MATCH when 'Time' cast_time(data) + when 'Date' + cast_date(data) when 'Object', 'Hash' data.is_a?(Hash) ? data : NO_MATCH when ARRAY_TYPE @@ -61,6 +63,15 @@ def self.cast_time(data) end private_class_method :cast_time + def self.cast_date(data) + return NO_MATCH unless data.is_a?(String) + + Date.parse(data) + rescue ArgumentError, TypeError + NO_MATCH + end + private_class_method :cast_date + def self.cast_array(sub_type, data) return NO_MATCH unless data.is_a?(Array) @@ -121,6 +132,8 @@ def self.coerce(type_name, data) data.is_a?(Numeric) ? data.to_f : data when 'Time' coerce_time(data) + when 'Date' + coerce_date(data) when ARRAY_TYPE sub_type = Regexp.last_match[:sub_type] data.is_a?(Array) ? data.map { |item| coerce(sub_type, item) } : data @@ -143,6 +156,17 @@ def self.coerce_time(data) end private_class_method :coerce_time + def self.coerce_date(data) + return data unless data.is_a?(String) + + begin + Date.parse(data) + rescue ArgumentError, TypeError + data + end + end + private_class_method :coerce_date + # Resolves a bare model name under Models:: and dispatches according to # what kind of generated constant it is, without any `valid?` gating: # - a real model class (Serializable/Validations): `from_hash` (recurses) diff --git a/samples/client/petstore/ruby-nextgen/lib/petstore.rb b/samples/client/petstore/ruby-nextgen/lib/petstore.rb index 19e492b7a84c..720d08e15619 100644 --- a/samples/client/petstore/ruby-nextgen/lib/petstore.rb +++ b/samples/client/petstore/ruby-nextgen/lib/petstore.rb @@ -5,6 +5,7 @@ # The version of the OpenAPI document: 1.0.0 # Generated by OpenAPI Generator (https://openapi-generator.tech) +require 'date' require 'erb' require 'forwardable' require 'json' diff --git a/samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb b/samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb index 8f18bf11fc31..01b1ad682286 100644 --- a/samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb +++ b/samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb @@ -40,6 +40,8 @@ def self.cast_raw(type_name, data) data.is_a?(String) ? data : NO_MATCH when 'Time' cast_time(data) + when 'Date' + cast_date(data) when 'Object', 'Hash' data.is_a?(Hash) ? data : NO_MATCH when ARRAY_TYPE @@ -61,6 +63,15 @@ def self.cast_time(data) end private_class_method :cast_time + def self.cast_date(data) + return NO_MATCH unless data.is_a?(String) + + Date.parse(data) + rescue ArgumentError, TypeError + NO_MATCH + end + private_class_method :cast_date + def self.cast_array(sub_type, data) return NO_MATCH unless data.is_a?(Array) @@ -121,6 +132,8 @@ def self.coerce(type_name, data) data.is_a?(Numeric) ? data.to_f : data when 'Time' coerce_time(data) + when 'Date' + coerce_date(data) when ARRAY_TYPE sub_type = Regexp.last_match[:sub_type] data.is_a?(Array) ? data.map { |item| coerce(sub_type, item) } : data @@ -143,6 +156,17 @@ def self.coerce_time(data) end private_class_method :coerce_time + def self.coerce_date(data) + return data unless data.is_a?(String) + + begin + Date.parse(data) + rescue ArgumentError, TypeError + data + end + end + private_class_method :coerce_date + # Resolves a bare model name under Models:: and dispatches according to # what kind of generated constant it is, without any `valid?` gating: # - a real model class (Serializable/Validations): `from_hash` (recurses)