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

Omitted request body path param leaves an empty request body #296

Closed
levi opened this issue May 2, 2023 · 0 comments · Fixed by #310
Closed

Omitted request body path param leaves an empty request body #296

levi opened this issue May 2, 2023 · 0 comments · Fixed by #310
Labels
bug Something isn't working

Comments

@levi
Copy link

levi commented May 2, 2023

#10 Removed path params from request bodies. However, if the request body only has a single parameter that is the path parameter, the generated spec will still define a required empty request body. For example:

export const router = createTRPCRouter({
  favorite: procedure
    .meta({ openapi: { method: 'POST', path: '/posts/{id}/favorite' } })
    .input(z.object({ id: z.string() }))
    .output(z.object({ id: z.string() }))
    .mutation(async ({ ctx, input }) => {
      // ...
    })
})

Generates:

{
  "post": {
    "operationId": "mutation.post.favorite",
    "requestBody": {
      "required": true,
      "content": {
        "application/json": {
          "schema": {
            "type": "object",
            "properties": {},
            "additionalProperties": false
          }
        }
      }
    },
    "parameters": [
      {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": { "type": "string" }
      }
    ],
    "responses": {
      //...
    }
  }
}

When really it should have no body at all, since there is technically no request body required. This causes an issue with my code gen tooling, since an empty request body creates an Any type and it doesn't know how to decode it.

@jlalmes jlalmes added the bug Something isn't working label May 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants