Skip to content

[ruby] Add object_id to reserved words - #25175

Merged
wing328 merged 1 commit into
OpenAPITools:masterfrom
corsonknowles:ruby-object-id-reserved-word
Oct 8, 2026
Merged

wing328 merged 1 commit into
OpenAPITools:masterfrom
corsonknowles:ruby-object-id-reserved-word

Conversation

@corsonknowles

@corsonknowles corsonknowles commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25174

Adds object_id to the ruby client generator's reserved words. A schema property named ObjectId or object_id used to produce attr_accessor :object_id, which overrides Object#object_id. Ruby 3.4 warns about that at load time by default (warning: redefining 'object_id' may cause serious problems), and identity checks get the field value back instead of the object's id. With this change the accessor is generated as _object_id, like every other reserved word, and attribute_map still maps it to the original JSON key, so the wire format doesn't change.

This follows the same approach as #3146 (send, also in RubyClientCodegen) and #22577 (object_id for Crystal). I scoped it to RubyClientCodegen to match send. If you'd rather cover ruby-nextgen and the Sinatra/Rails server generators too, I can move it to AbstractRubyCodegen.

None of the specs used by the Ruby sample configs in bin/configs have an ObjectId/object_id property or parameter, so no samples change. docs/generators/ruby.md is updated to list the new reserved word.

Tests: added RubyClientCodegenTest#objectIdPropertyIsEscapedTest. It generates a model with an ObjectId property and asserts attr_accessor :_object_id and :'_object_id' => :'ObjectId'. RubyClientCodegenTest, AbstractRubyCodegenTest and RubyClientOptionsTest pass locally.

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    Built the generator module and ran the Ruby test classes. No sample spec has the affected property, so no samples change. The docs change is the single reserved-word line that export_docs_generators.sh would produce.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Ruby technical committee: @cliffano @zlx @autopp

🤖 Generated with Claude Code


Summary by cubic

Adds object_id to the Ruby client generator's reserved words. A schema property named ObjectId or object_id previously generated attr_accessor :object_id, which overrides Object#object_id and triggers Ruby 3.4's "redefining 'object_id' may cause serious problems" warning. The accessor is now generated as _object_id like other reserved words, and attribute_map still maps it to the original JSON key, so the wire format doesn't change. No sample specs use the affected property, so no samples change.

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

View guided diff

A schema property named ObjectId generated attr_accessor :object_id,
overriding Object#object_id and triggering Ruby's "redefining 'object_id'
may cause serious problems" warning. Escape it like other reserved words.

Fixes OpenAPITools#25174

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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 3 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/java/org/openapitools/codegen/languages/RubyClientCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java:142">
P3: Escaping `object_id` to `_object_id` can silently shadow a sibling property in specs that legitimately define both. `toVarName` only escapes names that exactly match a reserved word, so a schema with both `object_id` and `_object_id` produces two `attr_accessor :_object_id` lines, and Ruby lets the later definition silently win — one of the two accessors and its `attribute_map` entry become unreachable. The same collision risk already exists for other reserved words, but this change extends it to a far more common JSON key.</violation>
</file>

Reply to a comment to ask cubic a question or push back. It learns from your replies.

View guided diff | Re-trigger cubic

for (String word : Arrays.asList(
"local_var_path", "query_params", "header_params", "_header_accept", "_header_accept_result",
"_header_content_type", "form_params", "post_body", "auth_names", "send")) {
"_header_content_type", "form_params", "post_body", "auth_names", "send", "object_id")) {

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: Escaping object_id to _object_id can silently shadow a sibling property in specs that legitimately define both. toVarName only escapes names that exactly match a reserved word, so a schema with both object_id and _object_id produces two attr_accessor :_object_id lines, and Ruby lets the later definition silently win — one of the two accessors and its attribute_map entry become unreachable. The same collision risk already exists for other reserved words, but this change extends it to a far more common JSON key.

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/java/org/openapitools/codegen/languages/RubyClientCodegen.java, line 142:

<comment>Escaping `object_id` to `_object_id` can silently shadow a sibling property in specs that legitimately define both. `toVarName` only escapes names that exactly match a reserved word, so a schema with both `object_id` and `_object_id` produces two `attr_accessor :_object_id` lines, and Ruby lets the later definition silently win — one of the two accessors and its `attribute_map` entry become unreachable. The same collision risk already exists for other reserved words, but this change extends it to a far more common JSON key.</comment>

<file context>
@@ -135,10 +135,11 @@ public RubyClientCodegen() {
         for (String word : Arrays.asList(
                 "local_var_path", "query_params", "header_params", "_header_accept", "_header_accept_result",
-                "_header_content_type", "form_params", "post_body", "auth_names", "send")) {
+                "_header_content_type", "form_params", "post_body", "auth_names", "send", "object_id")) {
             reservedWords.add(word.toLowerCase(Locale.ROOT));
         }
</file context>

@wing328 wing328 added this to the 7.27.0 milestone Oct 8, 2026
@wing328
wing328 merged commit f2697e5 into OpenAPITools:master Oct 8, 2026
15 checks passed
@wing328

wing328 commented Oct 8, 2026

Copy link
Copy Markdown
Member

thanks for the fix, which has been merged.

a possible workaround to the issue is to use the name mapping options: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#name-mapping

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][RUBY] Property named ObjectId generates attr_accessor :object_id, overriding Object#object_id

2 participants