🔍 属性スキーマ
属性スキーマは、Nodeblocksアプリケーションで属性グループデータのバリデーションを行うためのJSON Schema定義を提供します。これらのスキーマはデータの整合性を確保し、属性関連のAPIエンドポイントに対する明確な契約を提供します。
🎯 概要
属性スキーマは以下の目的で設計されています:
- 属性グループデータのバリデーション - 処理前の検証
- キー・バリューペア構造のサポート - 柔軟なデータ構造
- データの一貫性の確保 - 属性操作全体での整合性
- 属性検索とフィルタリング機能の有効化
- ページネーションのサポート - 大規模な属性コレクションに対応
📋 属性スキーマタイプ
基本属性スキーマ
他のスキーマの基盤として使用されるコア属性グループ構造。
属性作成スキーマ
必須フィールドのバリデーションを含む属性グループ作成用スキーマ。
属性更新スキーマ
オプションフィールドのバリデーションを含む属性グループ変更用スキーマ。
属性クエリスキーマ
属性のフィルタリングとページネーションパラメータ用スキーマ。
🔧 利用可能な属性スキーマ
attributesSchema (base)
属性グループデータの構造を定義する基本属性スキーマ。
目的: キー・バリューペアを持つ属性グループの構造を定義
スキーマ詳細:
- Type:
object - 必須フィールド: なし(基本スキーマ)
- Additional Properties:
false(厳密なバリデーション) - Properties:
name?: string- 属性グループ名items?: Array<{key: string, value: string}>- キー・バリューペア(最小1項目)
使用例:
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
新しい属性グループ用の必須フィールドを含む属性作成スキーマ。
目的: 作成時の属性グループデータをバリデーション
スキーマ詳細:
- Type:
object - 必須フィールド:
name、items - Additional Properties:
false(厳密なバリデーション) - Content-Type:
application/json - Request Body:
required
使用例:
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
属性グループ名を変更するための属性更新スキーマ。
目的: 部分的な属性グループ名の更新をバリデーション
スキーマ詳細:
- Type:
object - 必須フィールド: なし
- Additional Properties:
false(厳密なバリデーション) - Content-Type:
application/json - パラメータ:
attributeId(パスパラメータ) - Properties:
name?: string- 更新された属性グループ名
使用例:
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
単一の属性グループを取得するための属性取得スキーマ。
目的: 特定の属性グループを取得するリクエストをバリデーション
スキーマ詳細:
- パラメータ:
attributeId(パスパラメータ)
使用例:
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
属性グループを削除するための属性削除スキーマ。
目的: 特定の属性グループを削除するリクエストをバリデーション
スキーマ詳細:
- パラメータ:
attributeId(パスパラメータ)
使用例:
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
フィルタリングとページネーションを使用して属性グループを検索するための属性検索スキーマ。
目的: 属性グループの検索とページネーションを行うリクエストをバリデーション
スキーマ詳細:
- クエリパラメータ:
name?: string(名前によるオプションフィルタ)page?: number(ページネーション、最小1、最大1000)limit?: number(ページネーション、最小1、最大50)
使用例:
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
});
🔗 関連ドキュメント
- 属性ドメイン概要 - 属性ドメインの概要