Skip to content

openapi: fix nested params (#26894) #17044

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
956 changes: 903 additions & 53 deletions lib/rest/static/decorated/api.github.com.json

Large diffs are not rendered by default.

485 changes: 453 additions & 32 deletions lib/rest/static/decorated/ghes-3.1.json

Large diffs are not rendered by default.

795 changes: 750 additions & 45 deletions lib/rest/static/decorated/ghes-3.2.json

Large diffs are not rendered by default.

795 changes: 750 additions & 45 deletions lib/rest/static/decorated/ghes-3.3.json

Large diffs are not rendered by default.

956 changes: 903 additions & 53 deletions lib/rest/static/decorated/ghes-3.4.json

Large diffs are not rendered by default.

956 changes: 903 additions & 53 deletions lib/rest/static/decorated/github.ae.json

Large diffs are not rendered by default.

36 changes: 31 additions & 5 deletions script/rest/utils/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,12 @@ async function getBodyParams(paramsObject, requiredParams) {
param.childParamsGroups.push(childParamsGroup)
}

// if the param is an object, it may have child object params that have child params :/
if (param.rawType === 'object') {
// If the param is an object, it may have child object params that have child params :/
// Objects can potentially be null where the rawType is [ 'object', 'null' ].
if (
param.rawType === 'object' ||
(Array.isArray(param.rawType) && param.rawType.includes('object'))
) {
param.childParamsGroups.push(
...flatten(
childParamsGroup.params
Expand All @@ -324,8 +328,18 @@ async function getBodyParams(paramsObject, requiredParams) {
}

async function getChildParamsGroup(param) {
// only objects, arrays of objects, anyOf, allOf, and oneOf have child params
if (!(param.rawType === 'array' || param.rawType === 'object' || param.oneOf)) return
// Only objects, arrays of objects, anyOf, allOf, and oneOf have child params.
// Objects can potentially be null where the rawType is [ 'object', 'null' ].
if (
!(
param.rawType === 'array' ||
(Array.isArray(param.rawType) && param.rawType.includes('array')) ||
param.rawType === 'object' ||
(Array.isArray(param.rawType) && param.rawType.includes('object')) ||
param.oneOf
)
)
return
if (
param.oneOf &&
!param.oneOf.filter((param) => param.type === 'object' || param.type === 'array')
Expand All @@ -338,7 +352,19 @@ async function getChildParamsGroup(param) {
const childParams = await getBodyParams(childParamsObject, requiredParams)

// adjust the type for easier readability in the child table
const parentType = param.rawType === 'array' ? 'items' : param.rawType
let parentType

if (param.rawType === 'array') {
parentType = 'items'
} else if (Array.isArray(param.rawType) && param.rawType.includes('array')) {
// handle the case where rawType is [ 'array', 'null' ]
parentType = 'items'
} else if (Array.isArray(param.rawType) && param.rawType.includes('object')) {
// handle the case where rawType is [ 'object', 'null' ]
parentType = 'object'
} else {
parentType = param.rawType
}

// add an ID to the child table so they can be linked to
slugger.reset()
Expand Down