JSON模式验证-从If,Then,Else语句中访问不同的属性



我希望你们能帮助我了解如何从负载的不同部分访问If语句中的多个属性。我有一个下面的例子。我遇到的问题是,我需要then和else语句来处理数组中每个项的内容。当前只有当数组中只有一个项时,它才起作用。

架构:

{
"if": {
"allOf": [
{
"properties": {
"report_body": {
"properties": {
"afs_employee_director_rep": {
"items": {
"properties": {
"afs_emp_rep_Capacity": {
"contains": {
"const": "Current director of licensee"
}
}
},
"required": [
"afs_emp_rep_Capacity"
]
}
}
}
}
}
},
{
"properties": {
"report_body": {
"properties": {
"licensees_schemes_rep_involved": {
"properties": {
"report_submit_licensee": {
"const": "Yes"
}
},
"required": [
"report_submit_licensee"
]
}
}
}
}
}
]
},
"then": {
"properties": {
"report_body": {
"properties": {
"afs_employee_director_rep": {
"items": {
"required": [
"afs_emp_rep_verify"
]
}
}
}
}
}
},
"else": {
"not": {
"properties": {
"report_body": {
"properties": {
"afs_employee_director_rep": {
"items": {
"required": [
"afs_emp_rep_verify"
]
}
}
}
}
}
}
}
}

如预期,验证失败:

{
"report_body": {
"licensees_schemes_rep_involved": {
"report_submit_licensee": "Yes",
"report_licensee_types": "AFS licence",
"report_responsible_entity": "No",
"report_cciv_corporate_dir": "No",
"report_committed_entity": "Representative(s)",
"representative_ReportableSituationRelate": "Employee/director of licensee or related body corporate (who is not a financial adviser)"
},
"other_afs_licensees": [
"234563"
],
"afs_employee_director_rep": [
{
"afs_emp_rep_Capacity": [
"Current director of licensee"
],
"afs_emp_rep_work_monitored": "No",
"afs_emp_rep_verify_1": "No"
}
]
}
}

这不是:

{
"report_body": {
"licensees_schemes_rep_involved": {
"report_submit_licensee": "Yes",
"report_licensee_types": "AFS licence",
"report_responsible_entity": "No",
"report_cciv_corporate_dir": "No",
"report_committed_entity": "Representative(s)",
"representative_ReportableSituationRelate": "Employee/director of licensee or related body corporate (who is not a financial adviser)"
},
"other_afs_licensees": [
"234563"
],
"afs_employee_director_rep": [
{
"afs_emp_rep_Capacity": [
"Current director of licensee"
],
"afs_emp_rep_work_monitored": "No",
"afs_emp_rep_verify_1": "No"
},
{
"afs_emp_rep_Capacity": [
"Former director of licensee"
],
"afs_emp_rep_work_monitored": "No",
"afs_emp_rep_verify_1": "No"
}
]
}
}

感谢

我会使用嵌套的oneOf重写它:每个afs_employee_director_rep条目都需要不包含"持牌人的现任董事";字符串,或者如果它包含它,它还需要afs_emp_rep_verify密钥。

{
"allOf":[
{
"properties":{
"report_body":{
"properties":{
"afs_employee_director_rep":{
"items":{
"oneOf":[
{
"properties":{
"afs_emp_rep_Capacity":{
"contains":{
"const": "Current director of licensee"
}
}
},
"required":[
"afs_emp_rep_Capacity",
"afs_emp_rep_verify"
]
},
{
"properties":{
"afs_emp_rep_Capacity":{
"not":{
"contains":{
"const":"Current director of licensee"
}
}
}
},
"required":[
"afs_emp_rep_Capacity"
]
}
]
}
}
}
}
}
},
{
"properties":{
"report_body":{
"properties":{
"licensees_schemes_rep_involved":{
"properties":{
"report_submit_licensee":{
"const":"Yes"
}
},
"required":[
"report_submit_licensee"
]
}
}
}
}
}
]
}

这样,第二个例子失败了,而下面修改的例子(注意,它包含afs_emp_rep_verify(被接受了

...
{
"afs_emp_rep_Capacity": [
"Current director of licensee"
],
"afs_emp_rep_work_monitored": "No",
"afs_emp_rep_verify": "No"
},
...

相关内容

  • 没有找到相关文章

最新更新