ecyrbe / zodios

typescript http client and server with zod validation
https://www.zodios.org/
MIT License
1.59k stars 44 forks source link

TypeError: o.status is not a function #574

Closed aspdev91 closed 4 months ago

aspdev91 commented 6 months ago

Has anyone run into this bug/error when adding a body parameter to an API?

TypeError: o.status is not a function\n' +
    '    at b (/Users/mt/project/app/server/node_modules/@zodios/express/lib/index.js:12:2221)\n' 

    makeApi([
  {
    method: 'post',
    path: '/',
    alias: 'getRoutine',
    description: 'Get a specific routine instance by UUID',
    parameters: [
      {
        name: 'body',
        schema: z.object({uuid: z.string()}),
        type: 'Body',
      },
    ],
    response: UserRoutineResponseSchema,
  },
  ])
aspdev91 commented 6 months ago

Seems like an issue with this line:

https://github.com/ecyrbe/zodios-express/blob/f4f6c45eb99814fa74309bfae012c100352cc1a5/src/zodios.ts#L118

I tried logging the parameters in the minified code:

function b(t,e,o,a){o.status(400).json(t);}

and t,e,o,a do not line up with the function parameter signature in the code. When I change the code above to:

function b(t,e,o,a){o()}

it works. "o" is next and any errors parsing against the zod schema are passed to an error middleware I use.

stale[bot] commented 5 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.