metadevpro / openapi3-ts

TS Model & utils for creating and exposing OpenAPI 3.x contracts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

API Parameter description output to wrong place

kernwig opened this issue · comments

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.

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

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

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