You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The response structure is designed to be easily consumable by front-end applications. It presents validation errors in a clear, structured format, grouping errors by field and providing detailed messages for each validation rule that failed.
53
+
54
+
```json
55
+
{
56
+
"errors": {
57
+
"username": [
58
+
{
59
+
"message": "This field must be a string and is required.",
60
+
"key": "username",
61
+
"from": "body"
62
+
},
63
+
{
64
+
"message": "String must be at least 3 characters long",
65
+
"key": "username",
66
+
"from": "body"
67
+
},
68
+
{
69
+
"message": "String must be at most 255 characters long",
70
+
"key": "username",
71
+
"from": "body"
72
+
}
73
+
],
74
+
"email": [
75
+
{
76
+
"message": "This field must be a string and is required.",
77
+
"key": "email",
78
+
"from": "body"
79
+
},
80
+
{
81
+
"message": "Invalid email address",
82
+
"key": "email",
83
+
"from": "body"
84
+
}
85
+
]
86
+
}
87
+
}
88
+
```
89
+
</details>
90
+
49
91
## Available Validators
50
92
51
93
### String Validation
@@ -69,6 +111,8 @@ inp().string()
69
111
.datetime() // ISO datetime format
70
112
.base64() // Base64 string
71
113
.optional() // Make field optional
114
+
.enum(["admin", "user"]) // Must be one of values
115
+
.toNumber() // Convert to number (useful for query params)
72
116
```
73
117
74
118
### Number Validation
@@ -84,6 +128,7 @@ inp().number()
84
128
.finite() // Must be finite
85
129
.safe() // Safe integer
86
130
.optional() // Make field optional
131
+
.enum([1, 2, 3, 5]) // Must be one of values
87
132
```
88
133
89
134
### Array Validation
@@ -137,6 +182,7 @@ inp().date()
137
182
.weekday([1,2,3,4,5]) // Valid weekdays
138
183
.age(18) // Minimum age
139
184
.optional() // Make field optional
185
+
.enum([newDate("2024-01-01"), newDate("2024-12-31")]) // Must be one of dates
When validating numbers in query parameters, you can use the `toNumber()` method to convert the string to a number. This is useful for cases where you expect a number but receive it as a string in the query.
263
+
264
+
```ts
265
+
inp()
266
+
.string()
267
+
.toNumber() // Convert string to number but float is allowed
0 commit comments