🔍 Attribute Schema Blocks
Attribute schema blocks provide JSON Schema definitions for attribute group data validation in Nodeblocks applications. These schemas ensure data integrity and provide clear contracts for attribute-related API endpoints.
🎯 Overview
Attribute schema blocks are designed to:
- Validate attribute group data before processing
- Support key-value pair structures for flexible data
- Ensure data consistency across attribute operations
- Enable attribute search and filtering capabilities
- Support pagination for large attribute collections
📋 Attribute Schema Types
Base Attribute Schemas
Core attribute set structures used as foundations for other schemas.
Attribute Creation Schemas
Schemas for attribute set creation with required field validation.
Attribute Update Schemas
Schemas for attribute set modifications with optional field validation.
Attribute Query Schemas
Schemas for attribute filtering and pagination parameters.
🔧 Available Attribute Schemas
attributesSchema
(base)
Base attributes schema defining the structure for attribute set data.
Purpose: Defines the structure for attribute groups with key-value pairs
Schema Details:
- Type:
object
- Required Fields: None (base schema)
- Additional Properties:
false
(strict validation) - Properties:
name?: string
- Attribute group nameitems?: Array<{key: string, value: string}>
- Key-value pairs (min 1 item)
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { attributesSchema } = schemas;
const validate = ajv.compile(attributesSchema as SchemaDefinition);
const isValid = validate({
name: 'Product Attributes',
items: [{ key: 'color', value: 'red' }, { key: 'size', value: 'large' }]
});
createAttributesSchema
Attributes creation schema with required fields for new attribute sets.
Purpose: Validates attribute group data during creation
Schema Details:
- Type:
object
- Required Fields:
name
,items
- Additional Properties:
false
(strict validation) - Content-Type:
application/json
- Request Body:
required
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { createAttributesSchema } = schemas;
const attributesSchema = createAttributesSchema({});
const validate = ajv.compile(attributesSchema.schemas as SchemaDefinition);
const isValid = validate({
name: 'Product Attributes',
items: [{ key: 'color', value: 'red' }, { key: 'size', value: 'large' }]
});
updateAttributesSchema
Attributes update schema for modifying attribute set names.
Purpose: Validates partial attribute group name updates
Schema Details:
- Type:
object
- Required Fields: None
- Additional Properties:
false
(strict validation) - Content-Type:
application/json
- Parameters:
attributeId
(path parameter) - Properties:
name?: string
- Updated attribute set name
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { updateAttributesSchema } = schemas;
const attributesSchema = updateAttributesSchema({});
const validate = ajv.compile(attributesSchema.schemas as SchemaDefinition);
const isValid = validate({ name: 'Updated Product Attributes' });
getAttributeSchema
Attribute retrieval schema for getting single attribute sets.
Purpose: Validates requests for retrieving a specific attribute group
Schema Details:
- Parameters:
attributeId
(path parameter) - Purpose: Validates requests for retrieving specific attribute sets
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { getAttributeSchema } = schemas;
const attributeSchema = getAttributeSchema({});
const validate = ajv.compile(attributeSchema.schemas as SchemaDefinition);
const isValid = validate({
attributeId: 'attr123'
});
deleteAttributeSchema
Attribute deletion schema for removing attribute sets.
Purpose: Validates requests for deleting a specific attribute group
Schema Details:
- Parameters:
attributeId
(path parameter) - Purpose: Validates requests for deleting specific attribute sets
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { deleteAttributeSchema } = schemas;
const attributeSchema = deleteAttributeSchema({});
const validate = ajv.compile(attributeSchema.schemas as SchemaDefinition);
const isValid = validate({
attributeId: 'attr123'
});
findAttributesSchema
Attributes search schema for finding attribute sets with filtering and pagination.
Purpose: Validates requests for searching and paginating attribute groups
Schema Details:
- Query Parameters:
name?: string
(optional filter by name)page?: number
(pagination, min 1, max 1000)limit?: number
(pagination, min 1, max 50)
- Purpose: Validates requests for searching and paginating attribute sets
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { findAttributesSchema } = schemas;
const attributesSchema = findAttributesSchema({});
const validate = ajv.compile(attributesSchema.schemas as SchemaDefinition);
const isValid = validate({
name: 'Product',
page: 1,
limit: 10
});
🔗 Related Documentation
- Attribute Domain Overview - Attribute domain overview