Skip to content

Fix merge logic for allOf alternatives #3515

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nolannbiron
Copy link
Member

No description provided.

@nolannbiron nolannbiron requested review from gregberge and Copilot July 30, 2025 13:02
Copy link

linear bot commented Jul 30, 2025

Copy link

changeset-bot bot commented Jul 30, 2025

🦋 Changeset detected

Latest commit: b9e110b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@gitbook/react-openapi Patch
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the merge logic for handling allOf alternatives in OpenAPI schema processing. The changes address issues with the schema merging conditions and add defensive programming to handle undefined properties.

  • Changed merge conditions from every() to some() for determining when schemas can be merged
  • Added null checks and default values to prevent errors when accessing undefined properties
  • Improved handling of enum, properties, and required arrays to avoid runtime exceptions

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/react-openapi/src/OpenAPISchema.tsx Updated merge logic conditions and added defensive null checks for schema properties
.changeset/tame-months-knock.md Added changeset entry documenting the bug fix

@@ -556,8 +556,10 @@ function mergeAlternatives(
schemaOrRef.enum
) {
const keys = Object.keys(schemaOrRef);
if (keys.every((key) => ['type', 'enum', 'nullable'].includes(key))) {
latest.enum = Array.from(new Set([...latest.enum, ...schemaOrRef.enum]));
if (keys.some((key) => ['type', 'enum', 'nullable'].includes(key))) {
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Changing from every() to some() fundamentally alters the merge condition logic. This will now merge schemas if ANY of the keys match the allowed list, rather than requiring ALL keys to match. This could cause unintended merging of schemas that have additional properties beyond the allowed set.

Suggested change
if (keys.some((key) => ['type', 'enum', 'nullable'].includes(key))) {
if (keys.every((key) => ['type', 'enum', 'nullable'].includes(key))) {

Copilot uses AI. Check for mistakes.

@@ -566,18 +568,20 @@ function mergeAlternatives(
if (latest && latest.type === 'object' && schemaOrRef.type === 'object') {
const keys = Object.keys(schemaOrRef);
if (
keys.every((key) =>
keys.some((key) =>
Copy link
Preview

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Similar to the enum case above, changing from every() to some() will allow merging of object schemas even when they contain properties outside the allowed list ['type', 'properties', 'required', 'nullable']. This could lead to incorrect schema merging behavior.

Suggested change
keys.some((key) =>
keys.every((key) =>

Copilot uses AI. Check for mistakes.

Copy link

argos-ci bot commented Jul 30, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v2 (Inspect) ⚠️ Changes detected (Review) 1 changed Jul 30, 2025, 1:10 PM
v2-vercel (Inspect) ⚠️ Changes detected (Review) 1 changed, 1 failure Jul 30, 2025, 1:14 PM

Copy link
Contributor

@gregberge gregberge left a comment

Choose a reason for hiding this comment

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

Are we sure of that?

Copy link
Member Author

nope, opened it too fast, didn't spot any issues but I'm trying to make it safer

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.

2 participants