diff --git a/docs/generators/ruby.md b/docs/generators/ruby.md
index 59a8a701ef19..39c949860540 100644
--- a/docs/generators/ruby.md
+++ b/docs/generators/ruby.md
@@ -108,6 +108,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
next
nil
not
+object_id
or
post_body
query_params
diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java
index d4b5e3a8b8a3..783f3c888df6 100644
--- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java
+++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyClientCodegen.java
@@ -135,10 +135,11 @@ public RubyClientCodegen() {
// default HIDE_GENERATION_TIMESTAMP to true
hideGenerationTimestamp = Boolean.TRUE;
- // local variable names used in API methods (endpoints)
+ // local variable names used in API methods (endpoints), plus core methods that
+ // generated model accessors must not override
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));
}
diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java
index c688b531eec8..d866e2d65f4d 100644
--- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java
+++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/ruby/RubyClientCodegenTest.java
@@ -19,7 +19,9 @@
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
+import io.swagger.v3.oas.models.media.ObjectSchema;
import io.swagger.v3.oas.models.media.Schema;
+import io.swagger.v3.oas.models.media.StringSchema;
import org.apache.commons.io.FileUtils;
import org.openapitools.codegen.*;
import org.openapitools.codegen.languages.RubyClientCodegen;
@@ -912,4 +914,28 @@ public void testEnumBuildFromHashRaisesByDefault() throws Exception {
" raise \"Invalid ENUM value #{value} for class #Type\"\n" +
" end");
}
+
+ @Test(description = "a property named object_id must not override Object#object_id")
+ public void objectIdPropertyIsEscapedTest() throws Exception {
+ final File output = Files.createTempDirectory("test").toFile();
+ output.deleteOnExit();
+
+ final Schema schema = new ObjectSchema().addProperty("ObjectId", new StringSchema());
+ final OpenAPI openAPI = TestUtils.createOpenAPIWithOneSchema("Association", schema);
+ final RubyClientCodegen codegen = new RubyClientCodegen();
+ codegen.setOutputDir(output.getAbsolutePath());
+ codegen.setOpenAPI(openAPI);
+
+ CodegenProperty objectId = codegen.fromModel("Association", schema).getVars().get(0);
+ Assert.assertEquals(objectId.name, "_object_id");
+ Assert.assertEquals(objectId.baseName, "ObjectId");
+
+ ClientOptInput clientOptInput = new ClientOptInput().openAPI(openAPI).config(codegen);
+ new DefaultGenerator().opts(clientOptInput).generate();
+
+ Path association = new File(output, "lib/openapi_client/models/association.rb").toPath();
+ TestUtils.assertFileContains(association, "attr_accessor :_object_id");
+ TestUtils.assertFileContains(association, ":'_object_id' => :'ObjectId'");
+ TestUtils.assertFileNotContains(association, "attr_accessor :object_id");
+ }
}