Skip to content

Commit

Permalink
Fix validation for non object types
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-codaio committed Oct 7, 2024
1 parent 3bcf351 commit 96ccb7b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions dist/testing/execution.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions testing/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,14 @@ async function findAndExecutePackFunction<T extends FormulaSpecification>(
if (formula) {
const resultToNormalize =
formulaSpec.type === FormulaType.Sync ? (result as GenericSyncFormulaResult).result : result;
let resultToValidate = resultToNormalize;

// Matches legacy behavior within handler_templates:generateObjectResponseHandler where we never
// called transform body on non-object responses.
if (typeof resultToNormalize === 'object') {
const schema = executionContext?.sync?.schema ?? formula.schema;
let normalizedResult = transformBody(resultToNormalize, schema);

if (shouldValidateResult) {
validateResult(formula, normalizedResult);
}
resultToValidate = normalizedResult;

if (!useDeprecatedResultNormalization) {
normalizedResult = untransformBody(normalizedResult, schema);
Expand All @@ -154,6 +152,10 @@ async function findAndExecutePackFunction<T extends FormulaSpecification>(
result = normalizedResult;
}
}

if (shouldValidateResult) {
validateResult(formula, resultToValidate);
}
}

return result;
Expand Down

0 comments on commit 96ccb7b

Please sign in to comment.