Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swagger resolve errors - Could not resolve pointer #197

Open
clabnet opened this issue Oct 21, 2023 · 1 comment
Open

Swagger resolve errors - Could not resolve pointer #197

clabnet opened this issue Oct 21, 2023 · 1 comment

Comments

@clabnet
Copy link

clabnet commented Oct 21, 2023

This is a POST to get all drawings using where, select and others parameters.

export async function getAllDrawings(
  request: FastifyRequest<{ Body: z.infer<typeof drawingFindManyArgsSchema> }>,
  reply: FastifyReply
): Promise<drawing[]> {
  try {
    const { skip, take, select, orderBy, where } = request.body
    const data = await prisma.drawing.findMany({
      select: select,
      where: where,
      orderBy: orderBy,
      take: take ? Number(take) : 10,
      skip: skip ? Number(skip) : undefined,
    })
    if (!data || data.length === 0) {
      return reply.status(404).send({ message: 'No drawings found' })
    }
    return reply.status(200).send(data)
  } catch (error) {
    console.error(error)
    return reply.status(500).send({
      message: 'Error fetching drawings',
    })
  }
}

Using these packages

    "@fastify/swagger": "^8.12.0",
    "@fastify/swagger-ui": "^1.10.1",

when click on Swagger page, POST, I have a lot of errors :

Resolver error at paths./drawings/.post.requestBody.content.application/json.schema.properties.where.properties.AND.anyOf.0.$ref
Could not resolve reference: Could not resolve pointer: /properties/where does not exist in document
Resolver error at paths./drawings/.post.requestBody.content.application/json.schema.properties.where.properties.AND.anyOf.1.items.$ref
Could not resolve reference: Could not resolve pointer: /properties/where does not exist in document
Resolver error at paths./drawings/.post.requestBody.content.application/json.schema.properties.where.properties.OR.items.$ref
Could not resolve reference: Could not resolve pointer: /properties/where does not exist in document
Resolver error at paths./drawings/.post.requestBody.content.application/json.schema.properties.where.properties.NOT.anyOf.0.$ref
Could not resolve reference: Could not resolve pointer: /properties/where does not exist in document
.....

Are correct to use these schemas for CRUD operations ??

  • getByID : drawingWhereUniqueInputSchema
  • getAll : drawingFindManyArgsSchema
  • create : drawingCreateInputSchema
  • update : drawingWhereUniqueInputSchema and drawingUpdateInputSchema
  • delete : drawingWhereUniqueInputSchema

Thanks for your work.

@clabnet clabnet changed the title Swagger resolve errors Swagger resolve errors - Could not resolve pointer Oct 21, 2023
@chrishoermann
Copy link
Owner

@clabnet yes the schemas you mentioned can be used for CRUD operations. I personally use it with trpc but have not used it with swagger or fastify

In your example you also just used the type of the FindMAnyArgsSchema in

  request: FastifyRequest<{ Body: z.infer<typeof drawingFindManyArgsSchema> }>,

but did not validate at runtime if the body actually has the expeced data promised by the type like

const { skip, take, select, orderBy, where } = drawingFindManyArgsSchema.parse(request.body) // or use .safeParse() to not throw any errors directly

maybe this helps to catch any errors in your request body and gives some more traceable error messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants