我希望categoryEncoding的键等于一对一地到类别的id字段。我的意思是categoryEncoding应该同时具有每个类别的ID。
查看我的架构,如下所示:
export const categorySchema = Joi.object().keys({
id: Joi.string().required(),
label: i18nSchema.required(),
description: i18nSchema
});
const observedPropertySchema = Joi.object().keys({
label: i18nSchema.required(),
id: Joi.string(),
description: i18nSchema,
categories: Joi.array().items(categorySchema)
});
const parameterSchema = Joi.object().keys({
type: Joi.string().required().equal('Parameter'),
id: Joi.string(),
label: i18nSchema,
description: i18nSchema,
observedProperty: observedPropertySchema.required(),
categoryEncoding: Joi.any() // ???
}).with('observedProperty.categories', 'categoryEncoding');
和我的数据:
const object = {
parameter: {
//...
observedProperty: {
//...
categories: [
{
id: 'http://example.com/land_cover/categories/1',
label: {
tr: 'Category 1'
}
},
{
id: 'http://example.com/land_cover/categories/2',
label: {
tr: 'Category 2'
}
}
],
},
categoryEncoding: {
'http://example.com/land_cover/categories/1': 1,
'http://example.com/land_cover/categories/2': [2,3]
}
}
};
谢谢。