This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathappRouter.ts
51 lines (47 loc) · 1.54 KB
/
appRouter.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import {generateOpenApiDocument} from '@lilyrose2798/trpc-openapi'
import {publicProcedure, trpc, z} from '@supaglue/vdk'
import {crmRouter} from '@supaglue/vertical-crm'
import {salesEngagementRouter} from '@supaglue/vertical-sales-engagement'
import {mgmtRouter} from './mgmtRouter'
const publicRouter = trpc.router({
health: publicProcedure
.meta({
openapi: {
method: 'GET',
path: '/health',
summary: 'Health check',
},
})
.input(z.void())
.output(z.string())
.query(() => 'Ok as of ' + new Date().toISOString()),
getOpenAPISpec: publicProcedure
.meta({openapi: {method: 'GET', path: '/openapi.json'}})
.input(z.void())
.output(z.unknown())
.query((): unknown => getOpenAPISpec()),
})
export const appRouter = trpc.router({
public: publicRouter,
mgmt: mgmtRouter,
salesEngagement: salesEngagementRouter,
crm: crmRouter,
})
export function getOpenAPISpec() {
const oas = generateOpenApiDocument(appRouter, {
openApiVersion: '3.1.0', // Want jsonschema
title: 'Bulid your own Supaglue',
version: '0.0.0',
baseUrl: 'http://localhost:3000/api',
// TODO: add the security field to specify what methods are required.
securitySchemes: {
apiKey: {name: 'x-api-key', type: 'apiKey', in: 'header'},
customerId: {name: 'x-customer-id', type: 'apiKey', in: 'header'},
providerName: {name: 'x-provider-name', type: 'apiKey', in: 'header'},
},
})
return oas
}
if (require.main === module) {
console.log(JSON.stringify(getOpenAPISpec(), null, 2))
}