Repository navigation
Fix #25721: add the Date branch to the ruby-nextgen Polymorphism runtime #25760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| {{> api_info}} | ||
|
|
||
| require 'date' | ||
| require 'erb' | ||
| require 'forwardable' | ||
| require 'json' | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents
Suggested change
|
||||||||
|
|
||||||||
| Date.parse(data) | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||||||||
| 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) | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Prompt for AI agents |
||
| 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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2:
Date.parseis permissive and explicitly not a validator, so both new helpers accept non-ISO values as an OpenAPIformat: date; this can select the wrong Date arm or make aoneOfambiguous. Use the existingDate.iso8601(data)behavior in bothcast_dateandcoerce_date.Prompt for AI agents