Repository navigation
[ruby] Add object_id to reserved words - #25175
Conversation
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>
There was a problem hiding this comment.
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")) { |
There was a problem hiding this comment.
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>
|
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 |
Fixes #25174
Adds
object_idto therubyclient generator's reserved words. A schema property namedObjectIdorobject_idused to produceattr_accessor :object_id, which overridesObject#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, andattribute_mapstill maps it to the original JSON key, so the wire format doesn't change.This follows the same approach as #3146 (
send, also inRubyClientCodegen) and #22577 (object_idfor Crystal). I scoped it toRubyClientCodegento matchsend. If you'd rather coverruby-nextgenand the Sinatra/Rails server generators too, I can move it toAbstractRubyCodegen.None of the specs used by the Ruby sample configs in
bin/configshave anObjectId/object_idproperty or parameter, so no samples change.docs/generators/ruby.mdis updated to list the new reserved word.Tests: added
RubyClientCodegenTest#objectIdPropertyIsEscapedTest. It generates a model with anObjectIdproperty and assertsattr_accessor :_object_idand:'_object_id' => :'ObjectId'.RubyClientCodegenTest,AbstractRubyCodegenTestandRubyClientOptionsTestpass locally.PR checklist
export_docs_generators.shwould produce.Ruby technical committee: @cliffano @zlx @autopp
🤖 Generated with Claude Code
Summary by cubic
Adds
object_idto the Ruby client generator's reserved words. A schema property namedObjectIdorobject_idpreviously generatedattr_accessor :object_id, which overridesObject#object_idand triggers Ruby 3.4's "redefining 'object_id' may cause serious problems" warning. The accessor is now generated as_object_idlike other reserved words, andattribute_mapstill 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.