feat(api): implement runtime zod request validation - #64
Merged
codebestia merged 1 commit intoMay 29, 2026
Conversation
- Add reusable validate(schema) Express middleware returning structured 400s
- Add ChallengeSchema and VerifySchema for auth routes
- Replace manual if(!field) guards in auth.ts with validate middleware
- Structured error format: { error, issues: [{ field, message }] }
- Add supertest + 6 tests covering valid input, missing fields, wrong types
|
@0xDeon Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
codebestia
added a commit
that referenced
this pull request
Jun 26, 2026
feat(api): implement runtime zod request validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces unsafe manual
if (!field)guards in auth routes with a reusable Zod-powered validation middleware that returns structured 400 responses.Validation Architecture
A single
validate(schema)middleware factory insrc/middleware/validate.tswraps any Zod schema. On failure it returns:{ "error": "Validation failed", "issues": [{ "field": "walletAddress", "message": "walletAddress is required" }] }On success it replaces
req.bodywith the parsed (type-safe) data and callsnext().Middleware Design
validate(schema)returns a standard ExpressRequestHandler(3-arg)schema.safeParse()— never throwsissues[].fieldis the dot-joined Zod path (e.g.nested.field)Routes Migrated
POST /auth/challengeChallengeSchema— requireswalletAddress: stringPOST /auth/verifyVerifySchema— requireswalletAddress,signature,nonceSchemas live in
src/schemas/auth.schemas.tsfor maintainability.Tests Added
src/__tests__/validate.test.ts— 6 test cases:field+messagekeysAll 17 tests pass. Lint clean.
Fixes #20