Collection Validation errors when request contains variables

Hi,

I generated a collection from an API schema by using the API Designer. The requests in the collection had JSON bodies where the attributes had values of the type set in the API schema.
eg.
{
“username”: “<string>”
}

As I generated a Contract Test collection, I wanted to have the request use useful testing data and thus changed the ‘username’ value in the request to pull from the Environment by setting it to use a variable such as “{{USERNAME}}”. This works for the testing of the request when it is sent and response is tested with tests in the ‘test’ tab.

eg.
{
“username”: “{{USERNAME}}”
}

What doesn’t work is now if I go to the API Designer, click on ‘Test’ tab, and click on validate button under the 'VALIDATION" header beside the collection, I get an error indicating the request body doesn’t match the schema. Example below:

REQUEST BODY
The request body didn’t match the specified schema

The value of the variable is of the correct format as set in the schema for that property. I can get the request body validation to pass by changing the request parameter to a hard coded string.

eg.
{
“username”: “user@domain.com
}

What I am wondering, is it possible to have the collection validation pass by using variables when the variable references a value in the environment that meets the criteria of the schema?

Thank you.

2 Likes