From 85163fa9f74ee3fcbcb8ecee0410cd506a97f936 Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Thu, 10 Nov 2022 10:25:08 -0800 Subject: [PATCH] fix allOf openapi bug (#32501) --- lib/rest/static/decorated/api.github.com.json | 22 +++++++++++++++++-- lib/rest/static/decorated/ghec.json | 22 +++++++++++++++++-- lib/rest/static/decorated/ghes-3.3.json | 22 +++++++++++++++++-- lib/rest/static/decorated/ghes-3.4.json | 22 +++++++++++++++++-- lib/rest/static/decorated/ghes-3.5.json | 22 +++++++++++++++++-- lib/rest/static/decorated/ghes-3.6.json | 22 +++++++++++++++++-- lib/rest/static/decorated/ghes-3.7.json | 22 +++++++++++++++++-- lib/rest/static/decorated/github.ae.json | 22 +++++++++++++++++-- script/rest/utils/get-body-params.js | 21 +++++++++++++++++- 9 files changed, 180 insertions(+), 17 deletions(-) diff --git a/lib/rest/static/decorated/api.github.com.json b/lib/rest/static/decorated/api.github.com.json index 890c082f170c..978c66c06c37 100644 --- a/lib/rest/static/decorated/api.github.com.json +++ b/lib/rest/static/decorated/api.github.com.json @@ -362130,10 +362130,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/ghec.json b/lib/rest/static/decorated/ghec.json index 18045695569a..92ce8de2f37b 100644 --- a/lib/rest/static/decorated/ghec.json +++ b/lib/rest/static/decorated/ghec.json @@ -364090,10 +364090,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/ghes-3.3.json b/lib/rest/static/decorated/ghes-3.3.json index b1cbc6386551..8e3eea61f44e 100644 --- a/lib/rest/static/decorated/ghes-3.3.json +++ b/lib/rest/static/decorated/ghes-3.3.json @@ -284466,10 +284466,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/ghes-3.4.json b/lib/rest/static/decorated/ghes-3.4.json index 712559043e1f..326cb90f95b4 100644 --- a/lib/rest/static/decorated/ghes-3.4.json +++ b/lib/rest/static/decorated/ghes-3.4.json @@ -302677,10 +302677,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/ghes-3.5.json b/lib/rest/static/decorated/ghes-3.5.json index 4321e849140a..c08ab28f931c 100644 --- a/lib/rest/static/decorated/ghes-3.5.json +++ b/lib/rest/static/decorated/ghes-3.5.json @@ -309839,10 +309839,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/ghes-3.6.json b/lib/rest/static/decorated/ghes-3.6.json index c4ba25c849df..669faec2bcde 100644 --- a/lib/rest/static/decorated/ghes-3.6.json +++ b/lib/rest/static/decorated/ghes-3.6.json @@ -319190,10 +319190,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/ghes-3.7.json b/lib/rest/static/decorated/ghes-3.7.json index f340b7e9940e..85a638f55919 100644 --- a/lib/rest/static/decorated/ghes-3.7.json +++ b/lib/rest/static/decorated/ghes-3.7.json @@ -322640,10 +322640,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/lib/rest/static/decorated/github.ae.json b/lib/rest/static/decorated/github.ae.json index bf6de8f81325..957670958c74 100644 --- a/lib/rest/static/decorated/github.ae.json +++ b/lib/rest/static/decorated/github.ae.json @@ -261820,10 +261820,28 @@ ] }, { - "type": "", + "type": "object", "name": "source", "in": "body", - "description": "" + "description": "

Update the source for the repository. Must include the branch name and path.

", + "childParamsGroups": [ + { + "type": "string", + "name": "branch", + "description": "

The repository branch used to publish your site's source files.

", + "isRequired": true + }, + { + "type": "string", + "name": "path", + "description": "

The repository directory that includes the source files for the Pages site. Allowed paths are / or /docs.

", + "isRequired": true, + "enum": [ + "/", + "/docs" + ] + } + ] } ], "enabledForGitHubApps": true, diff --git a/script/rest/utils/get-body-params.js b/script/rest/utils/get-body-params.js index 922e13618a94..1abaee7569a4 100644 --- a/script/rest/utils/get-body-params.js +++ b/script/rest/utils/get-body-params.js @@ -47,7 +47,6 @@ export async function getBodyParams(schema, topLevel = false) { for (const [paramKey, param] of Object.entries(properties)) { const paramDecorated = {} - // OpenAPI 3.0 only had a single value for `type`. OpenAPI 3.1 // will either be a single value or an array of values. // This makes type an array regardless of how many values the array @@ -120,6 +119,26 @@ export async function getBodyParams(schema, topLevel = false) { // is in the first child parameter. const oneOfDescriptions = descriptions.length ? descriptions[0].description : '' if (!param.description) param.description = oneOfDescriptions + + // This is a workaround for an operation that incorrectly defines allOf for a + // body parameter. As a workaround, we will use the first object in the list of + // the allOf array. Otherwise, fallback to the first item in the array. + // This isn't ideal, and in the case of an actual allOf occurrence, we should + // handle it differently by merging all of the properties. There is currently + // only one occurrence for the operation id repos/update-information-about-pages-site + // See Ecosystem API issue number #3332 for future plans to fix this in the OpenAPI + } else if (param && param.anyOf && Object.keys(param).length === 1) { + const firstObject = Object.values(param.anyOf).find((item) => item.type === 'object') + if (firstObject) { + paramType.push('object') + param.description = firstObject.description + param.isRequired = firstObject.required + childParamsGroups.push(...(await getBodyParams(firstObject, false))) + } else { + paramType.push(param.anyOf[0].type) + param.description = param.anyOf[0].description + param.isRequired = param.anyOf[0].required + } } // Supports backwards compatibility for OpenAPI 3.0