asteasolutions / zod-to-openapi

A library that generates OpenAPI (Swagger) docs from Zod schemas
MIT License
788 stars 52 forks source link

using post request #204

Closed colinricardo closed 5 months ago

colinricardo commented 5 months ago

how can i add a schema for the data on an incoming post request?

it doesnt seem to just accept a z.object()

e.g.

registry.registerPath({
  method: "post",
  path: "/whatever",
  description: "Do something.",
  requestBody: {
    // what goes here?
  },
  responses: {
    200: {
      description: "Object with user data.",
      content: {
        "application/json": {
          schema: $MySchema,
        },
      },
    },

  },
})
AGalabov commented 5 months ago

@colinricardo the correct place to use this would be inside the request.body property instead. Iti s mentioned in this section https://nextjs.org/docs/app/building-your-application/routing/route-handlers