Skip to content

Commit

Permalink
chore: add changeset
Browse files Browse the repository at this point in the history
  • Loading branch information
smiley-uriux committed Nov 18, 2024
1 parent 3e825ef commit 5369669
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/healthy-kids-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'nestjs-typebox': patch
---

fix: apply response transformation before validation
8 changes: 6 additions & 2 deletions src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ export function buildSchemaValidator(config: SchemaValidatorConfig): SchemaValid
data = Convert(schema, references, data);
}

if (analysis.hasTransform) {
data = type === 'response' ? TransformEncode(schema, references, data) : TransformDecode(schema, references, data);
if (analysis.hasTransform && type === 'response') {
data = TransformEncode(schema, references, data);
}

if (!checker.Check(data)) {
throw new TypeboxValidationException(type, checker.Errors(data));
}

if (analysis.hasTransform && type !== 'response') {
data = TransformDecode(schema, references, data);
}

return data;
},
};
Expand Down

0 comments on commit 5369669

Please sign in to comment.