Skip to content

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

Open
feczkob wants to merge 3 commits into
OpenAPITools:masterfrom
feczkob:fix/23414-path-shadowing
Open

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

Conversation

@feczkob
Copy link
Copy Markdown
Contributor

@feczkob feczkob commented May 25, 2026

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

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

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

Labels

None yet

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

1 participant