turkerdev / fastify-type-provider-zod

MIT License
337 stars 21 forks source link

Could not resolve reference: Could not resolve pointer:does not exist in document #33

Closed Twiggeh closed 1 year ago

Twiggeh commented 1 year ago

Same zod object in the schema will throw the error in the title "Could not resolve reference: Could not resolve pointer:does not exist in document"

Full reproducible repo: https://github.com/Twiggeh/fastify-type-provider-zod-report/tree/main'

Quick Repro:

import { z } from "zod";
import { tFastify } from "../app.js";
export const accessToken = z.object({
    access_token: z.string(),
    expires_in: z.number(),
    user: z.string(),
    token_type: z.literal("Bearer"),
});

const LOGIN_SCHEMA = z.object({
    username: z.string().max(32).describe("Some description for username"),
    token: accessToken,
    password: z.string().max(32),
});

const loginResponse = z.object({
    username: z.string().max(32).describe("Some description for username"),
    login: accessToken,
    token: accessToken, // comment me !!!
    password: z.string().max(32),
});

export default (fastify: typeof tFastify) =>
    fastify.route({
        method: "POST",
        url: "/login",
        schema: { body: LOGIN_SCHEMA, response: { 200: loginResponse } },
        handler: (req, res) => {
            res.send({
                password: "",
                clients: [],
                token: {
                    access_token: "",
                    expires_in: 100,
                    token_type: "Bearer",
                    user: "",
                },
                login: {
                    access_token: "",
                    expires_in: 100,
                    token_type: "Bearer",
                    user: "",
                },
                username: "",
            });
        },
    });
ivstiv commented 1 year ago

I am running into a similar issue with extended schemas. Is there anything needed for the PR to get merged like tests or has it just been forgotten?

kibertoad commented 1 year ago

Approved, we can merge and release