Skip to content

[zod-openapi] parameters mapped to schema + form explode #792

Description

@hffmnn

Note: Because openapi-zod is a library standing on the shoulders of other libraries, I don't have an idea if this is the correct repository to ask.

I am currently migrating an existing API with an OpenAPI spec (that users use to automatically generate clients) to hono. What I would need (without breaking changes for automatically generated clients), would be this:

- in: query
          name: sort
          schema:
            $ref: "#/components/schemas/sort"
          style: form
          explode: true

I have the following call to createRoute

export const list = createRoute({
  path: "/profile",
  method: "get",
  summary: "Get a list of profiles for a given space.",
  request: {
    query: SortSchema,,
  },
});

and the following schema:

import { z } from "@hono/zod-openapi";

export const SortSchema = z.object({
  field: z.string().default("submittedAt").openapi({
    description: "The field to sort by. Default is 'submittedAt'.",
  }),
  order: z.enum(["ASC", "DESC"]).default("ASC").openapi({
    description: "The sort order. Can be either 'ASC' or 'DESC'. Default is 'ASC'.",
  }),
}).openapi("sort");

When generating some OpenAPI, it generates this as parameters (yaml for better readability):

...
parameters:
        - schema:
            type: string
            default: submittedAt
            description: The field to sort by. Default is 'submittedAt'.
          required: false
          name: field
          in: query
        - schema:
            type: string
            enum:
              - ASC
              - DESC
            default: ASC
            description: The sort order. Can be either 'ASC' or 'DESC'. Default is 'ASC'.
          required: false
          name: order
          in: query

First question: Shouldn't it put the schemas under a shared component (as it does with responses). This is what I would have expected:

- in: query
          name: sort
          schema:
            $ref: "#/components/schemas/sort"

So far I am without any luck to achieve this.

Second question: Where would it be possible to add the style and explode properties?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions