Skip to content

Multiple content types for the same route and method #207

@markedwards

Description

@markedwards

We have an oauth2 token endpoint, and we want it to work both with application/json and application/x-www-form-urlencoded. This does not seem to be possible out of the box.

However, it seems I can do this in roughly this way:

  • specifying no input.contentType
  • providing a z.union() for input.body which accepts a zod schema and a zod-form-data schema
  • using custom logic in the handler() to manage content-type and coerce types
  • provide a openApiOperation.requestBody and ignore type errors, the openapi schema reflects the expected structure

Is there a less hacky way to do this? Is this a capability that could be officially supported?

Another side note -- just trying to create a standard form data endpoint using the example from the docs, I get a type error on body: formSchema. This is with next-rest-framework 6.0.7, zod 3.25.76, and sod-form-data 2.0.8. The execution works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions