middleware icon indicating copy to clipboard operation
middleware copied to clipboard

[zod-openapi] streamSSE from hono/streaming together with @hono/zod-openapi have type issues

Open sebastianwessel opened this issue 1 year ago • 1 comments

Think it is related to this: #374

Issue:

The return type of streamSSE does not match and typsescript is complaining

Example:

const chatRoute = createRoute({
  method: 'post',
  path: '/{projectId}/chat',
  security: [{ Bearer: [] }],
  description: 'Send a message to the project chat and receive a response via SSE',
  request: {
    params: z.object({
      projectId: z.string().describe('The ID of the project'),
    }),
    body: {
      content: {
        'application/json': {
          schema: z.object({
            message: z.string().describe('The message to send'),
            conversationId: z
              .string()
              .optional()
              .describe('The ID of the conversation, if continuing an existing one'),
          }),
        },
      },
    },
  },
  responses: {
    200: {
      description: 'Successful response with SSE stream',
      content: {
        'text/event-stream': {
          schema: z.object({
            event: z.enum(['start', 'token', 'end', 'error']),
            data: z.string(),
          }),
        },
      },
    },
    ...errorResponse,
  },
})

app.openapi(chatRoute, async (c) => {
  return streamSSE(c, async (stream) => {
   [...]
  })
})

sebastianwessel avatar Sep 09 '24 12:09 sebastianwessel

This related to https://github.com/honojs/hono/issues/3309

yusukebe avatar Sep 10 '24 06:09 yusukebe