fix: jsonschema

This commit is contained in:
Innei
2022-06-04 21:29:13 +08:00
parent e8d1da4415
commit 5c60368816
4 changed files with 44 additions and 42 deletions

View File

@@ -186,6 +186,7 @@
"typescript": "4.7.3", "typescript": "4.7.3",
"ioredis": "5.0.6", "ioredis": "5.0.6",
"webpack": "5.72.1", "webpack": "5.72.1",
"fastify-cors": "npm:@fastify/cors@7.0.0" "fastify-cors": "npm:@fastify/cors@^7.0.0",
"fastify-formbody": "npm:@fastify/formbody@^6.0.0"
} }
} }

28
pnpm-lock.yaml generated
View File

@@ -4,7 +4,8 @@ overrides:
typescript: 4.7.3 typescript: 4.7.3
ioredis: 5.0.6 ioredis: 5.0.6
webpack: 5.72.1 webpack: 5.72.1
fastify-cors: npm:@fastify/cors@7.0.0 fastify-cors: npm:@fastify/cors@^7.0.0
fastify-formbody: npm:@fastify/formbody@^6.0.0
specifiers: specifiers:
'@algolia/client-search': '*' '@algolia/client-search': '*'
@@ -931,6 +932,12 @@ packages:
resolution: {integrity: sha512-wI3fpfDT0t7p8E6dA2eTECzzOd+bZsZCJ2Hcv+Onn2b7ZwK3RwD27uW2QDaMtQhAfWQQP+WNK7nKf0twLsBf9w==} resolution: {integrity: sha512-wI3fpfDT0t7p8E6dA2eTECzzOd+bZsZCJ2Hcv+Onn2b7ZwK3RwD27uW2QDaMtQhAfWQQP+WNK7nKf0twLsBf9w==}
dev: false dev: false
/@fastify/formbody/6.0.1:
resolution: {integrity: sha512-yIwCitoES4Sh0tPc6v+uHBqZEKw3CooSZ4kUvO9NC8Y7oRBCW+aC+pTgUZ8M3r2DOzRkNO+Pq0jMQkyL2k8jZQ==}
dependencies:
fastify-plugin: 3.0.1
dev: false
/@fastify/multipart/6.0.0: /@fastify/multipart/6.0.0:
resolution: {integrity: sha512-TwxPH9jE3bEaCdMD1Xqm2YS1aelgJxcNmA/uYAPCzqnVEylDiKCmxCstGulb1W5WdMoyqD5LBGm7AoqDwWTCWQ==} resolution: {integrity: sha512-TwxPH9jE3bEaCdMD1Xqm2YS1aelgJxcNmA/uYAPCzqnVEylDiKCmxCstGulb1W5WdMoyqD5LBGm7AoqDwWTCWQ==}
dependencies: dependencies:
@@ -1485,7 +1492,7 @@ packages:
'@nestjs/core': 8.4.6_vuwl3up5f332jd7oemx5cxyyz4 '@nestjs/core': 8.4.6_vuwl3up5f332jd7oemx5cxyyz4
fastify: 3.29.0 fastify: 3.29.0
fastify-cors: /@fastify/cors/7.0.0 fastify-cors: /@fastify/cors/7.0.0
fastify-formbody: 5.3.0 fastify-formbody: /@fastify/formbody/6.0.1
light-my-request: 5.0.0 light-my-request: 5.0.0
middie: 6.1.0 middie: 6.1.0
path-to-regexp: 3.2.0 path-to-regexp: 3.2.0
@@ -4102,19 +4109,6 @@ packages:
strnum: 1.0.5 strnum: 1.0.5
dev: false dev: false
/fastify-formbody/5.2.0:
resolution: {integrity: sha512-d8Y5hCL82akPyoFiXh2wYOm3es0pV9jqoPo3pO9OV2cNF0cQx39J5WAVXzCh4MSt9Z2qF4Fy5gHlvlyESwjtvg==}
dependencies:
fastify-plugin: 3.0.1
dev: false
/fastify-formbody/5.3.0:
resolution: {integrity: sha512-7cjFV2HE/doojyfTwCLToIFD6Hmbw2jVTbfqZ2lbUZznQWlSXu+MBQgqBU8T2nHcMfqSi9vx6PyX0LwTehuKkg==}
dependencies:
fastify-formbody-deprecated: /fastify-formbody/5.2.0
process-warning: 1.0.0
dev: false
/fastify-plugin/3.0.1: /fastify-plugin/3.0.1:
resolution: {integrity: sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==} resolution: {integrity: sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==}
dev: false dev: false
@@ -4309,7 +4303,7 @@ packages:
dev: false dev: false
/fresh/0.5.2: /fresh/0.5.2:
resolution: {integrity: sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==} resolution: {integrity: sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=}
engines: {node: '>= 0.6'} engines: {node: '>= 0.6'}
dev: false dev: false
@@ -5073,7 +5067,7 @@ packages:
dev: false dev: false
/javascript-natural-sort/0.7.1: /javascript-natural-sort/0.7.1:
resolution: {integrity: sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw==} resolution: {integrity: sha1-+eIwPUUH9tdDVac2ZNFED7Wg71k=}
dev: true dev: true
/jest-changed-files/28.0.2: /jest-changed-files/28.0.2:

View File

@@ -24,6 +24,7 @@ import {
JSONSchemaPasswordField, JSONSchemaPasswordField,
JSONSchemaPlainField, JSONSchemaPlainField,
JSONSchemaToggleField, JSONSchemaToggleField,
halfFieldOption,
} from './configs.jsonschema.decorator' } from './configs.jsonschema.decorator'
@JSONSchema({ title: 'SEO 优化' }) @JSONSchema({ title: 'SEO 优化' })
@@ -77,9 +78,7 @@ class MailOption {
@IsInt() @IsInt()
@Transform(({ value: val }) => parseInt(val)) @Transform(({ value: val }) => parseInt(val))
@IsOptional() @IsOptional()
@JSONSchemaNumberField('发件邮箱端口', { @JSONSchemaNumberField('发件邮箱端口', halfFieldOption)
'ui:options': { halfGrid: true },
})
port: number port: number
@IsUrl({ require_protocol: false }) @IsUrl({ require_protocol: false })
@IsOptional() @IsOptional()
@@ -100,9 +99,7 @@ export class MailOptionsDto {
@IsNotEmpty() @IsNotEmpty()
@IsOptional() @IsOptional()
@Exclude({ toPlainOnly: true }) @Exclude({ toPlainOnly: true })
@JSONSchemaPasswordField('发件邮箱密码', { @JSONSchemaPasswordField('发件邮箱密码', halfFieldOption)
'ui:options': { halfGrid: true },
})
pass: string pass: string
@ValidateNested() @ValidateNested()
@@ -147,23 +144,23 @@ export class BackupOptionsDto {
@IsString() @IsString()
@IsOptional() @IsOptional()
@JSONSchemaPlainField('SecretId') @JSONSchemaHalfGirdPlainField('SecretId')
secretId?: string secretId?: string
@IsOptional() @IsOptional()
@IsString() @IsString()
@Exclude({ toPlainOnly: true }) @Exclude({ toPlainOnly: true })
@JSONSchemaPasswordField('SecretKey') @JSONSchemaPasswordField('SecretKey', halfFieldOption)
secretKey?: string secretKey?: string
@IsOptional() @IsOptional()
@IsString() @IsString()
@JSONSchemaPlainField('Bucket') @JSONSchemaHalfGirdPlainField('Bucket')
bucket?: string bucket?: string
@IsString() @IsString()
@IsOptional() @IsOptional()
@JSONSchemaPlainField('地域 Region') @JSONSchemaHalfGirdPlainField('地域 Region')
region: string region: string
} }
@@ -208,28 +205,31 @@ export class AlgoliaSearchOptionsDto {
@JSONSchema({ title: '后台附加设置' }) @JSONSchema({ title: '后台附加设置' })
export class AdminExtraDto { export class AdminExtraDto {
@IsBoolean()
@IsOptional()
@JSONSchemaToggleField('开启后台管理反代', {
description: '是否可以通过 API 访问后台',
})
/**
* 是否开启后台反代访问
*/
enableAdminProxy?: boolean
@IsString() @IsString()
@IsOptional() @IsOptional()
@JSONSchemaPlainField('登录页面背景') @JSONSchemaPlainField('登录页面背景')
background?: string background?: string
@IsString()
@IsOptional()
@Exclude({ toPlainOnly: true })
@JSONSchemaPasswordField('高德查询 API Key', { description: '日记地点定位' })
gaodemapKey?: string
@IsString() @IsString()
@IsOptional() @IsOptional()
@JSONSchemaPlainField('中后台标题') @JSONSchemaPlainField('中后台标题')
title?: string title?: string
@IsBoolean() @IsString()
@IsOptional() @IsOptional()
@JSONSchemaToggleField('开启后台管理反代') @Exclude({ toPlainOnly: true })
/** @JSONSchemaPasswordField('高德查询 API Key', { description: '日记地点定位' })
* 是否开启后台反代访问 gaodemapKey?: string
*/
enableAdminProxy?: boolean
} }
@JSONSchema({ title: '终端设定' }) @JSONSchema({ title: '终端设定' })
@@ -252,7 +252,11 @@ export class TerminalOptionsDto {
@IsOptional() @IsOptional()
@IsString() @IsString()
@JSONSchemaPlainField('前置脚本') @JSONSchemaPlainField('前置脚本', {
'ui:option': {
type: 'textarea',
},
})
script?: string script?: string
} }

View File

@@ -1,6 +1,10 @@
import { JSONSchema } from 'class-validator-jsonschema' import { JSONSchema } from 'class-validator-jsonschema'
import { DecoratorSchema } from 'class-validator-jsonschema/build/decorators' import { DecoratorSchema } from 'class-validator-jsonschema/build/decorators'
export const halfFieldOption = {
'ui:options': { halfGrid: true },
}
export const JSONSchemaPasswordField = ( export const JSONSchemaPasswordField = (
title: string, title: string,
schema?: DecoratorSchema, schema?: DecoratorSchema,
@@ -20,8 +24,7 @@ export const JSONSchemaPlainField = (title: string, schema?: DecoratorSchema) =>
export const JSONSchemaHalfGirdPlainField: typeof JSONSchemaPlainField = ( export const JSONSchemaHalfGirdPlainField: typeof JSONSchemaPlainField = (
...rest ...rest
) => ) => JSONSchemaPlainField.call(null, ...rest, halfFieldOption)
JSONSchemaPlainField.call(null, ...rest, { 'ui:options': { halfGrid: true } })
export const JSONSchemaArrayField = (title: string, schema?: DecoratorSchema) => export const JSONSchemaArrayField = (title: string, schema?: DecoratorSchema) =>
JSONSchema({ JSONSchema({