From cb81de0a0471ed05d44e20e41c00f6a93f54ac96 Mon Sep 17 00:00:00 2001 From: Camillo Bucciarelli Date: Thu, 2 May 2024 14:55:26 +0200 Subject: [PATCH] BO40 --- .../src/api/http/shared/shared.schema.ts | 27 +++++++++++++++++++ functions/src/api/http/shared/shared.type.ts | 16 +++++++++++ 2 files changed, 43 insertions(+) create mode 100644 functions/src/api/http/shared/shared.schema.ts create mode 100644 functions/src/api/http/shared/shared.type.ts diff --git a/functions/src/api/http/shared/shared.schema.ts b/functions/src/api/http/shared/shared.schema.ts new file mode 100644 index 0000000..27fdec8 --- /dev/null +++ b/functions/src/api/http/shared/shared.schema.ts @@ -0,0 +1,27 @@ +import { z } from "zod"; +import { buildJsonSchemas } from "fastify-zod"; + +const idParamSchema = z.object({ + id: z.string(), +}); + +const genericResponse = z.object({ + message: z.string(), +}); + +const errorResponse = z.object({ + statusCode: z.number(), + code: z.string().optional(), + error: z.string(), + message: z.string(), +}); + +export const { schemas: sharedSchemas, $ref: $sharedSchemaRef } = + buildJsonSchemas( + { + idParamSchema, + genericResponse, + errorResponse, + }, + { $id: "SharedSchema" }, + ); diff --git a/functions/src/api/http/shared/shared.type.ts b/functions/src/api/http/shared/shared.type.ts new file mode 100644 index 0000000..36a8a8b --- /dev/null +++ b/functions/src/api/http/shared/shared.type.ts @@ -0,0 +1,16 @@ +type IdPathParam = { + id: string; +}; + +type GenericResponse = { + message: string; +}; + +type ErrorResponse = { + statusCode: number; + code?: string; + error: string; + message: string; +}; + +export { IdPathParam, GenericResponse, ErrorResponse };