Luong Dinh
Luong Dinh

Reputation: 569

RestAsure Check Json response schema base on Swagger docs

I'm implementing integration test for my API endpoints. To validate the json response schema, i had swagger docs. Usually, I have to convert swagger yaml to json and create Json schema file manually. I found that all the trick information is defined in swagger file, it should have some ways to validate json response directly from swagger docs.

Do you know any way to validate json schema response directly from swagger file?

Upvotes: 0

Views: 1257

Answers (1)

Luong Dinh
Luong Dinh

Reputation: 569

Thank Atlassian public this library. We can use rest assured filter to validate our response directly from swagger file.

private static final String SWAGGER_JSON_URL = 
"http://petstore.swagger.io/v2/swagger.json";

private final SwaggerValidationFilter validationFilter = new SwaggerValidationFilter(SWAGGER_JSON_URL);
@Test
public void testGetValidPet() {
    given()
            .port(PORT)
            .filter(validationFilter)
    .when()
            .get("/pet/1")
    .then()
            .assertThat()
            .statusCode(200);
}

refer here for detai: https://bitbucket.org/atlassian/swagger-request-validator/src/master/

Upvotes: 1

Related Questions