[WS] Validate OpenAPI against Specification
Description
Validate an OpenAPI/Swagger response body, request body, or string against an OpenAPI/Swagger specification. The OpenAPI/Swagger specification input can be a string, URL, or file path.
Keyword name: validateOpenAPIAgainstSpecification
Parameters
Validate an OpenAPI/Swagger request against an OpenAPI/ Swagger specification:
| Parameter | Parameter Type | Required | Description |
|---|---|---|---|
request | RequestObject | Yes | Specify the request object that needs to be validated. |
specSrc | String | Yes | Specify the OpenAPI/Swagger specification used to validate the OpenAPI/Swagger object. |
flowControl | FailureHandling | Optional | Specify failure handling schema to determine whether the execution should be allowed to continue or stop. |
Validate an OpenAPI/Swagger response against an OpenAPI/ Swagger specification:
| Parameter | Parameter Type | Required | Description |
|---|---|---|---|
response | ResponseObject | Yes | Specify the response object that needs to be validated |
request | RequestObject | Yes | Specify the request object that needs to be validated. |
specSrc | String | Yes | Specify the OpenAPI/Swagger specification used to validate the OpenAPI/Swagger object. |
flowControl | FailureHandling | Optional | Specify failure handling schema to determine whether the execution should be allowed to continue or stop. |
Returns
| Parameter Type | Description |
|---|---|
| boolean |
|
If Katalon Studio cannot find the schema file or the response does not pass the validation, throw StepFailedException.
Example
In this example, you want to validate the request and response against a Swagger specification.
RequestObject request = findTestObject('Object Repository/Swagger - Get Inventory - Passed')
ResponseObject response = null
String specSrcURL = 'http://petstore.swagger.io/v2/swagger.json'{"\n"}{"\n"}//Validate request
if (WS.validateOpenAPIAgainstSpecification(request, specSrcURL)) {
response = WS.sendRequest(request)
//Validate response
WS.validateOpenAPIAgainstSpecification(response, request, specSrcURL)
}
String specSrcFileLocation = FileUtil.getFile('example/swagger-openapi/swagger.json').getAbsolutePath()
//Validate request
if (WS.validateOpenAPIAgainstSpecification(request, specSrcFileLocation, FailureHandling.CONTINUE_ON_FAILURE)) {
response = WS.sendRequest(request)
//Validate response
WS.validateOpenAPIAgainstSpecification(response, request, specSrcFileLocation, FailureHandling.CONTINUE_ON_FAILURE)
Known limitation
-
The
WS.validateOpenApiAgainstSpecificationkeyword currently performs case-insensitive matching for object property names. As a result, validation may incorrectly pass when the API response violates the letter case defined in the OpenAPI Specification.For example, if your schema defines properties as Major or Minor (PascalCase), but the API response returns them as major or minor (lowercase), the validation still passes, even though the OpenAPI standard requires property names to be case-sensitive.
This is a known limitation and will be fixed in a future release to follow the OpenAPI standard.