Implements a public REST API for SplitPro using @trpc/openapi, with OpenAPI 3.1 spec generation, interactive documentation (Scalar), and offset-based pagination#707
Open
kushpvo wants to merge 15 commits into
Conversation
Adds an isolated public REST surface generated by @trpc/openapi (alpha): - apiRouter (curated subset) served at /api/v1 with API-key auth via createApiContext - ApiKey model (sha256-hashed, spro_ prefix) + create/list/revoke procedures + Account UI - OpenAPI spec at /api/openapi.json and Scalar docs at /api/docs - first exposed endpoint: user.me Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Add shared pagination module (paginationInput schema + paginatedResult helper)
- Create API-specific paginated variants for getAllExpenses, getExpensesWithFriend,
getGroupExpenses, and getOwnExpenses (app procedures unchanged)
- All four endpoints return { items, pagination: { total, limit, offset, hasMore } }
- Defaults: limit=20, offset=0, max limit=100
- Post-process generated OpenAPI spec to inject default values for limit/offset
5 tasks
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.
Description
Closes #615 — implements a public REST API for SplitPro using
@trpc/openapi, withOpenAPI 3.1 spec generation, interactive documentation (Scalar), and offset-based
pagination.
API surface (
/api/v1/*)All endpoints authenticate via API key:
Authorization: Bearer spro_<key>.user.meuser.getFriendsuser.getOwnExpensesuser.getBalancesWithFrienduser.getFriendgroup.getAllGroupsgroup.getGroupDetailsexpense.getBalancesexpense.getAllExpensesexpense.getExpensesWithFriendexpense.getGroupExpensesexpense.getExpenseDetailsexpense.addOrEditExpenseInput formats
All GET endpoints accept three equivalent input formats:
?groupId=150&limit=20?input={"groupId":150}?input={"json":{"groupId":150}}POST bodies are accepted as plain JSON (the API transformer handles superjson
transparently for both directions).
Pagination
Four list endpoints use offset-based pagination:
?limit=20&offset=0(defaults:limit=20,offset=0, maxlimit=100){ items: [...], pagination: { total, limit, offset, hasMore } }OpenAPI docs
/api/docs/api/openapi.jsonpnpm gen:openapiArchitecture
src/server/api/apiRouter.ts— curated public API router (separate fromappRouter)src/pages/api/v1/[trpc].ts— handler with API-key context + query param bridgesrc/server/api/pagination.ts— shared offset-pagination helpersscripts/generate-openapi.ts— build-time spec generation + post-processing (injects defaults)appRouterandapiRouterDemo
Checklist
CONTRIBUTING.mdin its entirety