swagger-model-validator icon indicating copy to clipboard operation
swagger-model-validator copied to clipboard

When a upper level failed (required field) is not available, child object does not get validated at all

Open samw2k00 opened this issue 4 years ago • 1 comments

When a upper level attribute is missing, the validator stop validating any other child object that exist

eg. https://raw.githubusercontent.com/ConsumerDataStandardsAustralia/standards/master/slate/source/includes/swagger/cds_banking.json

the following model:

"ResponseBankingAccountList" : { "type" : "object", "required" : [ "data", "links", "meta" ], "properties" : { "data" : { "$ref" : "#/definitions/ResponseBankingAccountList_data" }, "links" : { "$ref" : "#/definitions/LinksPaginated" }, "meta" : { "$ref" : "#/definitions/MetaPaginated" } } },

When "meta" object is missing. the child of "data" object and "links" object does not get validated at all.

sample data

{ "data": { "accounts": [ { "accountId": "account-1", "displayName": "John Smith 1", "nickname": "my savings 1", "isOwned": true, "maskedNumber": "xxxxxnt-1", "productCategory": "TRANS_AND_SAVINGS_ACCOUNTS", "productName": "S1", "consentStatus": "CONSENTED" }, { "accountId": "account-2", "displayName": "John Smith 2", "nickname": "my savings 2", "isOwned": true, "maskedNumber": "xxxxxnt-2", "productCategory": "TERM_DEPOSITS", "productName": "S2", "consentStatus": "CONSENTED" }, { "accountId": "account-3", "displayName": "John Smith 3", "nickname": "my savings 3", "isOwned": true, "maskedNumber": "xxxxxnt-3", "productCategory": "TRANS_AND_SAVINGS_ACCOUNTS", "productName": "S3", "consentStatus": "CONSENTED" }, { "accountId": "account-4", "displayName": "John Smith 4", "nickname": "my savings 4", "isOwned": true, "maskedNumber": "xxxxxnt-4", "productCategory": "TERM_DEPOSITS", "productName": "S4", "consentStatus": "CONSENTED" }, { "accountId": "account-5", "displayName": "John Smith 5", "nickname": "my savings 5", "isOwned": true, "maskedNumber": "xxxxxnt-5", "productCategory": "TRANS_AND_SAVINGS_ACCOUNTS", "productName": "S5", "consentStatus": "NOT_CONSENTED" } ] }, "links": { "first": "https://localhost:8701/consents/275/accounts?page=1&page-size=25", "self": "https://localhost:8701/consents/275/accounts?page=1&page-size=25", "last": "https://localhost:8701/consents/275/accounts?page=1&page-size=25" } }

samw2k00 avatar Nov 19 '21 06:11 samw2k00

Generally, once we've found a non-match (or error) we stop processing and return the error. This validation is primarily for developer support so we would expect them to keep calling us with progressively better conforming objects rather than communicate all the errors at once. So error paths do return multiple errors - some do not.

In this case you are failing the required test - So because you are missing a required field we are not going to bother testing anything else. We do the required tests first to reduce our processing load on an obejcvt that isn't going to pass anyway.

brodyd avatar May 08 '22 09:05 brodyd