Skip to content

Centralize validation with a typed schema layer for request bodies and params #14

Description

@mikewheeleer

Refactor scattered validation into a typed schema layer

Description

Validation in src/index.ts is duplicated and ad-hoc: isAssetCode, parseAmount, the regex checks in the pair PATCH handlers, and the body checks in webhook/api-key/config handlers all repeat the same 400 invalid_request + requestId pattern by hand. This issue centralizes validation behind a small typed schema layer (e.g. zod) and a reusable validate() middleware.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-backend only.
  • Add zod and create src/validation.ts (create file) with schemas for quote params, pair body, fee/min/max/liquidity patches, webhook body, api-key body, and config patch.
  • Provide a validate(schema, source) middleware that emits the existing canonical { error: "invalid_request", message, requestId } body on failure.
  • Preserve the exact BigInt amount semantics (no leading zero, positive) and the 1–12 char asset rule.
  • Keep all current error messages semantically equivalent so tests asserting on message text still pass (adjust regexes if needed).

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b refactor/validation-14-schema-layer
  • Implement changes
  • Test and commit

Test and commit

  • Run npm run build, npm run lint, and npm test.
  • Cover edge cases: each schema's invalid inputs, including array-form params.
  • Paste full npm test output in the PR.

Example commit message

refactor(validation): centralize request validation in a zod schema layer

Guidelines

  • Minimum 95 percent test coverage for impacted code.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions