Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation error (Not supporting anyOf property) #388

Open
anshul-031 opened this issue Sep 28, 2023 · 0 comments
Open

Validation error (Not supporting anyOf property) #388

anshul-031 opened this issue Sep 28, 2023 · 0 comments

Comments

@anshul-031
Copy link

anshul-031 commented Sep 28, 2023

We are trying to use the new Validator().validate() method of jsonSchema Library, But we are not getting accurate result in case schema parameter contains anyOf property.

For example: We have a payload which we are trying to validate against a schema having anyOf property. Our payload is satisfying one of the pattern of "anyOf" but still getting the validation error. Below are the details of payload, schema & validationResult received. Please look at this issue at earliest, Quite urgent for us.

payload =
{ "_ItemAmount": [{ "AmountInTransactionCurrency": 20 }] }

schema =
{ "additionalProperties": true, "type": "object", "title": "Postfixedassetacquisitionsapselfpost Inputs", "properties": { "QuantityInBaseUnit": { "multipleOf": 0.001, "anyOf": [{ "type": "number" }, { "type": "string" }], "maximum": 9999999999.999, "x-sap-scale": 3, "type": "number", "x-sap-precision": 13, "minimum": -9999999999.999, "example": 0 }, "AcqnAmtInTransactionCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "type": "string", "x-sap-precision": 23, "example": 0 }, "_ItemAmount": { "type": "array", "items": { "additionalProperties": true, "type": "object", "title": "D_FixedAssetPostAcqnItemAmtP", "properties": { "GlobalCurrency": { "type": "string", "title": "Global Currency", "maxLength": 3 }, "FreeDefinedCurrency1": { "description": "Freely Defined Currency 1", "type": "string", "title": "Free Defined Crcy 1", "maxLength": 3 }, "CompanyCodeCurrency": { "description": "Company Code Currency", "type": "string", "title": "CompanyCode Currency", "maxLength": 3 }, "FreeDefinedCurrency4": { "description": "Freely Defined Currency 4", "type": "string", "title": "Free Defined Crcy 4", "maxLength": 3 }, "AssetDepreciationArea": { "description": "Real depreciation area", "type": "string", "title": "Depreciation area", "maxLength": 2 }, "FreeDefinedCurrency5": { "description": "Freely Defined Currency 5", "type": "string", "title": "Free Defined Crcy 5", "maxLength": 3 }, "AmountInTransactionCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Transaction Currency", "type": "string", "title": "Amnt in Trans. Crcy", "x-sap-precision": 23, "example": 0 }, "FreeDefinedCurrency2": { "description": "Freely Defined Currency 2", "type": "string", "title": "Free Defined Crcy 2", "maxLength": 3 }, "FreeDefinedCurrency3": { "description": "Freely Defined Currency 3", "type": "string", "title": "Free Defined Crcy 3", "maxLength": 3 }, "FreeDefinedCurrency8": { "description": "Freely Defined Currency 8", "type": "string", "title": "Free Defined Crcy 8", "maxLength": 3 }, "AmountInFreeDefinedCurrency1": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 1", "type": "string", "title": "Amount in Currency 1", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency2": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 2", "type": "string", "title": "Amount in Currency 2", "x-sap-precision": 23, "example": 0 }, "FreeDefinedCurrency6": { "description": "Freely Defined Currency 6", "type": "string", "title": "Free Defined Crcy 6", "maxLength": 3 }, "AmountInFreeDefinedCurrency3": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 3", "type": "string", "title": "Amount in Currency 3", "x-sap-precision": 23, "example": 0 }, "FreeDefinedCurrency7": { "description": "Freely Defined Currency 7", "type": "string", "title": "Free Defined Crcy 7", "maxLength": 3 }, "AmountInFreeDefinedCurrency4": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 4", "type": "string", "title": "Amount in Currency 4", "x-sap-precision": 23, "example": 0 }, "AmountInGlobalCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Global Currency", "type": "string", "title": "Amnt in Global Crcy", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency5": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 5", "type": "string", "title": "Amount in Currency 5", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency6": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 6", "type": "string", "title": "Amount in Currency 6", "x-sap-precision": 23, "example": 0 }, "TransactionCurrency": { "type": "string", "title": "Transaction Currency", "maxLength": 3 }, "AmountInFreeDefinedCurrency7": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 7", "type": "string", "title": "Amount in Currency 7", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency8": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 8", "type": "string", "title": "Amount in Currency 8", "x-sap-precision": 23, "example": 0 }, "AmountInCompanyCodeCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Company Code Currency", "type": "string", "title": "Amnt in Comp Cd Crcy", "x-sap-precision": 23, "example": 0 }, "SubLedgerAcctLineItemType": { "description": "Subledger-Specific Line Item Type", "type": "string", "title": "Line Item Type", "maxLength": 5 } } } }, "FixedAsset": { "type": "string", "maxLength": 4 }, "BusinessTransactionType": { "type": "string", "maxLength": 4 }, "AssetValueDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "FixedAssetYearOfAcqnCode": { "type": "string", "maxLength": 1 }, "TransactionCurrency": { "type": "string", "maxLength": 3 }, "AccountingDocumentHeaderText": { "type": "string", "maxLength": 25 }, "MasterFixedAsset": { "type": "string", "maxLength": 12 }, "ExchangeRateDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "AccountingDocumentType": { "type": "string", "maxLength": 2 }, "OffsettingAccount": { "type": "string", "maxLength": 10 }, "BaseUnitISOCode": { "type": "string", "maxLength": 3 }, "TradingPartner": { "type": "string", "maxLength": 6 }, "DocumentReferenceID": { "type": "string", "maxLength": 16 }, "DebitCreditCode": { "type": "string", "maxLength": 1 }, "AssignmentReference": { "type": "string", "maxLength": 18 }, "BaseUnitSAPCode": { "type": "string", "maxLength": 3 }, "ReferenceDocumentItem": { "type": "string", "maxLength": 6 }, "PostingDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "_Ledger": { "type": "array", "items": { "additionalProperties": true, "type": "object", "title": "D_FixedAssetPostAcqnLedgerP", "properties": { "Ledger": { "description": "Ledger in General Ledger Accounting", "type": "string", "title": "Ledger", "maxLength": 2 }, "_Valuation": { "type": "array", "items": { "additionalProperties": true, "type": "object", "title": "D_FixedAssetPostAcqnValuationP", "properties": { "AssetDepreciationArea": { "description": "Real depreciation area", "type": "string", "title": "Depreciation area", "maxLength": 2 } } } } } } }, "AssetOriginalValueDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "DocumentItemText": { "type": "string", "maxLength": 50 }, "DocumentDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "CompanyCode": { "type": "string", "maxLength": 4 } } }

validationResult=
{ "instance": { "_ItemAmount": [{ "AmountInTransactionCurrency": 20 }] }, "schema": { "additionalProperties": true, "type": "object", "title": "Postfixedassetacquisitionsapselfpost Inputs", "properties": { "QuantityInBaseUnit": { "multipleOf": 0.001, "anyOf": [{ "type": "number" }, { "type": "string" }], "maximum": 9999999999.999, "x-sap-scale": 3, "type": "number", "x-sap-precision": 13, "minimum": -9999999999.999, "example": 0 }, "AcqnAmtInTransactionCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "type": "string", "x-sap-precision": 23, "example": 0 }, "_ItemAmount": { "type": "array", "items": { "additionalProperties": true, "type": "object", "title": "D_FixedAssetPostAcqnItemAmtP", "properties": { "GlobalCurrency": { "type": "string", "title": "Global Currency", "maxLength": 3 }, "FreeDefinedCurrency1": { "description": "Freely Defined Currency 1", "type": "string", "title": "Free Defined Crcy 1", "maxLength": 3 }, "CompanyCodeCurrency": { "description": "Company Code Currency", "type": "string", "title": "CompanyCode Currency", "maxLength": 3 }, "FreeDefinedCurrency4": { "description": "Freely Defined Currency 4", "type": "string", "title": "Free Defined Crcy 4", "maxLength": 3 }, "AssetDepreciationArea": { "description": "Real depreciation area", "type": "string", "title": "Depreciation area", "maxLength": 2 }, "FreeDefinedCurrency5": { "description": "Freely Defined Currency 5", "type": "string", "title": "Free Defined Crcy 5", "maxLength": 3 }, "AmountInTransactionCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Transaction Currency", "type": "string", "title": "Amnt in Trans. Crcy", "x-sap-precision": 23, "example": 0 }, "FreeDefinedCurrency2": { "description": "Freely Defined Currency 2", "type": "string", "title": "Free Defined Crcy 2", "maxLength": 3 }, "FreeDefinedCurrency3": { "description": "Freely Defined Currency 3", "type": "string", "title": "Free Defined Crcy 3", "maxLength": 3 }, "FreeDefinedCurrency8": { "description": "Freely Defined Currency 8", "type": "string", "title": "Free Defined Crcy 8", "maxLength": 3 }, "AmountInFreeDefinedCurrency1": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 1", "type": "string", "title": "Amount in Currency 1", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency2": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 2", "type": "string", "title": "Amount in Currency 2", "x-sap-precision": 23, "example": 0 }, "FreeDefinedCurrency6": { "description": "Freely Defined Currency 6", "type": "string", "title": "Free Defined Crcy 6", "maxLength": 3 }, "AmountInFreeDefinedCurrency3": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 3", "type": "string", "title": "Amount in Currency 3", "x-sap-precision": 23, "example": 0 }, "FreeDefinedCurrency7": { "description": "Freely Defined Currency 7", "type": "string", "title": "Free Defined Crcy 7", "maxLength": 3 }, "AmountInFreeDefinedCurrency4": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 4", "type": "string", "title": "Amount in Currency 4", "x-sap-precision": 23, "example": 0 }, "AmountInGlobalCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Global Currency", "type": "string", "title": "Amnt in Global Crcy", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency5": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 5", "type": "string", "title": "Amount in Currency 5", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency6": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 6", "type": "string", "title": "Amount in Currency 6", "x-sap-precision": 23, "example": 0 }, "TransactionCurrency": { "type": "string", "title": "Transaction Currency", "maxLength": 3 }, "AmountInFreeDefinedCurrency7": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 7", "type": "string", "title": "Amount in Currency 7", "x-sap-precision": 23, "example": 0 }, "AmountInFreeDefinedCurrency8": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Freely Defined Currency 8", "type": "string", "title": "Amount in Currency 8", "x-sap-precision": 23, "example": 0 }, "AmountInCompanyCodeCurrency": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Company Code Currency", "type": "string", "title": "Amnt in Comp Cd Crcy", "x-sap-precision": 23, "example": 0 }, "SubLedgerAcctLineItemType": { "description": "Subledger-Specific Line Item Type", "type": "string", "title": "Line Item Type", "maxLength": 5 } } } }, "FixedAsset": { "type": "string", "maxLength": 4 }, "BusinessTransactionType": { "type": "string", "maxLength": 4 }, "AssetValueDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "FixedAssetYearOfAcqnCode": { "type": "string", "maxLength": 1 }, "TransactionCurrency": { "type": "string", "maxLength": 3 }, "AccountingDocumentHeaderText": { "type": "string", "maxLength": 25 }, "MasterFixedAsset": { "type": "string", "maxLength": 12 }, "ExchangeRateDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "AccountingDocumentType": { "type": "string", "maxLength": 2 }, "OffsettingAccount": { "type": "string", "maxLength": 10 }, "BaseUnitISOCode": { "type": "string", "maxLength": 3 }, "TradingPartner": { "type": "string", "maxLength": 6 }, "DocumentReferenceID": { "type": "string", "maxLength": 16 }, "DebitCreditCode": { "type": "string", "maxLength": 1 }, "AssignmentReference": { "type": "string", "maxLength": 18 }, "BaseUnitSAPCode": { "type": "string", "maxLength": 3 }, "ReferenceDocumentItem": { "type": "string", "maxLength": 6 }, "PostingDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "_Ledger": { "type": "array", "items": { "additionalProperties": true, "type": "object", "title": "D_FixedAssetPostAcqnLedgerP", "properties": { "Ledger": { "description": "Ledger in General Ledger Accounting", "type": "string", "title": "Ledger", "maxLength": 2 }, "_Valuation": { "type": "array", "items": { "additionalProperties": true, "type": "object", "title": "D_FixedAssetPostAcqnValuationP", "properties": { "AssetDepreciationArea": { "description": "Real depreciation area", "type": "string", "title": "Depreciation area", "maxLength": 2 } } } } } } }, "AssetOriginalValueDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "DocumentItemText": { "type": "string", "maxLength": 50 }, "DocumentDate": { "format": "date", "type": "string", "example": "2017-04-13" }, "CompanyCode": { "type": "string", "maxLength": 4 } } }, "options": {}, "path": [], "propertyPath": "instance", "errors": [{ "path": ["_ItemAmount", 0, "AmountInTransactionCurrency"], "property": "instance._ItemAmount[0].AmountInTransactionCurrency", "message": "is not of a type(s) string", "schema": { "format": "decimal", "anyOf": [{ "type": "number" }, { "type": "string" }], "description": "Amount in Transaction Currency", "type": "string", "title": "Amnt in Trans. Crcy", "x-sap-precision": 23, "example": 0 }, "instance": 20, "name": "type", "argument": ["string"], "stack": "instance._ItemAmount[0].AmountInTransactionCurrency is not of a type(s) string" }], "disableFormat": false }

Code:
const validationResult = new Validator().validate(payload, schema);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant