nextlove icon indicating copy to clipboard operation
nextlove copied to clipboard

fix: jsonResponse doesn't assume ZodObject

Open ethanplee14 opened this issue 2 years ago • 3 comments

Close #60

Checks if json response is a zod json object schema or not by checking the zod schema definition typeName. It's a bit of a weird feature that I found after doing some digging here https://github.com/colinhacks/zod/pull/523

I also haven't tested this yet. If someone can explain how to do that, would appreciate it.

ethanplee14 avatar Apr 28 '23 04:04 ethanplee14

Interesting, I wonder if this will maintain safe types

seveibar avatar Apr 28 '23 05:04 seveibar

I also haven't tested this yet. If someone can explain how to do that, would appreciate it.

I think you can add a test to the example app in this repo (but those tests don't currently run in CI?)

codetheweb avatar Apr 28 '23 18:04 codetheweb

Got around this by adding a addOkStatus: false in my route spec. Will use this for now and look into testing the solution or other options.

import { createWithRouteSpec } from 'nextlove'

import withDb from './with-db.ts'
import withOAuthAccessToken from './with-oauth-access-token.ts'

export const withRouteSpec = createWithRouteSpec({
  apiName: 'Fake Template',
  productionServerUrl: 'https://example.com',
  shouldValidateGetRequestBody: false,
  globalMiddlewares: [withDb],
  authMiddlewareMap: {
    oauth_access_token: withOAuthAccessToken,
  },
  addOkStatus: false,
} as const)

export default withRouteSpec

ethanplee14 avatar May 01 '23 17:05 ethanplee14