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

Unable to validate json schema using chakram-expectation.schema, for wrong schema method is returning true. #113

Open
Sumit-Soman opened this issue Nov 15, 2017 · 1 comment

Comments

@Sumit-Soman
Copy link

Hi team, i am not able to validate my json with the provided schema. The method is returning true for any provided schema for my json. Kindly help
Below are the details:
raw json
{
"user_id": 954,
"first_name": "Claudia",
"last_name": "Hackbarth",
"user_role": "Alum",
"permission": {
"german_colleague": false,
"create_job": true,
"create_profiles": true,
"search_profile": false,
"admin": false
},
"status": {
"change_password": false
},
"exp": 1511265571,
"iss": "issuer_name",
"aud": "client"
}

schema
var expectedSchema={
properties: {
wrong_entity: {type: "integer"},
first_name: {type: 'number'},
last_name: {type: 'string'},
user_role: {type: 'string'},
permission: {
type: "object",
properties: {
german_colleague: {type: "boolean"},
create_job: {type: "boolean"},
create_profiles: {type: "boolean"},
search_profile: {type: "boolean"},
admin: {type: "boolean"}
}
},
status: {
type: "object",
properties: {
change_password: {type: "boolean"}
}
},
exp: {type: "integer"},
iss: {type: 'string'},
aud: {type: 'string'}
},
required: ["user_id"]
};

expect(response).to.have.schema(expectedSchema);

  • for field "user_id" in json i have mentioned "wrong_entity" in my schema.
    For wrong schema above, method "chakram-expectation.schema" is returning true[unexpected]. Am I missing some config changes here.
@ADNolan
Copy link

ADNolan commented Nov 18, 2017

Your schema is only checking that the user_id is present, which it is. The schema validation for tv4 is the same one postman uses and I have run into the same situation in the past. since wrong_entity is not required and not present, tv4 validator ignores that property. If that property was there, it would validate against your definition.

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

2 participants