-
Notifications
You must be signed in to change notification settings - Fork 4k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@gitbook/react-openapi': patch | ||
--- | ||
|
||
Fix merge logic for allOf alternatives |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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))) { | ||||||
latest.enum = Array.from( | ||||||
new Set([...(latest.enum || []), ...(schemaOrRef.enum || [])]) | ||||||
); | ||||||
latest.nullable = latest.nullable || schemaOrRef.nullable; | ||||||
return acc; | ||||||
} | ||||||
|
@@ -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) => | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the enum case above, changing from
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
['type', 'properties', 'required', 'nullable'].includes(key) | ||||||
) | ||||||
) { | ||||||
latest.properties = { | ||||||
...latest.properties, | ||||||
...schemaOrRef.properties, | ||||||
...(latest.properties || {}), | ||||||
...(schemaOrRef.properties || {}), | ||||||
}; | ||||||
latest.required = Array.from( | ||||||
new Set([ | ||||||
...(Array.isArray(latest.required) ? latest.required : []), | ||||||
...(Array.isArray(schemaOrRef.required) | ||||||
...(latest.required && Array.isArray(latest.required) | ||||||
? latest.required | ||||||
: []), | ||||||
...(schemaOrRef.required && Array.isArray(schemaOrRef.required) | ||||||
? schemaOrRef.required | ||||||
: []), | ||||||
]) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing from
every()
tosome()
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.Copilot uses AI. Check for mistakes.