From f6bc99b964f474dc6c8b3317da2bda9807a58ca5 Mon Sep 17 00:00:00 2001 From: x032205 Date: Fri, 9 May 2025 13:40:15 -0400 Subject: [PATCH] support openapi titles for zod description --- backend/package-lock.json | 11 ++++++----- backend/package.json | 2 +- backend/src/server/plugins/fastify-zod.ts | 19 +++++++++++++++++-- docs/mint.json | 2 +- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 4e0d27ada..0bc3aadd1 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -122,7 +122,7 @@ "tweetnacl-util": "^0.15.1", "uuid": "^9.0.1", "zod": "^3.22.4", - "zod-to-json-schema": "^3.22.4" + "zod-to-json-schema": "^3.24.5" }, "bin": { "backend": "dist/main.js" @@ -27442,11 +27442,12 @@ } }, "node_modules/zod-to-json-schema": { - "version": "3.22.4", - "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.22.4.tgz", - "integrity": "sha512-2Ed5dJ+n/O3cU383xSY28cuVi0BCQhF8nYqWU5paEpl7fVdqdAmiLdqLyfblbNdfOFwFfi/mqU4O1pwc60iBhQ==", + "version": "3.24.5", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.24.5.tgz", + "integrity": "sha512-/AuWwMP+YqiPbsJx5D6TfgRTc4kTLjsh5SOcd4bLsfUg2RcEXrFMJl1DGgdHy2aCfsIA/cr/1JM0xcB2GZji8g==", + "license": "ISC", "peerDependencies": { - "zod": "^3.22.4" + "zod": "^3.24.1" } } } diff --git a/backend/package.json b/backend/package.json index 1735fcd18..a8ab76cf8 100644 --- a/backend/package.json +++ b/backend/package.json @@ -241,6 +241,6 @@ "tweetnacl-util": "^0.15.1", "uuid": "^9.0.1", "zod": "^3.22.4", - "zod-to-json-schema": "^3.22.4" + "zod-to-json-schema": "^3.24.5" } } diff --git a/backend/src/server/plugins/fastify-zod.ts b/backend/src/server/plugins/fastify-zod.ts index 4e898a9b5..95fb29722 100644 --- a/backend/src/server/plugins/fastify-zod.ts +++ b/backend/src/server/plugins/fastify-zod.ts @@ -5,7 +5,7 @@ import type { FastifySchema, FastifySchemaCompiler, FastifyTypeProvider } from "fastify"; import type { FastifySerializerCompiler } from "fastify/types/schema"; import type { z, ZodAny, ZodTypeAny } from "zod"; -import { zodToJsonSchema } from "zod-to-json-schema"; +import { PostProcessCallback, zodToJsonSchema } from "zod-to-json-schema"; // eslint-disable-next-line @typescript-eslint/no-explicit-any type FreeformRecord = Record; @@ -28,9 +28,24 @@ interface Schema extends FastifySchema { hide?: boolean; } +const jsonDescription: PostProcessCallback = (jsonSchema, def) => { + if (def.description) { + try { + return { + ...jsonSchema, + description: undefined, + ...JSON.parse(def.description) + }; + } catch {} + } + + return jsonSchema; +}; + const zodToJsonSchemaOptions = { target: "openApi3", - $refStrategy: "none" + $refStrategy: "none", + postProcess: jsonDescription } as const; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/docs/mint.json b/docs/mint.json index ecfe798e2..9e677843a 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -327,7 +327,7 @@ } ] }, - "documentation/platform/token", + "documentation/platform/token", "documentation/platform/mfa", "documentation/platform/github-org-sync" ]