Skip to content

Router: staff API input rules live in tags and Resolve - #2748

Open
tbarbugli wants to merge 1 commit into
mainfrom
cursor/staff-api-validation-rules
Open

tbarbugli wants to merge 1 commit into
mainfrom
cursor/staff-api-validation-rules

Conversation

@tbarbugli

Copy link
Copy Markdown
Member

Why

The /v1/manage/* and /v1/ops/* operations still validated their input by hand in handlers, which the go skill's api.md rules say belongs in struct tags or a Resolve method. Some refusals also put internal text (a store error, the operator's public URL) into the response.

Changes

  • Request-only checks move out of handlers into Resolve methods: blank after trim, from/to ordering, span and horizon, UTF-8 and NUL, limit subject/level/id rules, user and scope rules, allowed IP ranges, price-change content rules. Handlers keep only checks that need stored state.
  • Staff-only price-change types get tags: entries required with minItems: 1, Idempotency-Key required on create, maxLength: 255 on both keys. at on the active price list is a typed time.Time parameter.
  • Provider-app manifest and registration refusals answer with fixed messages instead of passing through the error text.
  • Limits, grants, account and user-policy types are shared with customer routes, so they use Resolve only and no schema tag changed.
  • openapi.yaml regenerated: the only diff is in the staff-only price-change operations.
  • Refusals are still 400, but request-only ones now come as the validation_failed envelope naming the field.
  • Left as is: manageActor middleware (refuses before Huma binds), cursor errors (already fixed messages), and the getSpend renamed-parameter errors in server.go.

Validation

  • go build ./..., go vet ./internal/api, go vet -tags integration ./internal/api and go test ./... -count=1 pass.
  • Postgres-backed suites skip without ROUTER_POSTGRES_DSN; they compile, but none of their cases ran, so behaviour through the store is untested here.
  • New unit tests serve each changed operation through humatest or a chi router with no store, so a refused request never reaches a handler, and a valid one does.

Blank, ordering, span and target rules on the /v1/manage and /v1/ops operations move into Resolve methods; provider-app and 10DLC refusals answer in fixed words.
@tbarbugli
tbarbugli marked this pull request as ready for review November 30, 2026 14:29
@getstream-metis

Copy link
Copy Markdown

👋 Hi Tommaso, want a second pair of eyes on this?

I'm Jeffery, Stream's review agent. I look for bugs, regressions, missing tests and slow paths, and I only post findings I've checked against the code.

  • Review this PR

Or comment /jeffery review. I'll stay quiet unless you ask.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant