Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions template/nestJs/src/.generate/i18n.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type I18nTranslations = {
"NOT_EMPTY": string;
"IS_ARRAY": string;
"NOT_EMPTY_HUMAN": string;
"TYPE_ERROR": string;
};
};
/* prettier-ignore */
Expand Down
3 changes: 2 additions & 1 deletion template/nestJs/src/i18n/enUS/validation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"NOT_EMPTY": "{property} should not to be empty",
"IS_ARRAY": "{property} should to be array",
"NOT_EMPTY_HUMAN": "{name} should not to be empty"
"NOT_EMPTY_HUMAN": "{name} should not to be empty",
"TYPE_ERROR": "{property} should to be {type}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix the English validation copy.

"should to be" reads incorrectly in API errors. Please change it to "should be {type}" or "must be {type}".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@template/nestJs/src/i18n/enUS/validation.json` at line 5, Update the
validation message for the "TYPE_ERROR" key in validation.json to correct the
English; replace the current value "{property} should to be {type}" with a
grammatically correct phrase such as "{property} should be {type}" (or
"{property} must be {type}") so API errors read properly.

}
3 changes: 2 additions & 1 deletion template/nestJs/src/i18n/zhCN/validation.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"NOT_EMPTY": "{property} 不能为空",
"IS_ARRAY": "{property} 应该为数组",
"NOT_EMPTY_HUMAN": "{name} 不能为空"
"NOT_EMPTY_HUMAN": "{name} 不能为空",
"TYPE_ERROR": "{property} 应该为 {type}"
}
9 changes: 5 additions & 4 deletions template/nestJs/src/menu/dto/create-menu.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsNotEmpty } from 'class-validator';
import { IsNotEmpty, IsString } from 'class-validator';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -e
# Inspect ValidationPipe setup and whether missing properties are skipped globally.
rg -n -C3 'ValidationPipe|skipMissingProperties' --type ts

Repository: opentiny/tiny-pro

Length of output: 1019


🏁 Script executed:

#!/bin/bash
# Read the actual create-menu.dto.ts file to see the current state
cat -n template/nestJs/src/menu/dto/create-menu.dto.ts | head -60

Repository: opentiny/tiny-pro

Length of output: 1992


🌐 Web query:

nestjs-i18n I18nValidationPipe default skipMissingProperties behavior

💡 Result:

I18nValidationPipe does not change skipMissingProperties—it just extends Nest’s built-in ValidationPipe and accepts the same ValidationPipeOptions (minus exceptionFactory). (app.unpkg.com)

So the default behavior is the same as ValidationPipe / class-validator: missing (null/undefined) properties are not skipped unless you explicitly enable it, i.e. skipMissingProperties effectively defaults to false. (docs.nestjs.com)

To enable “skip missing properties” behavior:

app.useGlobalPipes(new I18nValidationPipe({ skipMissingProperties: true }));
``` ([docs.nestjs.com](https://docs.nestjs.com/techniques/validation?utm_source=openai))

Citations:

- 1: https://app.unpkg.com/nestjs-i18n%4010.4.9/files/dist/pipes/i18n-validation.pipe.d.ts
- 2: https://docs.nestjs.com/techniques/validation?utm_source=openai
- 3: https://docs.nestjs.com/techniques/validation?utm_source=openai

---



</details>

**`icon` is not actually optional without `@IsOptional()`.**

`required: false` only affects OpenAPI docs. Since `I18nValidationPipe` uses default NestJS behavior (`skipMissingProperties: false`), `@IsString()` will reject requests that omit `icon`. The field is marked optional in Swagger but required in both validation and TypeScript. Fix the inconsistency by adding `@IsOptional()`, making the property optional in the DTO signature, and keeping the Swagger metadata consistent.

<details>
<summary>Suggested fix</summary>

```diff
-import { IsNotEmpty, IsString } from 'class-validator';
+import { IsNotEmpty, IsOptional, IsString } from 'class-validator';

   `@ApiProperty`({
     description: '菜单图标',
     required: false,
   })
+  `@IsOptional`()
   `@IsString`({
-    message: i18nValidationMessage<I18nTranslations>('validation.TYPE_ERROR', {type: 'string'}),
+    message: i18nValidationMessage<I18nTranslations>('validation.TYPE_ERROR', { type: 'string' }),
   })
-  icon: string;
+  icon?: string;

Also applies to: 42-49

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@template/nestJs/src/menu/dto/create-menu.dto.ts` at line 1, The DTO marks the
icon field optional in Swagger but not in validation/TypeScript, so update the
CreateMenuDto (and the other DTO occurrences noted) by importing and adding the
`@IsOptional`() decorator before `@IsString`(), change the property signature to be
optional (icon?: string), and ensure IsOptional is added to the import list so
validation, TypeScript typing, and Swagger metadata are consistent.

import { i18nValidationMessage } from 'nestjs-i18n';
import { I18nTranslations } from '../../.generate/i18n.generated';
import { ApiProperty } from '@nestjs/swagger';
Expand Down Expand Up @@ -40,10 +40,11 @@ export class CreateMenuDto {
})
component: string;
@ApiProperty({
description: '菜单图标'
description: '菜单图标',
required: false,
})
@IsNotEmpty({
message: i18nValidationMessage<I18nTranslations>('validation.NOT_EMPTY'),
@IsString({
message: i18nValidationMessage<I18nTranslations>('validation.TYPE_ERROR', {type: 'string'}),
})
icon: string;
@ApiProperty({
Expand Down
Loading