Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

{{> api_info}}

require 'date'
require 'erb'
require 'forwardable'
require 'json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Date.parse is permissive and explicitly not a validator, so both new helpers accept non-ISO values as an OpenAPI format: date; this can select the wrong Date arm or make a oneOf ambiguous. Use the existing Date.iso8601(data) behavior in both cast_date and coerce_date.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache, line 69:

<comment>`Date.parse` is permissive and explicitly not a validator, so both new helpers accept non-ISO values as an OpenAPI `format: date`; this can select the wrong Date arm or make a `oneOf` ambiguous. Use the existing `Date.iso8601(data)` behavior in both `cast_date` and `coerce_date`.</comment>

<file context>
@@ -61,6 +63,15 @@ module {{moduleName}}
+    def self.cast_date(data)
+      return NO_MATCH unless data.is_a?(String)
+
+      Date.parse(data)
+    rescue ArgumentError, TypeError
+      NO_MATCH
</file context>

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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions samples/client/others/ruby-nextgen-qdrant/lib/qdrant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Contact: andrey@vasnetsov.com
# Generated by OpenAPI Generator (https://openapi-generator.tech)

require 'date'
require 'erb'
require 'forwardable'
require 'json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: cast_date rejects Date instances, while the Integer, Float, String and Boolean arms accept values that are already typed. On an anyOf/oneOf with a Date arm, build(Date.today) raises ArgumentError, and from_hash(model.to_hash) fails because to_hash keeps Date objects. Accept Date instances here.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb, line 67:

<comment>`cast_date` rejects `Date` instances, while the `Integer`, `Float`, `String` and `Boolean` arms accept values that are already typed. On an anyOf/oneOf with a Date arm, `build(Date.today)` raises `ArgumentError`, and `from_hash(model.to_hash)` fails because `to_hash` keeps Date objects. Accept `Date` instances here.</comment>

<file context>
@@ -61,6 +63,15 @@ def self.cast_time(data)
     private_class_method :cast_time
 
+    def self.cast_date(data)
+      return NO_MATCH unless data.is_a?(String)
+
+      Date.parse(data)
</file context>
Suggested change
return NO_MATCH unless data.is_a?(String)
return data if data.is_a?(Date)
return NO_MATCH unless data.is_a?(String)


Date.parse(data)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Date.parse is heuristic, so this Date arm accepts non-RFC3339 strings such as 3rd Feb 2001 instead of returning NO_MATCH; use a strict RFC3339 full-date parser in both date helpers, such as Date.iso8601.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb, line 69:

<comment>`Date.parse` is heuristic, so this Date arm accepts non-RFC3339 strings such as `3rd Feb 2001` instead of returning `NO_MATCH`; use a strict RFC3339 full-date parser in both date helpers, such as `Date.iso8601`.</comment>

<file context>
@@ -61,6 +63,15 @@ def self.cast_time(data)
+    def self.cast_date(data)
+      return NO_MATCH unless data.is_a?(String)
+
+      Date.parse(data)
+    rescue ArgumentError, TypeError
+      NO_MATCH
</file context>

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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/ruby-nextgen/lib/petstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 24 additions & 0 deletions samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Date.parse is heuristic, so this Date arm accepts non-RFC3339 strings such as 3rd Feb 2001 instead of returning NO_MATCH; use a strict RFC3339 full-date parser in both date helpers, such as Date.iso8601.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb, line 69:

<comment>`Date.parse` is heuristic, so this Date arm accepts non-RFC3339 strings such as `3rd Feb 2001` instead of returning `NO_MATCH`; use a strict RFC3339 full-date parser in both date helpers, such as `Date.iso8601`.</comment>

<file context>
@@ -61,6 +63,15 @@ def self.cast_time(data)
+    def self.cast_date(data)
+      return NO_MATCH unless data.is_a?(String)
+
+      Date.parse(data)
+    rescue ArgumentError, TypeError
+      NO_MATCH
</file context>

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)

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
Loading