Skip to main content

[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:
ParameterParameter TypeRequiredDescription
requestRequestObjectYesSpecify the request object that needs to be validated.
specSrcStringYesSpecify the OpenAPI/Swagger specification used to validate the OpenAPI/Swagger object.
flowControlFailureHandlingOptionalSpecify 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
ParameterParameter TypeRequiredDescription
responseResponseObjectYesSpecify the response object that needs to be validated
requestRequestObjectYesSpecify the request object that needs to be validated.
specSrcStringYesSpecify the OpenAPI/Swagger specification used to validate the OpenAPI/Swagger object.
flowControlFailureHandlingOptionalSpecify failure handling schema to determine whether the execution should be allowed to continue or stop.

Returns

Parameter TypeDescription
boolean
  • true if the response passes the validation
  • false if the response does not pass the validation

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'

//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)
}​
Was this page helpful?