diff --git a/backend/src/api.ts b/backend/src/api.ts index 3db0e61fcb7f99102a716a391bf47654fc0c0e00..5c5c0ab9c7d98a4507062651cea136e4a428de32 100644 --- a/backend/src/api.ts +++ b/backend/src/api.ts @@ -1,8 +1,14 @@ import { FastifyPluginCallback } from "fastify"; -import { Static, Type } from "@sinclair/typebox"; + +import { Static, Type, TSchema, TUnion, TNull } from "@sinclair/typebox"; + +function Nullable<T extends TSchema>(schema: T): TUnion<[T, TNull]> { + return { ...schema, nullable: true } as any; +} import { connection } from "./db"; +// NOTE: refer to https://cloud.google.com/apis/design/ // NOTE: see https://www.npmjs.com/package/fastify-plugin for TS plugin definition const IdInParamsSchema = Type.Object({ @@ -25,7 +31,7 @@ type ClueType = Static<typeof ClueSchema>; const ShotSchema = Type.Object({ id: Type.Readonly(Type.String({ format: "uuid" })), game_id: Type.Readonly(Type.String({ format: "uuid" })), - clue_id: Type.Optional(Type.Readonly(Type.String({ format: "uuid" }))), + clue_id: Nullable(Type.String({ format: "uuid" })), began_at: Type.String({ format: "date-time" }), ended_at: Type.String({ format: "date-time" }), typed: Type.String(), diff --git a/backend/src/index.ts b/backend/src/index.ts index 26f5d5a42f310b90e561b0afc2db75f75976da5a..1519cb6105c939f45f9d31968d456d28c5dfcd9a 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,7 +1,5 @@ import fastify from "fastify"; import fastifyCors from "fastify-cors"; -import { connection } from "./db"; -import { FromSchema } from "json-schema-to-ts"; import fastifySwagger from "fastify-swagger"; const server = fastify({