Skip to content

Commit fee8640

Browse files
authored
Merge pull request #25001 from github/repo-sync
repo sync
2 parents 0de878d + fedad09 commit fee8640

File tree

7 files changed

+61
-23
lines changed

7 files changed

+61
-23
lines changed

components/parameter-table/ChildBodyParametersRows.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type Props = {
1212
childParamsGroups: ChildParameter[]
1313
parentName: string
1414
parentType: string
15+
oneOfObject?: boolean
1516
}
1617

1718
export function ChildBodyParametersRows({
@@ -20,17 +21,21 @@ export function ChildBodyParametersRows({
2021
parentName,
2122
parentType,
2223
childParamsGroups,
24+
oneOfObject = false,
2325
}: Props) {
2426
const { t } = useTranslation(['parameter_table', 'products'])
25-
2627
return (
2728
<tr className={cx(styles.childBodyParametersRows, 'color-bg-subtle border-top-0')}>
2829
<td colSpan={4} className="has-nested-table">
2930
<details className="box px-3 ml-1 mb-0" open={open}>
3031
<summary role="button" aria-expanded="false" className="mb-2 keyboard-focus">
31-
<span id={`${slug}-${parentName}-${parentType}`}>
32-
Properties of <code>{parentName}</code>
33-
</span>
32+
{oneOfObject ? (
33+
<span id={`${slug}-${parentName}-${parentType}`}>Can be one of these objects:</span>
34+
) : (
35+
<span id={`${slug}-${parentName}-${parentType}`}>
36+
Properties of <code>{parentName}</code>
37+
</span>
38+
)}
3439
</summary>
3540
<table id={`${parentName}-object`} className="mb-4 color-bg-subtle">
3641
<thead className="visually-hidden">

components/parameter-table/ParameterRow.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ export function ParameterRow({
138138
parentType={Array.isArray(rowParams.type) ? rowParams.type.join(' or ') : rowParams.type}
139139
childParamsGroups={rowParams.childParamsGroups}
140140
open={rowParams.name === clickedBodyParameterName}
141+
oneOfObject={rowParams.oneOfObject}
141142
/>
142143
)}
143144

@@ -164,9 +165,15 @@ export function ParameterRow({
164165
onToggle={bodyParamExpandCallback}
165166
>
166167
<summary role="button" aria-expanded="false" className="mb-2 keyboard-focus">
167-
<span id={`${slug}-${rowParams.name}`}>
168-
Properties of <code>{rowParams.name}</code>
169-
</span>
168+
{rowParams.oneOfObject ? (
169+
<span id={`${slug}-${rowParams.name}`}>
170+
Can be one of these objects: <code>{rowParams.name}</code>
171+
</span>
172+
) : (
173+
<span id={`${slug}-${rowParams.name}`}>
174+
Properties of <code>{rowParams.name}</code>
175+
</span>
176+
)}
170177
</summary>
171178
</details>
172179
</td>

components/parameter-table/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ export interface ChildParameter {
2929
enum?: Array<string | null>
3030
default?: string | boolean | number | undefined | string[]
3131
childParamsGroups?: ChildParameter[]
32+
oneOfObject?: boolean
3233
}

src/github-apps/lib/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
22
"sha": "5e5aae0773f486f4cf84593a39c1187316445672"
3-
ah}
3+
}

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,31 @@ export async function getBodyParams(schema, topLevel = false) {
102102
keyParam.childParamsGroups.push(...(await getBodyParams(param.additionalProperties, false)))
103103
childParamsGroups.push(keyParam)
104104
} else if (paramType && paramType.includes('array')) {
105-
const arrayType = param.items.type
106-
if (arrayType) {
107-
paramType.splice(paramType.indexOf('array'), 1, `array of ${arrayType}s`)
108-
}
109-
if (arrayType === 'object') {
110-
childParamsGroups.push(...(await getBodyParams(param.items, false)))
105+
if (param.items && param.items.oneOf) {
106+
if (param.items.oneOf.every((object) => object.type === 'object')) {
107+
paramType.splice(paramType.indexOf('array'), 1, `array of objects`)
108+
param.oneOfObject = true
109+
110+
for (const oneOfParam of param.items.oneOf) {
111+
const objParam = {
112+
type: 'object',
113+
name: oneOfParam.title,
114+
description: await renderContent(oneOfParam.description),
115+
isRequired: oneOfParam.required,
116+
childParamsGroups: [],
117+
}
118+
objParam.childParamsGroups.push(...(await getBodyParams(oneOfParam, false)))
119+
childParamsGroups.push(objParam)
120+
}
121+
}
122+
} else {
123+
const arrayType = param.items.type
124+
if (arrayType) {
125+
paramType.splice(paramType.indexOf('array'), 1, `array of ${arrayType}s`)
126+
}
127+
if (arrayType === 'object') {
128+
childParamsGroups.push(...(await getBodyParams(param.items, false)))
129+
}
111130
}
112131
} else if (paramType && paramType.includes('object')) {
113132
childParamsGroups.push(...(await getBodyParams(param, false)))
@@ -138,13 +157,12 @@ export async function getBodyParams(schema, topLevel = false) {
138157
const oneOfDescriptions = descriptions.length ? descriptions[0].description : ''
139158
if (!param.description) param.description = oneOfDescriptions
140159

141-
// This is a workaround for an operation that incorrectly defines allOf for a
142-
// body parameter. As a workaround, we will use the first object in the list of
143-
// the allOf array. Otherwise, fallback to the first item in the array.
144-
// This isn't ideal, and in the case of an actual allOf occurrence, we should
145-
// handle it differently by merging all of the properties. There is currently
146-
// only one occurrence for the operation id repos/update-information-about-pages-site
147-
// See Ecosystem API issue number #3332 for future plans to fix this in the OpenAPI
160+
// This is a workaround for an operation that incorrectly defines anyOf
161+
// for a body parameter. As a workaround, we will use the first object
162+
// in the list of the anyOf array. Otherwise, fallback to the first item
163+
// in the array. There is currently only one occurrence for the operation
164+
// id repos/update-information-about-pages-site. See Ecosystem API issue
165+
// number #3332 for future plans to fix this in the OpenAPI
148166
} else if (param && param.anyOf && Object.keys(param).length === 1) {
149167
const firstObject = Object.values(param.anyOf).find((item) => item.type === 'object')
150168
if (firstObject) {
@@ -212,6 +230,10 @@ async function getTransformedParam(param, paramType, props) {
212230
paramDecorated.enum = param.enum
213231
}
214232

233+
if (param.oneOfObject) {
234+
paramDecorated.oneOfObject = true
235+
}
236+
215237
// we also want to catch default values of `false` for booleans
216238
if (param.default !== undefined) {
217239
paramDecorated.default = param.default

src/rest/scripts/utils/sync.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ async function formatRestData(operations) {
109109
async function updateRestConfigData(schemas) {
110110
const restConfigFilename = 'src/rest/lib/config.json'
111111
const restConfigData = JSON.parse(await readFile(restConfigFilename, 'utf8'))
112-
const restApiVersionData = restConfigData['api-versions']
112+
const restApiVersionData = restConfigData['api-versions'] || {}
113113
// If the version isn't one of the OpenAPI version,
114114
// then it's an api-versioned schema
115115
for (const schema of schemas) {
@@ -118,6 +118,9 @@ async function updateRestConfigData(schemas) {
118118
const openApiVer = OPENAPI_VERSION_NAMES.find((ver) => schemaBaseName.startsWith(ver))
119119
const date = schemaBaseName.split(`${openApiVer}-`)[1]
120120

121+
if (!restApiVersionData[openApiVer]) {
122+
restApiVersionData[openApiVer] = []
123+
}
121124
if (!restApiVersionData[openApiVer].includes(date)) {
122125
const dates = restApiVersionData[openApiVer]
123126
dates.push(date)

tests/linting/lint-files.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ const automatedConfigFiles = walk(`src`, { includeBasePath: true, globs: ['**/li
244244
const automatedIgnorePaths = (
245245
await Promise.all(
246246
automatedConfigFiles.map(async (p) => {
247-
return JSON.parse(await fs.readFile(p, 'utf8')).linterIgnore
247+
return JSON.parse(await fs.readFile(p, 'utf8')).linterIgnore || []
248248
})
249249
)
250250
)

0 commit comments

Comments
 (0)