elierotenberg/fastify-zod

Validation schema not working for params & querystring

henrifardeau opened this issue · 4 comments

Hello !

I encounter an error when validating parameters or querystring

I register all my schema in my app file like so :

export const { schemas, $ref } = buildJsonSchemas({
  findByIdPartnerSchema,
  findByIdCustomerSchema,
  createPartnerSchema,
  createCustomerSchema,
});

schemas.forEach((schema) => app.addSchema(schema));

I try to generate documentation based on the "findByIdCustomerSchema" but this is what i'm getting; (It's working for body validation/documentation)

Maybe i'm doing something wrong 😅

Thank you for your help !
(From france 🇫🇷)

Capture d’écran 2022-05-20 à 10 08 20

Capture d’écran 2022-05-20 à 10 08 30

Capture d’écran 2022-05-20 à 10 09 02

Capture d’écran 2022-05-20 à 10 11 16

EDIT : Sorry my bad, i was using @fastify/swagger instead of fastify-swagger

@henrifardeau did you downgrade to get this working?

It looks like https://www.npmjs.com/package/fastify-swagger is actually deprecated.
They recommend upgrading to @fastify/swagger@6.0.0

Hello,

I'm sorry, as mentioned in #15 for some reason GitHub notifications got lost in my mailbox.

I added support for querystring in 1.0.0. Does it cover your needs?

@sourcec0de did you ever find a workaround for this? @elierotenberg do we HAVE to use fastify-swagger to get queryStrings and params working? I am running into this same issue still

EDIT: NVM! my solution was to use @fastify/swagger in dynamic mode and change swagger (openAPIV2) in the plugin definition to openapi:

import { FastifyPluginAsync } from "fastify";
import fp from "fastify-plugin";
import fastifySwagger from "@fastify/swagger";
import fastifySwaggerUi from "@fastify/swagger-ui";

const schemas: FastifyPluginAsync = async (fastify) => {
  await fastify.register(fastifySwagger, {
    openapi: {
      info: {
        title: "API",
        description: "Documentation for our application APIs",
        version: "0.0.1",
      },
      host: "localhost:8080",
      schemes: ["http"],
      consumes: ["application/json"],
      produces: ["application/json"],
      securityDefinitions: {
        apiKey: {
          type: "apiKey",
          name: "Authorization",
          in: "header",
        },
      },
    },
  });

  await fastify.register(fastifySwaggerUi, {
    routePrefix: "/documentation",
  });
};

export default fp(schemas);