Skip to content
This repository was archived by the owner on Nov 19, 2024. It is now read-only.
This repository was archived by the owner on Nov 19, 2024. It is now read-only.

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

@levi

Description

@levi

#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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions