Skip to content

Commit 76e9675

Browse files
Validate actionAttemptType
1 parent ee6e556 commit 76e9675

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/lib/blueprint.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,11 @@ const createResponse = (
921921
)
922922
}
923923

924-
const actionAttemptType = parsedOperation['x-action-attempt-type']
924+
const actionAttemptType = validateActionAttemptType(
925+
parsedOperation['x-action-attempt-type'],
926+
responseKey,
927+
path,
928+
)
925929
const refKey = responseKey
926930

927931
if (refKey != null && properties[refKey] != null) {
@@ -944,6 +948,25 @@ const createResponse = (
944948
}
945949
}
946950

951+
const validateActionAttemptType = (
952+
actionAttemptType: string | undefined,
953+
responseKey: string,
954+
path: string,
955+
) => {
956+
const excludedPaths = ['/action_attempts']
957+
const isPathExcluded = excludedPaths.some((p) => path.startsWith(p))
958+
959+
if (
960+
actionAttemptType == null &&
961+
responseKey === 'action_attempt' &&
962+
!isPathExcluded
963+
) {
964+
throw new Error(`Missing action_attempt_type for path ${path}`)
965+
}
966+
967+
return actionAttemptType
968+
}
969+
947970
export const createProperties = (
948971
properties: Record<string, OpenapiSchema>,
949972
parentPaths: string[],

0 commit comments

Comments
 (0)