turkerdev / fastify-type-provider-zod

MIT License
303 stars 19 forks source link

feat: added refs and separated the type providers #77

Closed Bram-dc closed 2 weeks ago

Bram-dc commented 2 months ago

I added a way to add refs to your schema and modified the type provider correctly for when this PR is accepted: https://github.com/fastify/fastify/discussions/5311

Bram-dc commented 2 months ago

Refs will be added once they find a matching object in the "components" objects. It uses JSON.stringify to check for this. It also checks for some common alterations like nullable.

    const app = Fastify();
    app.setValidatorCompiler(validatorCompiler);
    app.setSerializerCompiler(serializerCompiler);

    const TOKEN_SCHEMA = z.string().length(12);

    app.register(fastifySwagger, {
      openapi: {
        info: {
          title: 'SampleApi',
          description: 'Sample backend service',
          version: '1.0.0',
        },
        components: {
          schemas: jsonSchemaTransformSchemas({
            Token: TOKEN_SCHEMA,
          }),
        },
        servers: [],
      },
      transform: jsonSchemaTransform,
      transformObject: jsonSchemaTransformObject,
    });
Bram-dc commented 1 month ago

This change got accepted in: https://github.com/fastify/fastify/pull/5427

Bram-dc commented 2 weeks ago

I just merged the latest changes into my branch and resolved some linting errors! This should be ready to go for v5. I you wish to have the ref feature separated please tell me.

Bram-dc commented 2 weeks ago

I just merged the latest changes into my branch and resolved some linting errors! This should be ready to go for v5. I you wish to have the ref feature separated please tell me.

https://github.com/turkerdev/fastify-type-provider-zod/pull/97

Bram-dc commented 2 weeks ago

I created 2 other PRs to separate these changes:

https://github.com/turkerdev/fastify-type-provider-zod/pull/97 https://github.com/turkerdev/fastify-type-provider-zod/pull/98