Conversation
WalkthroughThis PR introduces a new TYPE_ERROR translation message for type validation across English and Chinese localization files, updates the TypeScript type definition, and modifies the CreateMenuDto to validate the icon field as a string type using the new message. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@template/nestJs/src/i18n/enUS/validation.json`:
- 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.
In `@template/nestJs/src/menu/dto/create-menu.dto.ts`:
- 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.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 2888c4fd-0541-4663-a004-c4fb1ae20514
📒 Files selected for processing (4)
template/nestJs/src/.generate/i18n.generated.tstemplate/nestJs/src/i18n/enUS/validation.jsontemplate/nestJs/src/i18n/zhCN/validation.jsontemplate/nestJs/src/menu/dto/create-menu.dto.ts
| "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}" |
There was a problem hiding this comment.
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.
| @@ -1,4 +1,4 @@ | |||
| import { IsNotEmpty } from 'class-validator'; | |||
| import { IsNotEmpty, IsString } from 'class-validator'; | |||
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -e
# Inspect ValidationPipe setup and whether missing properties are skipped globally.
rg -n -C3 'ValidationPipe|skipMissingProperties' --type tsRepository: 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 -60Repository: 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.
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
Documentation
New Features