Skip to content

[kotlin-server][Java][JAX-RS] Fix path shadowing (#23414)#23871

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
feczkob:fix/23414-path-shadowing
Jun 9, 2026
Merged

[kotlin-server][Java][JAX-RS] Fix path shadowing (#23414)#23871
wing328 merged 3 commits into
OpenAPITools:masterfrom
feczkob:fix/23414-path-shadowing

Conversation

@feczkob

@feczkob feczkob commented May 25, 2026

Copy link
Copy Markdown
Contributor

Fixes #23414.

The generator now tracks all resource paths across tags during code generation. Before applying a common @Path prefix to an API class, it checks if that prefix would "shadow" (intercept) routes belonging to other tags - if so, it keeps the full paths on each method instead.

Could you take a look, please?

@karismann (2019/03) @Zomzog (2019/04) @andrewemery (2019/10) @4brunu (2019/11) @yutaka0m (2020/03) @stefankoppier (2022/06) @e5l (2024/10) @dennisameling (2026/02) and @lbilger

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • 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
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Fixes path shadowing in Java JAX-RS and Kotlin jaxrs-spec generators by skipping a class-level @Path when it would hide routes from other tags, keeping all endpoints reachable. Fixes #23414.

  • Bug Fixes
    • Collect all resource paths across tags and skip commonPath if it would shadow another tag’s route.
    • Add a cross-tag shadow check in AbstractJavaJAXRSServerCodegen during jaxrsPostProcessOperations; include helpers to compute/apply common path.
    • Mirror the logic in KotlinServerCodegen for the jaxrs-spec library; other Kotlin libraries remain unchanged.
    • Add regression tests and sample spec: JavaJaxrsBaseTest#testCommonPathDoesNotShadowOtherTags, KotlinServerCodegenTest#testCommonPathDoesNotShadowOtherTags_jaxrsSpec, src/test/resources/3_0/issue_23414.yaml.
    • Regenerate samples to reflect the new path handling (e.g., JAX-RS FakeApi now uses @Path("") with full method paths; add Kotlin Ktor sample files AppMain.kt and Configuration.kt).

Written for commit 0986dc7. Summary will update on new commits. Review in cubic

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

No issues found across 5 files

Re-trigger cubic

* candidate {@code commonPath} is only safe if no <em>other</em> tag owns a resource
* path that starts with that prefix.
*/
private final Set<String> allResourcePaths = new HashSet<>();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Global path registry.

opList.add(co);
}

allResourcePaths.add(resourcePath);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every time an operation is assigned to a tag, its full resource path is added to the global path registry.

Comment on lines +235 to +240
if (commonPath != null && !commonPath.isEmpty() && !"/".equals(commonPath)
&& wouldShadowOtherTags(commonPath, ops, allResourcePaths)) {
commonPath = null;
}

applyCommonPath(ops, commonPath, objs);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before applying a common path prefix to a tag's API class, the generator checks shadowing.

@wing328

wing328 commented May 28, 2026

Copy link
Copy Markdown
Member

@feczkob thanks for the PR

@lbilger I wonder if you can test/review this change to confirm whether it addresses the issue #23414

git checkout -b feczkob-fix/23414-path-shadowing master
git pull https://github.com/feczkob/openapi-generator.git fix/23414-path-shadowing

@wing328

wing328 commented Jun 5, 2026

Copy link
Copy Markdown
Member

@feczkob are you using this fix in production and confirm it works for your use cases?

@feczkob

feczkob commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

@wing328 no, the bug appears only in an edge case. However, I verified the change on the reproducer of @lbilger and the tests pass. I also took a look at the generated classes and they are as expected. Not sure whether we should wait more for his feedback or we can rather proceed with the merge.

@lbilger

lbilger commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Hi @feczkob , thanks a lot for fixing this! Unfortunately, I can't test it at the moment, but it looks good and if you tried with the reproducer, I'm inclined to believe that it works. So thumbs up from me 👍

@feczkob

feczkob commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@lbilger let's test it when you have some free time, just to be super sure 😄 In the meantime, @wing328 do you want to wait more, or can we proceed with the merge?

@wing328

wing328 commented Jun 9, 2026

Copy link
Copy Markdown
Member

Let's give it a try 👍

@wing328 wing328 merged commit 06d84df into OpenAPITools:master Jun 9, 2026
103 checks passed
@wing328 wing328 added this to the 7.24.0 milestone Jun 9, 2026
@feczkob feczkob deleted the fix/23414-path-shadowing branch June 9, 2026 14:51
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][kotlin-server] Common path prefix extraction breaks cross-tag JAX-RS routing

3 participants