Create comprehensive request validation schemas with JSON Schema, Zod, or Joi for API endpoints.
You are a backend developer specializing in API input validation and data integrity.
## CONTEXT
I need to create validation schemas for my API endpoints.
**Requirements:**
- Framework: {{FRAMEWORK}}
- Validation Library: {{VALIDATION_LIB}}
- Endpoints: {{ENDPOINTS}}
- Data Types: {{DATA_TYPES}}
## TASK
Create comprehensive validation schemas:
### 1. JSON SCHEMA
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["field1", "field2"],
"properties": {
"field1": {
"type": "string",
"minLength": 1,
"maxLength": 100,
"pattern": "^[a-zA-Z]+$"
},
"email": {
"type": "string",
"format": "email"
}
},
"additionalProperties": false
}
```
### 2. ZOD SCHEMA (TypeScript)
```typescript
const createUserSchema = z.object({
email: z.string().email(),
name: z.string().min(1).max(100),
age: z.number().int().min(0).max(150).optional(),
});
```
### 3. JOI SCHEMA (Node.js)
```javascript
const schema = Joi.object({
email: Joi.string().email().required(),
name: Joi.string().min(1).max(100).required(),
});
```
### 4. COMMON VALIDATIONS
- Email, URL, UUID formats
- Date/time validation
- Enum values
- Nested objects
- Arrays with constraints
- Conditional validation
- Custom validators
### 5. ERROR MESSAGES
Customized, user-friendly error messages.
### 6. MIDDLEWARE INTEGRATION
Code for integrating validation in your framework.Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[{FRAMEWORK][{VALIDATION_LIB][{ENDPOINTS][{DATA_TYPES]{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["field1", "field2"],
"properties": {
"field1": {
"type": "string",
"minLength": 1,
"maxLength": 100,
"pattern": "^[a-zA-Z]+$"
}{
"type": "string",
"format": "email"
}{
email: z.string().email(),
name: z.string().min(1).max(100),
age: z.number().int().min(0).max(150).optional(),
}{
email: Joi.string().email().required(),
name: Joi.string().min(1).max(100).required(),
}