Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: jsonResponse doesn't assume ZodObject #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ethanplee14
Copy link

@ethanplee14 ethanplee14 commented Apr 28, 2023

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 colinhacks/zod#523

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

@seveibar
Copy link
Contributor

Interesting, I wonder if this will maintain safe types

@codetheweb
Copy link
Contributor

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?)

@ethanplee14
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI generation assumes jsonResponse is a z.object()
3 participants