Skip to content

Conversation

@mdanilowicz
Copy link
Contributor

@mdanilowicz mdanilowicz commented Nov 19, 2025

Prevents conflicts when merging overrides that use composition keywords. In OpenAPI, an object cannot have both $ref and composition keywords, so this removes $ref when composition is present.

closes: #2125

Schema patching improvements

  • Added logic to patchJsonSchema.ts to remove $ref from schema objects when an override uses composition keywords (oneOf, anyOf, allOf, not), preventing conflicts and ensuring correct schema merging. [1] [2]

Code consistency and formatting

  • Updated function signatures and method calls throughout patchJsonSchema.ts for consistency, such as removing trailing commas and ensuring uniform argument formatting. [1] [2] [3] [4] [5] [6] [7]
  • Minor formatting changes to log messages for clarity and consistency in output. [1] [2]

@vercel
Copy link

vercel bot commented Nov 19, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
frontends-demo Ready Ready Preview Nov 21, 2025 1:53pm
frontends-vue-starter-template Error Error Nov 21, 2025 1:53pm
shopware-frontends-docs Ready Ready Preview Nov 21, 2025 1:53pm

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 19, 2025

CodSpeed Performance Report

Merging #2126 will create unknown performance changes

Comparing feat/GH-2125 (7ca42bf) with main (61a60a0)1

Summary

⚠️ No benchmarks were detected in both the base of the PR and the PR.
Please ensure that your benchmarks are correctly instrumented with CodSpeed.

Check out the benchmarks creation guide

⏩ 8 skipped2

Footnotes

  1. No successful run was found on main (2439238) during the generation of this report, so 61a60a0 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Contributor

@patzick patzick left a comment

Choose a reason for hiding this comment

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

Nice addition, currently during override you should specify _DELETE_ value in $ref for the same effect. What if it's the other way around and you want to have $ref instead of composition key?

One thing is that it's missing test scenarios for it so than it would make it also properly documented and easier to understand

Comment on lines 51 to 52
// biome-ignore lint/performance/noDelete: delete $ref
delete obj.$ref;
Copy link
Contributor

Choose a reason for hiding this comment

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

probably that would not trigger linter error

Suggested change
// biome-ignore lint/performance/noDelete: delete $ref
delete obj.$ref;
delete obj["$ref"];

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this will trigger lint/complexity/useLiteralKeys

}

// remove $ref from the target object
if (
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference here? from previous condition? I'd love to see test scenarios for it

const compositionKeywords = ["oneOf", "anyOf", "allOf", "not"];
if (
typeof key === "string" &&
compositionKeywords.includes(key) &&
Copy link
Contributor

@mkucmus mkucmus Nov 19, 2025

Choose a reason for hiding this comment

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

the condition is really hard to get through, please maybe move some parts to the helper funcion to be used later on, maybe event the whole condition - then we can write an additional unit test 😍 for that?

  const compositionKeywords = ["oneOf", "anyOf", "allOf", "not"];
  const hasCompositionKeyword = (val: unknown): boolean => {
    if (typeof val !== "object" || val === null || Array.isArray(val)) {
      return false;
    }
    return compositionKeywords.some((keyword) => keyword in val);
  };

Comment on lines 44 to 50
if (
typeof key === "string" &&
compositionKeywords.includes(key) &&
typeof obj === "object" &&
obj !== null &&
"$ref" in obj
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

then:

Suggested change
if (
typeof key === "string" &&
compositionKeywords.includes(key) &&
typeof obj === "object" &&
obj !== null &&
"$ref" in obj
) {
if (
typeof obj === "object" &&
obj !== null &&
"$ref" in obj &&
hasCompositionKeyword(value)
) {

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] [API-GEN] Composition keywords are ignored on final TS file

4 participants