Skip to content

fix(MergedSpecBuilder): merge path items by HTTP method instead of overwriting on path collision#24100

Draft
Picazsoo wants to merge 9 commits into
OpenAPITools:masterfrom
Picazsoo:feature/merge-specs
Draft

fix(MergedSpecBuilder): merge path items by HTTP method instead of overwriting on path collision#24100
Picazsoo wants to merge 9 commits into
OpenAPITools:masterfrom
Picazsoo:feature/merge-specs

Conversation

@Picazsoo

@Picazsoo Picazsoo commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

PR checklist

  • Read the contribution guidelines.
  • 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.
  • 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

Adds a mergeMode to improve multi-spec merging. Default REF preserves the original $ref-based index; opt-in DEEP merges paths by HTTP method and dedupes components with conflict handling.

  • Bug Fixes

    • Merge path items by HTTP method on path collisions; on duplicate path+method keep last in REF, keep first (or fail) in DEEP.
    • Merge components by name; dedupe identical; warn on conflicts (or fail in DEEP).
    • Preserve x- vendor extensions and deduplicate server URLs; add http://localhost:8080 if none.
  • New Features

    • Add mergeMode: REF (default, original behavior) or DEEP (inline merge with component dedupe/conflict detection). Exposed in CLI (--merge-mode), Gradle (mergeMode), and Maven (mergeMode).
    • Add mergeConflictStrategy: WARN (default) or FAIL for DEEP. Exposed in CLI (--merge-conflict-strategy), Gradle (mergeConflictStrategy), and Maven (mergeConflictStrategy).
    • Only process .yaml, .yml, .json; ignore invalid files; deterministic ordering; choose JSON output if the first spec is JSON.

Written for commit f5f50a0. Summary will update on new commits.

Review in cubic

@Picazsoo Picazsoo marked this pull request as ready for review June 30, 2026 11:00
@Picazsoo Picazsoo marked this pull request as draft June 30, 2026 11:01

@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 and verified against the latest diff

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-maven-plugin/src/main/java/org/openapitools/codegen/plugin/ValidateMojo.java">

<violation number="1" location="modules/openapi-generator-maven-plugin/src/main/java/org/openapitools/codegen/plugin/ValidateMojo.java:272">
P2: mergeConflictStrategy is parsed and applied unconditionally despite being documented as DEEP-only. A null or invalid value will crash a REF-mode build with an unwrapped IllegalArgumentException/NullPointerException, bypassing the MojoExecutionException handling in execute().</violation>
</file>

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

Re-trigger cubic

mergedSpec = Optional.of(new MergedSpecBuilder(inputSpecRootDirectory, mergedFileName,
mergedFileInfoName, mergedFileInfoDescription, mergedFileInfoVersion, auth)
.withMergeMode(MergedSpecBuilder.MergeMode.valueOf(mergeMode.toUpperCase(java.util.Locale.ROOT)))
.withConflictStrategy(MergedSpecBuilder.MergeConflictStrategy.valueOf(mergeConflictStrategy.toUpperCase(java.util.Locale.ROOT)))

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.

P2: mergeConflictStrategy is parsed and applied unconditionally despite being documented as DEEP-only. A null or invalid value will crash a REF-mode build with an unwrapped IllegalArgumentException/NullPointerException, bypassing the MojoExecutionException handling in execute().

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

<comment>mergeConflictStrategy is parsed and applied unconditionally despite being documented as DEEP-only. A null or invalid value will crash a REF-mode build with an unwrapped IllegalArgumentException/NullPointerException, bypassing the MojoExecutionException handling in execute().</comment>

<file context>
@@ -251,6 +268,8 @@ private Optional<String> mergeInDirectory() {
       mergedSpec = Optional.of(new MergedSpecBuilder(inputSpecRootDirectory, mergedFileName,
           mergedFileInfoName, mergedFileInfoDescription, mergedFileInfoVersion, auth)
+          .withMergeMode(MergedSpecBuilder.MergeMode.valueOf(mergeMode.toUpperCase(java.util.Locale.ROOT)))
+          .withConflictStrategy(MergedSpecBuilder.MergeConflictStrategy.valueOf(mergeConflictStrategy.toUpperCase(java.util.Locale.ROOT)))
           .buildMergedSpec());
       LOGGER.info("Merge input spec would be used - {}", mergedSpec.get());
</file context>

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.

1 participant