fix(api): 默认关闭接口文档

This commit is contained in:
2026-05-12 00:52:43 +08:00
parent 11cf298332
commit fad890abe1
2 changed files with 19 additions and 14 deletions
+2
View File
@@ -4,11 +4,13 @@ import { z } from 'zod'
export const env = createEnv({
server: {
DATABASE_URL: z.url({ protocol: /^mysql$/ }),
ENABLE_API_DOCS: z.stringbool().default(false),
LOG_DB: z.stringbool().default(false),
LOG_FORMAT: z.enum(['pretty', 'json']).optional(),
LOG_LEVEL: z.enum(['trace', 'debug', 'info', 'warning', 'error', 'fatal']).default('info'),
SOH_PREDICTION_API_BASE_URL: z.url({ protocol: /^https?$/ }),
SOH_PREDICTION_CACHE_TTL_SECONDS: z.coerce.number().int().positive().default(86_400),
SOH_PREDICTION_NEGATIVE_CACHE_TTL_SECONDS: z.coerce.number().int().positive().default(300),
SOH_PREDICTION_TIMEOUT_MS: z.coerce.number().int().positive().default(10_000),
},
clientPrefix: 'VITE_',
+17 -14
View File
@@ -4,24 +4,27 @@ import { onError } from '@orpc/server'
import { ZodToJsonSchemaConverter } from '@orpc/zod/zod4'
import { createFileRoute } from '@tanstack/react-router'
import { name, version } from '#package'
import { env } from '@/env'
import { handleValidationError, logError } from '@/server/api/interceptors'
import { router } from '@/server/api/routers'
const handler = new OpenAPIHandler(router, {
plugins: [
new OpenAPIReferencePlugin({
docsProvider: 'scalar',
schemaConverters: [new ZodToJsonSchemaConverter()],
specGenerateOptions: {
info: {
title: name,
version,
},
},
docsPath: '/docs',
specPath: '/spec.json',
}),
],
plugins: env.ENABLE_API_DOCS
? [
new OpenAPIReferencePlugin({
docsProvider: 'scalar',
schemaConverters: [new ZodToJsonSchemaConverter()],
specGenerateOptions: {
info: {
title: name,
version,
},
},
docsPath: '/docs',
specPath: '/spec.json',
}),
]
: [],
interceptors: [onError(logError)],
clientInterceptors: [onError(handleValidationError)],
})