ResourcefulObjectType
The ResourcefulObjectType class provides validation for complex nested objects with typed properties. It supports OpenAPI composition patterns and property validation.
For complete API reference, see ResourcefulObjectType.
Basic Usage
typescript
import { ResourcefulObjectType, ResourcefulStringType, ResourcefulNumberType } from '@nhtio/lucid-resourceful/definitions'
const addressType = ResourcefulObjectType({
properties: {
street: ResourcefulStringType({ minLength: 1, maxLength: 100 }),
city: ResourcefulStringType({ minLength: 1, maxLength: 50 }),
zipCode: ResourcefulStringType({ minLength: 5, maxLength: 10 })
},
required: ['street', 'city'],
additionalProperties: false
})Configuration
properties: object- Object property definitionsrequired?: string[]- Required property namesadditionalProperties?: boolean | ResourcefulDataType- Allow additional propertiesminProperties?: number- Minimum property countmaxProperties?: number- Maximum property count
Common Patterns
typescript
class User extends compose(BaseModel, withResourceful({ name: 'User' })) {
// Contact information
@resourcefulColumn.object({
type: ResourcefulObjectType({
properties: {
email: ResourcefulStringType({ minLength: 5, maxLength: 100 }),
phone: ResourcefulStringType({ minLength: 10, maxLength: 15 })
},
required: ['email'],
additionalProperties: false
}),
nullable: true
})
declare contactInfo: object | null
// Preferences object
@resourcefulColumn.object({
type: ResourcefulObjectType({
properties: {
theme: ResourcefulStringType({ enum: ['light', 'dark'] }),
notifications: ResourcefulBooleanType()
},
additionalProperties: true
}),
nullable: true
})
declare preferences: object | null
}Composition Patterns
Supports OpenAPI composition with oneOf, allOf, anyOf, and not:
typescript
const flexibleType = ResourcefulObjectType({
properties: {
data: {
oneOf: [
ResourcefulStringType({ minLength: 1, maxLength: 100 }),
ResourcefulNumberType({ minimum: 0, maximum: 1000, format: 'double' })
]
}
}
})Best Practices
- Define clear property structures
- Use required arrays for mandatory fields
- Consider additionalProperties carefully
- Validate nested object schemas thoroughly