Skip to content

refactor(streak): introduced zod schema for API parameter validation#124

Open
Subhooo5 wants to merge 2 commits into
JhaSourav07:mainfrom
Subhooo5:feat/zod-param-validation
Open

refactor(streak): introduced zod schema for API parameter validation#124
Subhooo5 wants to merge 2 commits into
JhaSourav07:mainfrom
Subhooo5:feat/zod-param-validation

Conversation

@Subhooo5
Copy link
Copy Markdown
Contributor

@Subhooo5 Subhooo5 commented May 17, 2026

Description

Fixes #67

Introduces zod for strict validation of incoming URL parameters across all three API routes, replacing scattered manual searchParams.get() calls and if/else fallbacks with a single centralized schema.

  • New file lib/validations.ts:
    Defines streakParamsSchema, githubParamsSchema, and ogParamsSchema using Zod. Default values (theme: "dark", scale: "linear", speed: "8s") are handled via Zod's .default(). Invalid speed and scale values silently fall back to their defaults using .catch() to preserve existing behavior. The user and username fields are required and return a structured JSON error if missing.

  • Changes in app/api/streak/route.ts:
    Replaced all individual searchParams.get() calls with a single streakParamsSchema.safeParse() call at the top of the handler. If parsing fails (e.g. missing user), the route returns a clean structured JSON 400 error immediately before any GitHub API call is made. All downstream logic remains identical.

  • Changes in app/api/github/route.ts:
    Replaced manual searchParams.get('username') and if (!username) check with githubParamsSchema.safeParse(). Returns a structured JSON 400 error if username is missing. All error handling and cache logic remains identical.

  • Changes in app/api/og/route.tsx:
    Replaced searchParams.get('user') ?? 'unknown' with ogParamsSchema.parse(). Since user is optional with a default of 'unknown', this route never throws a validation error. All rendering logic remains identical.

  • Added 4 additional optional properties — radius, font, year, and refresh {Other than the requested ones}.

  • All Acceptance Criteria are met. 🚀

Pillar

  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

Screenshot 2026-05-17 at 1 43 52 PM

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak).
  • I have run npm run format and npm run lint locally and resolved all errors.
  • My commits follow the Conventional Commits format.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 17, 2026

@Subhooo5 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@Subhooo5 Subhooo5 force-pushed the feat/zod-param-validation branch from c827b62 to d3a01fd Compare May 17, 2026 08:28
@Subhooo5
Copy link
Copy Markdown
Contributor Author

Hey @JhaSourav07 , please feel free to review the PR and merge the same. It satisfies all the acceptance criteria. Thank you 🚀🫂.

@Subhooo5 Subhooo5 closed this May 17, 2026
@Subhooo5 Subhooo5 deleted the feat/zod-param-validation branch May 17, 2026 08:44
@Subhooo5 Subhooo5 restored the feat/zod-param-validation branch May 17, 2026 08:44
@Subhooo5 Subhooo5 deleted the feat/zod-param-validation branch May 17, 2026 08:44
@Subhooo5 Subhooo5 restored the feat/zod-param-validation branch May 17, 2026 08:44
@Subhooo5 Subhooo5 reopened this May 17, 2026
@Subhooo5
Copy link
Copy Markdown
Contributor Author

@JhaSourav07 I accidentally named the branch on my fork as feat/zod-param-validation instead of refactor/zod-param-validation . So is the PR ok to merge, or do I need to recreate the PR with the updated correct branch name? It would take me just a few clicks to recreate the PR. Please feel free to confirm if change is required. 🚀

@JhaSourav07
Copy link
Copy Markdown
Owner

@Subhooo5
Kindly look at the comment i have left in the issue

@JhaSourav07
Copy link
Copy Markdown
Owner

@harxhe

Can you please review this PR.

@JhaSourav07 JhaSourav07 added performance Improvements related to speed, efficiency, caching, and reducing resource usage GSSoC 2026 level:advanced Complex contributions involving architecture, optimization, or significant feature work quality:exceptional Outstanding contribution with exceptional implementation quality, testing. mentor:harxhe labels May 17, 2026
@Subhooo5 Subhooo5 force-pushed the feat/zod-param-validation branch from d3a01fd to 42af8cb Compare May 17, 2026 09:40
@Subhooo5
Copy link
Copy Markdown
Contributor Author

@Subhooo5 Kindly look at the comment i have left in the issue

All Done @JhaSourav07 🚀. Feel free to check and authorize.

@JhaSourav07
Copy link
Copy Markdown
Owner

Hey @Subhooo5,

@harxhe will review your PR. Once he will Approve it i will merge it.
Till then can you make sure to keep the PR to 1 commit.

@Subhooo5 Subhooo5 force-pushed the feat/zod-param-validation branch from 87dd2d4 to e98f260 Compare May 17, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GSSoC 2026 level:advanced Complex contributions involving architecture, optimization, or significant feature work mentor:harxhe performance Improvements related to speed, efficiency, caching, and reducing resource usage quality:exceptional Outstanding contribution with exceptional implementation quality, testing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core: Add Zod validation for API search parameters

2 participants