⚗️ Implement chat API
This commit is contained in:
15
apps/viewer/src/utils/server/generateOpenApi.ts
Normal file
15
apps/viewer/src/utils/server/generateOpenApi.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { generateOpenApiDocument } from 'trpc-openapi'
|
||||
import { writeFileSync } from 'fs'
|
||||
import { appRouter } from './routers/v1/_app'
|
||||
|
||||
const openApiDocument = generateOpenApiDocument(appRouter, {
|
||||
title: 'Chat API',
|
||||
version: '1.0.0',
|
||||
baseUrl: 'https://typebot.io/api/v1',
|
||||
docsUrl: 'https://docs.typebot.io/api',
|
||||
})
|
||||
|
||||
writeFileSync(
|
||||
'./openapi/chat/_spec_.json',
|
||||
JSON.stringify(openApiDocument, null, 2)
|
||||
)
|
8
apps/viewer/src/utils/server/routers/v1/_app.ts
Normal file
8
apps/viewer/src/utils/server/routers/v1/_app.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { chatRouter } from '@/features/chat/api'
|
||||
import { router } from '../../trpc'
|
||||
|
||||
export const appRouter = router({
|
||||
chat: chatRouter,
|
||||
})
|
||||
|
||||
export type AppRouter = typeof appRouter
|
13
apps/viewer/src/utils/server/trpc.ts
Normal file
13
apps/viewer/src/utils/server/trpc.ts
Normal file
@ -0,0 +1,13 @@
|
||||
import { initTRPC } from '@trpc/server'
|
||||
import { OpenApiMeta } from 'trpc-openapi'
|
||||
import superjson from 'superjson'
|
||||
|
||||
const t = initTRPC.meta<OpenApiMeta>().create({
|
||||
transformer: superjson,
|
||||
})
|
||||
|
||||
export const middleware = t.middleware
|
||||
|
||||
export const router = t.router
|
||||
|
||||
export const publicProcedure = t.procedure
|
Reference in New Issue
Block a user