Skip to content

Fix #25723: ruby-nextgen Response no longer advertises to_hash when data has none - #25754

Open
Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25723-to-hash
Open

Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25723-to-hash

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25723

The generated Response class used def_delegators :data, ..., :to_hash, :dig — Forwardable's static delegation defines to_hash on Response unconditionally, so respond_to?(:to_hash) is true even when data (Array/nil/primitive) has no to_hash, and calling it raises NoMethodError (the issue's repro).

:to_hash is removed from the static delegators and dispatched via method_missing/respond_to_missing? gated on data.respond_to?(:to_hash): Array/nil now honestly report no to_hash (with "Did you mean? to_h"), Hash/model data still delegates. Other delegators and to_h untouched.

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. RubyNextgenClientCodegenTest 25/25 green.


Summary by cubic

Fixes #25723 by making the ruby-nextgen Response class report to_hash only when its data actually supports it. Previously def_delegators :data, ..., :to_hash defined to_hash unconditionally, so respond_to?(:to_hash) returned true for Array, nil, and primitive data even though calling it raised NoMethodError.

to_hash is now dispatched via method_missing/respond_to_missing? and only delegated when data.respond_to?(:to_hash). Other delegators and to_h behavior are unchanged.

Written for commit 2a86666. Summary will update on new commits.

View guided diff

…_hash when data has none

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.

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

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.

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

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] Response#to_hash is advertised and raises when the data is an Array

1 participant