Repository navigation
Conversation
…_hash when data has none Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
Contributor
There was a problem hiding this comment.
1 issue found across 5 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="modules/openapi-generator/src/main/resources/ruby-nextgen/response.mustache">
<violation number="1" location="modules/openapi-generator/src/main/resources/ruby-nextgen/response.mustache:29">
P3: `respond_to_missing?` advertises private/protected `data.to_hash` methods, but `method_missing` rejects them, so `respond_to?(:to_hash, true)` claims support for a call that raises. Use the same public-method check here unless private delegation is intentionally implemented.</violation>
</file>
Reply with feedback, questions, or to request a fix.
View guided diff | Re-trigger cubic
| end | ||
|
|
||
| def respond_to_missing?(name, include_private = false) | ||
| (name == :to_hash && data.respond_to?(:to_hash, include_private)) || super |
Contributor
There was a problem hiding this comment.
P3: respond_to_missing? advertises private/protected data.to_hash methods, but method_missing rejects them, so respond_to?(:to_hash, true) claims support for a call that raises. Use the same public-method check here unless private delegation is intentionally implemented.
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/response.mustache, line 29:
<comment>`respond_to_missing?` advertises private/protected `data.to_hash` methods, but `method_missing` rejects them, so `respond_to?(:to_hash, true)` claims support for a call that raises. Use the same public-method check here unless private delegation is intentionally implemented.</comment>
<file context>
@@ -14,12 +14,21 @@ module {{moduleName}}
+ end
+
+ def respond_to_missing?(name, include_private = false)
+ (name == :to_hash && data.respond_to?(:to_hash, include_private)) || super
+ end
+
</file context>
Suggested change
| (name == :to_hash && data.respond_to?(:to_hash, include_private)) || super | |
| (name == :to_hash && data.respond_to?(:to_hash)) || super |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25723
The generated
Responseclass useddef_delegators :data, ..., :to_hash, :dig— Forwardable's static delegation definesto_hashonResponseunconditionally, sorespond_to?(:to_hash)is true even whendata(Array/nil/primitive) has noto_hash, and calling it raisesNoMethodError(the issue's repro).:to_hashis removed from the static delegators and dispatched viamethod_missing/respond_to_missing?gated ondata.respond_to?(:to_hash): Array/nil now honestly report noto_hash(with "Did you mean? to_h"), Hash/model data still delegates. Other delegators andto_huntouched.1 generator test + regenerated petstore/qdrant samples + 5-case rspec spec (picked up by the samples-ruby-nextgen workflow); standalone Ruby semantics check: 9/9 assertions.
RubyNextgenClientCodegenTest25/25 green.Summary by cubic
Fixes #25723 by making the ruby-nextgen
Responseclass reportto_hashonly when itsdataactually supports it. Previouslydef_delegators :data, ..., :to_hashdefinedto_hashunconditionally, sorespond_to?(:to_hash)returned true for Array, nil, and primitive data even though calling it raisedNoMethodError.to_hashis now dispatched viamethod_missing/respond_to_missing?and only delegated whendata.respond_to?(:to_hash). Other delegators andto_hbehavior are unchanged.Written for commit 2a86666. Summary will update on new commits.