feature: add trpc openapi (#1818)

This commit is contained in:
Manuel
2024-01-14 22:20:51 +01:00
committed by GitHub
parent 33da630db5
commit c701f723cf
18 changed files with 2177 additions and 134 deletions

View File

@@ -15,11 +15,13 @@ import { adminProcedure, createTRPCRouter, publicProcedure } from '../trpc';
export const configRouter = createTRPCRouter({
delete: adminProcedure
.meta({ openapi: { method: 'DELETE', path: '/configs', tags: ['config'] } })
.input(
z.object({
name: configNameSchema,
}),
)
.output(z.object({ message: z.string() }))
.mutation(async ({ input }) => {
if (input.name.toLowerCase() === 'default') {
Consola.error('Rejected config deletion because default configuration can\'t be deleted');
@@ -160,11 +162,21 @@ export const configRouter = createTRPCRouter({
};
}),
byName: publicProcedure
.meta({
openapi: {
method: 'GET',
path: '/configs/byName',
tags: ['config'],
deprecated: true,
summary: 'Retrieve content of the JSON configuration. Deprecated because JSON will be removed in a future version and be replaced with a relational database.'
}
})
.input(
z.object({
name: configNameSchema,
}),
)
.output(z.custom<ConfigType>())
.query(async ({ ctx, input }) => {
if (!configExists(input.name)) {
throw new TRPCError({
@@ -177,6 +189,7 @@ export const configRouter = createTRPCRouter({
}),
saveCustomization: adminProcedure
.input(boardCustomizationSchema.and(z.object({ name: configNameSchema })))
.output(z.void())
.mutation(async ({ input }) => {
const previousConfig = getConfig(input.name);
const newConfig = {