Skip to content

Commit

Permalink
Implement hasPagination
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Feb 27, 2025
1 parent 2469ccb commit fd6c7cf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
28 changes: 23 additions & 5 deletions src/lib/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,11 @@ const createEndpointFromOperation = async (
const draftMessage = parsedOperation['x-draft']

const request = createRequest(methods, operation, path)
const response = createResponse(operation, path, context)
const { hasPagination, ...response } = createResponse(
operation,
path,
context,
)

const operationAuthMethods = parsedOperation.security.map(
(securitySchema) => {
Expand All @@ -595,8 +599,7 @@ const createEndpointFromOperation = async (
draftMessage,
response,
request,
// TODO: True if response properties contains the paginationResponseKey
hasPagination: false,
hasPagination,
authMethods: endpointAuthMethods,
workspaceScope,
}
Expand Down Expand Up @@ -909,7 +912,7 @@ const createResponse = (
operation: OpenapiOperation,
path: string,
context: Context,
): Response => {
): Response & { hasPagination: boolean } => {
if (!('responses' in operation) || operation.responses == null) {
throw new Error(
`Missing responses in operation for ${operation.operationId}`,
Expand All @@ -924,7 +927,11 @@ const createResponse = (
const okResponse = responses['200']

if (typeof okResponse !== 'object' || okResponse == null) {
return { responseType: 'void', description: 'Unknown' }
return {
responseType: 'void',
description: 'Unknown',
hasPagination: false,
}
}

const description = okResponse.description ?? ''
Expand All @@ -939,6 +946,7 @@ const createResponse = (
return {
responseType: 'void',
description,
hasPagination: false,
}
}

Expand All @@ -951,6 +959,7 @@ const createResponse = (
return {
responseType: 'void',
description,
hasPagination: false,
}
}

Expand All @@ -960,6 +969,7 @@ const createResponse = (
return {
responseType: 'void',
description,
hasPagination: false,
}
}

Expand All @@ -968,6 +978,7 @@ const createResponse = (
return {
responseType: 'void',
description,
hasPagination: false,
}
}

Expand Down Expand Up @@ -1003,6 +1014,12 @@ const createResponse = (
responseKey: refKey,
resourceType: refString?.split('/').at(-1) ?? 'unknown',
description,
hasPagination:
(paginationResponseKey in properties &&
properties[paginationResponseKey]?.$ref?.endsWith(
`/${paginationResponseKey}`,
)) ??
false,
...(actionAttemptType != null && { actionAttemptType }),
}
}
Expand All @@ -1011,6 +1028,7 @@ const createResponse = (
return {
responseType: 'void',
description: 'Unknown',
hasPagination: false,
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/snapshots/blueprint.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ Generated by [AVA](https://avajs.dev).
deprecationMessage: '',
description: '',
draftMessage: '',
hasPagination: false,
hasPagination: true,
isDeprecated: false,
isDraft: false,
isUndocumented: false,
Expand Down Expand Up @@ -2001,7 +2001,7 @@ Generated by [AVA](https://avajs.dev).
deprecationMessage: '',
description: '',
draftMessage: '',
hasPagination: false,
hasPagination: true,
isDeprecated: false,
isDraft: false,
isUndocumented: false,
Expand Down
Binary file modified test/snapshots/blueprint.test.ts.snap
Binary file not shown.

0 comments on commit fd6c7cf

Please sign in to comment.