I am in the middle of upgrading dredd from 1.08 to the latest version, while at it, I am trying to validate our api documentation, written in blueprint with the realtime test api and it is failing.
Since the tests are running against a real time api, the response returned from the api contains different values than specified in the blurprint document. I receive the following error from dredd.
Could someone help me figure it out ? :)
body: At '/data/email' No enum match for: "[email protected]"
body: At '/data/firstName' No enum match for: "Sniper"
body: At '/data/lastName' No enum match for: "Wolf"
body: At '/data/verified' No enum match for: false
## `ResponseSchema` (object)
+ email: `[email protected]` (string, required) - Email address
+ firstName: John (string, required) - First name
+ lastName: Doe (string, required) - Last name
+ verified: true (boolean, required) - True
# Group Account
## Login [/login/?]
Login user
### Login [POST]
Authentication required.
+ Request (application/json)
+ Attribute (LoginInputSchema)
+ Response 200 (application/json; charset=UTF-8)
+ Attribute
+ status: 200 (number, required, fixed)
+ data (ResponseSchema, required, fixed)
The JSON Schema generated by dredd is below
bodySchema: {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"status": {
"type": "number",
"enum": [
200
]
},
"data": {
"type": "object",
"properties": {
"email": {
"type": "string",
"enum": [
"[email protected]"
],
"description": "Email address of the guest."
},
"firstName": {
"type": "string",
"enum": [
"John"
],
"description": "First name of the guest."
},
"lastName": {
"type": "string",
"enum": [
"Doe"
],
"description": "Last name of the guest."
},
"verified": {
"type": "boolean",
"enum": [
true
],
"description": "The user is verified or not"
},
},
"required": [
"email",
"firstName",
"lastName",
"verified",
],
"additionalProperties": false
}
},
"required": [
"status",
"data"
]
}
TL;DR: Try to use fixed-type
instead of fixed
in your API Blueprint document. fixed
requires the sample values to be the actual values.
More elaborate explanation:
body: At '/data/email' No enum match for: "[email protected]"
This means the response returned by the server under test contains a correctly parseable JSON body, but the body isn't valid according to the schema provided by the API description.
The error points to /data/email
, which means the {"data": {"email": ...
property is problematic. Further, it mentions that enum
of values is expected, and that the actual response contains [email protected]
, which isn't allowed by the enum. The other errors are similar.
Looking at the API description, the specification of what is expected in the response goes as follows:
+ Attribute
+ status: 200 (number, required, fixed)
+ data (ResponseSchema, required, fixed)
The fixed
attribute, as explained in the 4.3 Nested Member Types section of the MSON spec, fixes not only the structure, but also all values, and propagates further down the data structure:
...MAY specify fixed to indicate a "value object" where all the properties MUST be present and the values of the properties MUST be the values specified, if any, in its Nested Member Types. Further, such an object type structure MUST NOT contain any other properties.
I think you want to use fixed-type
instead, which fixes just the structure. This is further explained also in the Making Dredd Validation Stricter section of the Dredd docs.