0

我正在使用 JsonLogic 使用 JsonLogic 定义的规则来验证我的输入有效负载。我可以使用“使用它”工具测试规则,并且我的规则对我的输入数据工作得很好。

但是,当我通过我的 .net Core 应用程序通过从 Postman 传递有效负载来运行相同的规则时,规则总是返回else条件,即使它应该来自if条件的错误。

{
"if": [
{
  "missing": [
     "ProposedProjectDetails.IsFreezone",
    "ProposedProjectDetails.InterestedToLeaseFrom",
    "ProposedProjectDetails.IndustryType",
    "ProposedProjectDetails.OtherType",
    "ProposedProjectDetails.ProjectDescription",
    "ProposedProjectDetails.OutputofFacility",
    "ProposedProjectDetails.ProductionCapacity",
    "ProposedProjectDetails.ProductionCapacityVolume",
    "ProposedProjectDetails.MainRawMaterials",
    "ProposedProjectDetails.RawMaterialQuantity",
    "ProposedProjectDetails.RawMaterialEstimatedCost",
    "ProposedProjectDetails.RawMaterialEstimatedTotInvestment",
    "ProposedProjectDetails.AnnualSalesRevenue",
    "ProposedProjectDetails.ConstructionStartDate",
    "ProposedProjectDetails.Skilledjobs",
    "ProposedProjectDetails.TotalAccomodationRequired",
    "ProposedProjectDetails.TotalWorkerSalary",
    "ProposedProjectDetails.EBITDA",
    "ProposedProjectDetails.PortCargoImports",
  ]
},
"Missing mandatory inputs",
"all good"
]
}

样本输入有效载荷是

{
"companyId": "string",
"serviceCode": "IPA",
"serviceType": "string",
"serviceName": "string",
"crmApplicationId": "string",
"crmReferenceNumber": "string",
"portalReferenceNumber": "string",
"data": {
    "proposedProjectDetails": {
        "outputofFacility": 2,
        "productionCapacity": 0,
        "productionCapacityVolume": 0,
        "others": "string",
        "shiftsPerDay": 0
     }
   }
}

我正在评估的.Net代码是

  public ValidationResponse Validate(JObject validation, JObject data)
    {
        var evaluator = new JsonLogicEvaluator(EvaluateOperators.Default);
        var result = evaluator.Apply(validation, data);

        return new ValidationResponse
        {
            IsValid = (string.Equals("All Fine", result.ToString(), StringComparison.OrdinalIgnoreCase)),
            Message = result
        };
    }

当我运行上面的代码时JsonRulesPayload我总是得到all good响应。但是由于我在有效负载中缺少所需的数据,它应该会得到Missing mandatory inputs我在 JsonLogic“玩它”工具中得到的错误。

4

0 回答 0