Skip to content

[ruby-nextgen] Expose nested resources through clients - #25002

Open
axelray-dev wants to merge 3 commits into
OpenAPITools:masterfrom
axelray-dev:fix/ruby-nextgen-nested-resources-24999
Open

axelray-dev wants to merge 3 commits into
OpenAPITools:masterfrom
axelray-dev:fix/ruby-nextgen-nested-resources-24999

Conversation

@axelray-dev

@axelray-dev axelray-dev commented Sep 23, 2026 •

Copy link
Copy Markdown

Fixes #24999

Summary

Expose nested Ruby-nextgen resource clients through their namespace clients. This makes paths such as client.store.order available to callers and also generates a concrete namespace class when a namespace only contains nested resources, so Zeitwerk can load the generated files correctly.

The change adds regression coverage for direct and namespace-only nested resources, including multiple child resources, and updates the Petstore sample to expose client.store.order.

Validation

  • CircleCI node0 through node3 passed.
  • git diff --check passed.
  • The focused Maven test could not run on the VPS because Java is not installed; the generator test suite is covered by CI.

@axelray-dev
axelray-dev marked this pull request as ready for review September 24, 2026 20:50

@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 7 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/test/java/org/openapitools/codegen/rubynextgen/RubyNextgenClientCodegenTest.java">

<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/rubynextgen/RubyNextgenClientCodegenTest.java:416">
P3: The test's stated purpose is verifying nested resources are reachable from the client, but for the namespace-only case it only checks the generated namespace file (api/only.rb) and never asserts that client.rb exposes the namespace (e.g. "def only"). Add an assertFileContains(client.rb, "def only") so the end-to-end client accessor for the namespace-only namespace is actually covered.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

.toClientOptInput();
new org.openapitools.codegen.DefaultGenerator(false).opts(input).generate();

org.openapitools.codegen.TestUtils.assertFileContains(

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: The test's stated purpose is verifying nested resources are reachable from the client, but for the namespace-only case it only checks the generated namespace file (api/only.rb) and never asserts that client.rb exposes the namespace (e.g. "def only"). Add an assertFileContains(client.rb, "def only") so the end-to-end client accessor for the namespace-only namespace is actually covered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/rubynextgen/RubyNextgenClientCodegenTest.java, line 416:

<comment>The test's stated purpose is verifying nested resources are reachable from the client, but for the namespace-only case it only checks the generated namespace file (api/only.rb) and never asserts that client.rb exposes the namespace (e.g. "def only"). Add an assertFileContains(client.rb, "def only") so the end-to-end client accessor for the namespace-only namespace is actually covered.</comment>

<file context>
@@ -398,4 +398,36 @@ public void testAcronymModelsGetZeitwerkInflections() throws Exception {
+                        .toClientOptInput();
+        new org.openapitools.codegen.DefaultGenerator(false).opts(input).generate();
+
+        org.openapitools.codegen.TestUtils.assertFileContains(
+                target.resolve("lib/petstore/client.rb"), "def stables", "Petstore::Api::Stables.new");
+        org.openapitools.codegen.TestUtils.assertFileContains(
</file context>

@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 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyNextgenClientCodegen.java">

<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyNextgenClientCodegen.java:774">
P1: Renaming a resource accessor here also changes the value later used as its Zeitwerk inflection key, but the resource file keeps the raw route basename. Keep the resource filename separate from its client method name and generate inflections from the raw basename, otherwise acronym resources can fail to autoload after a collision rename.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Map<String, Object> rm = new HashMap<>();
rm.put("accessor", underscore(sanitizeName(res.replace('-', '_'))));
String resourceAccessor = underscore(sanitizeName(res.replace('-', '_')));
rm.put("accessor", safeResourceAccessorName(resourceAccessor, reservedNames));

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.

P1: Renaming a resource accessor here also changes the value later used as its Zeitwerk inflection key, but the resource file keeps the raw route basename. Keep the resource filename separate from its client method name and generate inflections from the raw basename, otherwise acronym resources can fail to autoload after a collision rename.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/RubyNextgenClientCodegen.java, line 774:

<comment>Renaming a resource accessor here also changes the value later used as its Zeitwerk inflection key, but the resource file keeps the raw route basename. Keep the resource filename separate from its client method name and generate inflections from the raw basename, otherwise acronym resources can fail to autoload after a collision rename.</comment>

<file context>
@@ -753,9 +766,12 @@ public Map<String, Object> postProcessSupportingFileData(Map<String, Object> obj
                 Map<String, Object> rm = new HashMap<>();
-                rm.put("accessor", underscore(sanitizeName(res.replace('-', '_'))));
+                String resourceAccessor = underscore(sanitizeName(res.replace('-', '_')));
+                rm.put("accessor", safeResourceAccessorName(resourceAccessor, reservedNames));
                 rm.put("className", toApiName(e.getKey() + "/" + res));
                 resources.add(rm);
</file context>

@axelray-dev

Copy link
Copy Markdown
Author

Addressed the current review findings in a445f4a. Namespace-only output now follows the first actually generated nested resource, resource accessors avoid initialize and direct-operation collisions, and generated metadata continues to derive from the processed operation set. git diff --check passed on the VPS; Java and Maven are not installed there, so CI is the authoritative generator test. Please re-review the new head.

@wing328

wing328 commented Sep 25, 2026

Copy link
Copy Markdown
Member

thanks for the PR. please review the build failure when you've time.

cc @n-rodriguez (author of ruby-nextgen)

@wing328 wing328 modified the milestone: 7.26.0 Sep 25, 2026

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][RUBY-NEXTGEN] Nested resources are not reachable from the client

2 participants