Skip to content

fix: normalize adapter middleware responses - #163

Open
charlie12520 wants to merge 2 commits into
tscircuit:mainfrom
charlie12520:charlie/30-adapter-middleware-response-guard
Open

fix: normalize adapter middleware responses#163
charlie12520 wants to merge 2 commits into
tscircuit:mainfrom
charlie12520:charlie/30-adapter-middleware-response-guard

Conversation

@charlie12520

@charlie12520 charlie12520 commented May 27, 2026

Copy link
Copy Markdown

Summary

  • Normalize responses returned by public makeRequest / adapter options.middleware.
  • Thread makeRequest options through createWinterSpecFromRouteMap so the exported helper exercises the same middleware path.
  • Normalize custom handle404 returns so raw JSON gets the existing guidance and ctx.json-style runtime returns become real Responses.
  • Serialize ctx.json(...) / SerializableToResponse middleware short-circuits with z.any().
  • Throw the existing raw JSON guidance when adapter middleware or handle404 returns a plain object.
  • Throw a clear helper error when adapter middleware or handle404 returns unsupported primitives instead of passing invalid values through as Responses.
  • Add focused regression coverage for adapter middleware and handle404 raw object / ctx.json / invalid return paths.

Acceptance / contributor review

Validation

  • 2026-05-27 fresh check: npx ava tests/errors/do-not-allow-raw-json.test.ts -> 7 passed.
  • Earlier check: npx ava tests/errors/do-not-allow-raw-json.test.ts -> 7 passed.
  • Earlier check: npx prettier --check src/types/winter-spec.ts tests/errors/do-not-allow-raw-json.test.ts -> passed.
  • Earlier check: git diff --check -> passed, with only the normal Windows LF-to-CRLF warning.
  • npx tsc --noEmit --pretty false -> blocked by existing OpenAPI/codegen type errors in src/cli/commands/codegen/openapi.ts, src/cli2/commands/codegen/openapi.ts, and tests/cli/codegen/openapi/openapi-codegen.test.ts.
  • npm test -- tests/errors/do-not-allow-raw-json.test.ts -> blocked during pretest build by the existing OpenAPI operation.responses errors above.

Non-overlap check

Before submitting, I checked open PRs for makeRequestAgainstWinterSpec middleware, adapter middleware ctx.json, options.middleware raw object, handle404 ctx.json, and handle404 raw JSON. I did not find an open PR covering these public makeRequest/options.middleware or handle404 paths. PR #162 covers route/auth middleware inside createWithWinterSpec; this patch covers adapter-level middleware and custom 404 handlers passed through makeRequest/adapters.

/claim #30

@charlie12520
charlie12520 force-pushed the charlie/30-adapter-middleware-response-guard branch from 4c08b2d to 9179e92 Compare May 27, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant