我想在另一种模式中使用一种模式,而无需手动输入字段。
我可以像这样对数组执行此操作:
import schemaAccountInfo from './schemaAccountInfo';
const schemaAccount = {
type: 'array',
items: schemaAccountInfo,
}
似乎无法想象它只是一个物体:
import schemaAccountInfo from './schemaAccountInfo';
const schemaAccount = {
type: 'object',
properties: {
id: { type: 'string' },
active: { type: 'boolean' },
accountInfo: {
type: 'object',
properties: schemaAccountInfo, // problem here
},
},
required: [
'id',
],
additionalProperties: false,
};
您的数组版本还应该使用
$ref
语法。
import schemaAccountInfo from './schemaAccountInfo';
const schemaAccount = {
type: 'array',
items:
$ref: schemaAccountInfo,
}
import schemaAccountInfo from './schemaAccountInfo';
const schemaAccount = {
type: 'object',
properties: {
id: { type: 'string' },
active: { type: 'boolean' },
accountInfo: {
$ref: schemaAccountInfo, // problem here
},
},
required: [
'id',
],
additionalProperties: false,
};