🔍 Category Schema Blocks
Category schema blocks provide JSON Schema definitions for category data validation in Nodeblocks applications. These schemas ensure data integrity and provide clear contracts for category-related API endpoints.
🎯 Overview
Category schema blocks are designed to:
- Validate category data before processing
- Support hierarchical structures with parent-child relationships
- Ensure data consistency across category operations
- Enable category search and filtering capabilities
- Support pagination for large category collections
📋 Category Schema Types
Base Category Schemas
Core category structures used as foundations for other schemas.
Category Creation Schemas
Schemas for category creation with required field validation.
Category Update Schemas
Schemas for category modifications with optional field validation.
Category Query Schemas
Schemas for category filtering and pagination parameters.
🔧 Available Category Schemas
categorySchema
Base category schema with core category fields.
Purpose: Defines basic category structure for reuse
Schema Details:
- Type:
object
- Required Fields: None
- Additional Properties:
false
(strict validation) - Properties:
name?: string
- Category namedescription?: string
- Category descriptionparent?: string
- Parent category IDstatus?: string
- Category status
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { categorySchema } = schemas;
const categorySchema = categorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({
name: 'Electronics',
description: 'Electronic devices and accessories',
status: 'active'
});
createCategorySchema
Category creation schema with required fields for new categories.
Purpose: Validates category data during creation
Schema Details:
- Type:
object
- Required Fields:
name
,description
,status
- Additional Properties:
false
(strict validation) - Content-Type:
application/json
- Request Body:
required
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { createCategorySchema } = schemas;
const categorySchema = createCategorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({
name: 'Electronics',
description: 'Electronic devices and accessories',
status: 'active'
});
updateCategorySchema
Category update schema with optional fields for category modifications.
Purpose: Validates partial category data updates
Schema Details:
- Type:
object
- Required Fields: None
- Additional Properties:
false
(strict validation) - Content-Type:
application/json
- Parameters:
categoryId
(path parameter) - Properties:
name?: string
- Updated category namedescription?: string
- Updated category descriptionparent?: string
- Updated parent category ID
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { updateCategorySchema } = schemas;
const categorySchema = updateCategorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({ description: 'Updated description' });
getCategorySchema
Category retrieval schema for getting single categories.
Purpose: Validates requests for retrieving specific categories
Schema Details:
- Parameters:
categoryId
(path parameter) - Purpose: Validates requests for retrieving specific categories
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { getCategorySchema } = schemas;
const categorySchema = getCategorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({
categoryId: 'cat123'
});
deleteCategorySchema
Category deletion schema for removing categories.
Purpose: Validates requests for deleting specific categories
Schema Details:
- Parameters:
categoryId
(path parameter) - Purpose: Validates requests for deleting specific categories
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { deleteCategorySchema } = schemas;
const categorySchema = deleteCategorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({
categoryId: 'cat123'
});
enableCategorySchema
Category enable schema for activating categories.
Purpose: Validates requests for enabling specific categories
Schema Details:
- Parameters:
categoryId
(path parameter) - Purpose: Validates requests for enabling specific categories
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { enableCategorySchema } = schemas;
const categorySchema = enableCategorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({
categoryId: 'cat123'
});
disableCategorySchema
Category disable schema for deactivating categories.
Purpose: Validates requests for disabling specific categories
Schema Details:
- Parameters:
categoryId
(path parameter) - Purpose: Validates requests for disabling specific categories
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { disableCategorySchema } = schemas;
const categorySchema = disableCategorySchema({});
const validate = ajv.compile(categorySchema.schemas as SchemaDefinition);
const isValid = validate({
categoryId: 'cat123'
});
findCategoriesSchema
Categories search schema for finding categories with filtering and pagination.
Purpose: Validates requests for searching and paginating categories
Schema Details:
- Query Parameters:
description?: string
(optional filter by description)name?: string
(optional filter by name)parent?: string
(optional filter by parent category)status?: string
(optional filter by status)page?: number
(pagination)limit?: number
(pagination)
- Purpose: Validates requests for searching and paginating categories
Usage:
import { schemas } from '@nodeblocks/backend-sdk';
const { findCategoriesSchema } = schemas;
const categoriesSchema = findCategoriesSchema({});
const validate = ajv.compile(categoriesSchema.schemas as SchemaDefinition);
const isValid = validate({
name: 'Electronics',
status: 'active',
page: 1,
limit: 10
});
🔗 Related Documentation
- Category Domain Overview - Category domain overview