metadevpro / openapi3-ts

TS Model & utils for creating and exposing OpenAPI 3.x contracts.
MIT License
485 stars 64 forks source link

API Parameter description output to wrong place #125

Closed kernwig closed 1 year ago

kernwig commented 1 year ago

The output OpenAPI spec does not place the description of a (query string) parameter in the right place, and thus is lost when rendered.

Example:

const getServiceAreasRequestSchema = z
  .object({
    clientBC: z.string().describe("Business code identifying the Client"),
  });

// ... elsewhere ....

import { OpenApiGeneratorV3, OpenAPIRegistry } from "@asteasolutions/zod-to-openapi";
import { OpenAPIObject } from "openapi3-ts/oas30";
// ...

  registry.registerPath({
    path: "/clients/getServiceAreas",
    method: "get",
    request: { query: getServiceAreasRequestSchema },
    responses: {
      "200": { content: { "application/json": { schema: serviceAreaSchema.array() } }  },
    },
  });

Results in OpenAPI spec:

  /clients/getServiceAreas:
    get:
      parameters:
        - schema:
            type: string
            minLength: 1
            description: Business code identifying the Client
          required: true
          name: clientBC
          in: query
      responses:
        "200":
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: "#/components/schemas/ServiceArea"

The description: Business code identifying the Client belongs one element up, next to the parameter name and required. See https://swagger.io/docs/specification/describing-parameters/

As a result, the description is not rendered by Swagger UI.

samchungy commented 1 year ago

Hey mate this is an issue with the zod-to-openapi library and not this library

pjmolina commented 1 year ago

Note the field description is part of the parameter object. In your sample @kernwig it is placed under schema.

kernwig commented 1 year ago

@pjmolina , that's the bug I was reporting. @samchungy Thanks for pointing out the mix-up.