Repository navigation
Conversation
…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 <vadimlazuk5@gmail.com>
There was a problem hiding this comment.
4 issues found across 6 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. 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. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb">
<violation number="1" location="samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb:67">
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.</violation>
<violation number="2" location="samples/client/others/ruby-nextgen-qdrant/lib/qdrant/polymorphism.rb:69">
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`.</violation>
</file>
<file name="samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb">
<violation number="1" location="samples/client/petstore/ruby-nextgen/lib/petstore/polymorphism.rb:69">
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`.</violation>
</file>
<file name="modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/ruby-nextgen/polymorphism.mustache:69">
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`.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| private_class_method :cast_time | ||
|
|
||
| def self.cast_date(data) | ||
| return NO_MATCH unless data.is_a?(String) |
There was a problem hiding this comment.
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>
| return NO_MATCH unless data.is_a?(String) | |
| return data if data.is_a?(Date) | |
| return NO_MATCH unless data.is_a?(String) |
| def self.cast_date(data) | ||
| return NO_MATCH unless data.is_a?(String) | ||
|
|
||
| Date.parse(data) |
There was a problem hiding this comment.
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>
| def self.cast_date(data) | ||
| return NO_MATCH unless data.is_a?(String) | ||
|
|
||
| Date.parse(data) |
There was a problem hiding this comment.
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>
| def self.cast_date(data) | ||
| return NO_MATCH unless data.is_a?(String) | ||
|
|
||
| Date.parse(data) |
There was a problem hiding this comment.
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>
Fixes #25721
AbstractRubyCodegenmapsformat: dateto RubyDate, but the generatedPolymorphismruntime only dispatchedTime:cast_rawhad noDatecandidate (an anyOf/oneOfDatearm always fell through tocast_model→NO_MATCH) andcoerceleftformat: dateproperties as rawStringinfrom_hash— both symptoms from the issue reproduce on master.cast_raw/coercegainDatebranches withcast_date/coerce_datehelpers mirroring the existing Time semantics (NO_MATCHon parse failure; coerce falls back to raw data), and the generated gems nowrequire 'date'next torequire 'time'.Committed ruby-nextgen samples regenerated via the stock configs (+75 lines across the two runtimes and gem entry files — sample drift otherwise clean). Pre-fix probe reproduced both symptoms; post-fix:
format: date→Dateinfrom_hash,DateOrCode.build('2026-05-06')→Date, unparseable strings still raise/fall back per coerce semantics. Sample suites: petstore 23/23, qdrant 813/813 rspec examples.Summary by cubic
Fixes #25721 by adding
Datehandling to the ruby-nextgenPolymorphismruntime.format: datevalues were previously left as rawStringbyfrom_hash, andDatecandidates in anyOf/oneOf never matched; nowcast_rawandcoercedispatch to newcast_date/coerce_datehelpers that parse withDate.parseand mirror the existingTimesemantics (NO_MATCHon parse failure, raw value fallback incoerce). Generated gems nowrequire 'date', and the petstore and qdrant samples have been regenerated.Written for commit bb7419b. Summary will update on new commits.