Skip to content

Commit fd6c7cf

Browse files
committed
Implement hasPagination
1 parent 2469ccb commit fd6c7cf

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

src/lib/blueprint.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,11 @@ const createEndpointFromOperation = async (
568568
const draftMessage = parsedOperation['x-draft']
569569

570570
const request = createRequest(methods, operation, path)
571-
const response = createResponse(operation, path, context)
571+
const { hasPagination, ...response } = createResponse(
572+
operation,
573+
path,
574+
context,
575+
)
572576

573577
const operationAuthMethods = parsedOperation.security.map(
574578
(securitySchema) => {
@@ -595,8 +599,7 @@ const createEndpointFromOperation = async (
595599
draftMessage,
596600
response,
597601
request,
598-
// TODO: True if response properties contains the paginationResponseKey
599-
hasPagination: false,
602+
hasPagination,
600603
authMethods: endpointAuthMethods,
601604
workspaceScope,
602605
}
@@ -909,7 +912,7 @@ const createResponse = (
909912
operation: OpenapiOperation,
910913
path: string,
911914
context: Context,
912-
): Response => {
915+
): Response & { hasPagination: boolean } => {
913916
if (!('responses' in operation) || operation.responses == null) {
914917
throw new Error(
915918
`Missing responses in operation for ${operation.operationId}`,
@@ -924,7 +927,11 @@ const createResponse = (
924927
const okResponse = responses['200']
925928

926929
if (typeof okResponse !== 'object' || okResponse == null) {
927-
return { responseType: 'void', description: 'Unknown' }
930+
return {
931+
responseType: 'void',
932+
description: 'Unknown',
933+
hasPagination: false,
934+
}
928935
}
929936

930937
const description = okResponse.description ?? ''
@@ -939,6 +946,7 @@ const createResponse = (
939946
return {
940947
responseType: 'void',
941948
description,
949+
hasPagination: false,
942950
}
943951
}
944952

@@ -951,6 +959,7 @@ const createResponse = (
951959
return {
952960
responseType: 'void',
953961
description,
962+
hasPagination: false,
954963
}
955964
}
956965

@@ -960,6 +969,7 @@ const createResponse = (
960969
return {
961970
responseType: 'void',
962971
description,
972+
hasPagination: false,
963973
}
964974
}
965975

@@ -968,6 +978,7 @@ const createResponse = (
968978
return {
969979
responseType: 'void',
970980
description,
981+
hasPagination: false,
971982
}
972983
}
973984

@@ -1003,6 +1014,12 @@ const createResponse = (
10031014
responseKey: refKey,
10041015
resourceType: refString?.split('/').at(-1) ?? 'unknown',
10051016
description,
1017+
hasPagination:
1018+
(paginationResponseKey in properties &&
1019+
properties[paginationResponseKey]?.$ref?.endsWith(
1020+
`/${paginationResponseKey}`,
1021+
)) ??
1022+
false,
10061023
...(actionAttemptType != null && { actionAttemptType }),
10071024
}
10081025
}
@@ -1011,6 +1028,7 @@ const createResponse = (
10111028
return {
10121029
responseType: 'void',
10131030
description: 'Unknown',
1031+
hasPagination: false,
10141032
}
10151033
}
10161034

test/snapshots/blueprint.test.ts.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,7 @@ Generated by [AVA](https://avajs.dev).
762762
deprecationMessage: '',
763763
description: '',
764764
draftMessage: '',
765-
hasPagination: false,
765+
hasPagination: true,
766766
isDeprecated: false,
767767
isDraft: false,
768768
isUndocumented: false,
@@ -2001,7 +2001,7 @@ Generated by [AVA](https://avajs.dev).
20012001
deprecationMessage: '',
20022002
description: '',
20032003
draftMessage: '',
2004-
hasPagination: false,
2004+
hasPagination: true,
20052005
isDeprecated: false,
20062006
isDraft: false,
20072007
isUndocumented: false,
15 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)