Skip to content

Fix #25721: add the Date branch to the ruby-nextgen Polymorphism runtime - #25760

Open
Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25721-date-branch
Open

Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25721-date-branch

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25721

AbstractRubyCodegen maps format: date to Ruby Date, but the generated Polymorphism runtime only dispatched Time: cast_raw had no Date candidate (an anyOf/oneOf Date arm always fell through to cast_model → NO_MATCH) and coerce left format: date properties as raw String in from_hash — both symptoms from the issue reproduce on master.

cast_raw/coerce gain Date branches with cast_date/coerce_date helpers mirroring the existing Time semantics (NO_MATCH on parse failure; coerce falls back to raw data), and the generated gems now require 'date' next to require '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 → Date in from_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 Date handling to the ruby-nextgen Polymorphism runtime. format: date values were previously left as raw String by from_hash, and Date candidates in anyOf/oneOf never matched; now cast_raw and coerce dispatch to new cast_date/coerce_date helpers that parse with Date.parse and mirror the existing Time semantics (NO_MATCH on parse failure, raw value fallback in coerce). Generated gems now require 'date', and the petstore and qdrant samples have been regenerated.

Written for commit bb7419b. Summary will update on new commits.

View guided diff

…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>

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

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)

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)

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>

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/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)

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>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][RUBY-NEXTGEN] format: date properties stay String after from_hash

1 participant