Skip to content

Commit c1cb295

Browse files
committed
fix(rest): properly parse body parameters when mixed with oneOf
Fixes an issue where endpoints that declare properties at the top level alongside a oneOf field (like Create a check run) were missing those top-level properties. It also fixes oneOf elements without 'type: object'.
1 parent 74e8af3 commit c1cb295

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/rest/scripts/utils/get-body-params.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,33 @@ async function getTopLevelOneOfProperty(
5454
// is the array as a property of the object. We need to ensure that the
5555
// first option listed is the most comprehensive and preferred option.
5656
const firstOneOfObject = schema.oneOf[0]
57-
const allOneOfAreObjects = schema.oneOf.every((elem) => elem.type === 'object')
58-
let required = firstOneOfObject.required || []
59-
let properties = firstOneOfObject.properties || {}
57+
const allOneOfAreObjects = schema.oneOf.every(
58+
(elem) => elem.type === 'object' || elem.properties !== undefined,
59+
)
60+
let required = firstOneOfObject.required ? [...firstOneOfObject.required] : []
61+
const properties = firstOneOfObject.properties ? { ...firstOneOfObject.properties } : {}
6062

6163
// When all of the oneOf objects have the `type: object` we
6264
// need to display all of the parameters.
6365
// This merges all of the properties and required values.
6466
if (allOneOfAreObjects) {
6567
for (const each of schema.oneOf.slice(1)) {
66-
if (firstOneOfObject.properties && each.properties) {
67-
Object.assign(firstOneOfObject.properties, each.properties)
68+
if (each.properties) {
69+
Object.assign(properties, each.properties)
6870
}
69-
if (firstOneOfObject.required && each.required) {
70-
required = firstOneOfObject.required.concat(each.required)
71+
if (each.required) {
72+
required = Array.from(new Set([...required, ...each.required]))
7173
}
7274
}
73-
properties = firstOneOfObject.properties || {}
7475
}
76+
77+
if (schema.properties) {
78+
Object.assign(properties, schema.properties)
79+
}
80+
if (schema.required) {
81+
required = Array.from(new Set([...required, ...schema.required]))
82+
}
83+
7584
return { properties, required }
7685
}
7786

0 commit comments

Comments
 (0)