Swagger Compliance Assertion

Applies to ReadyAPI 3.56, last modified on October 29, 2024

The Swagger Compliance assertion verifies that the response corresponds with the specified definition. The assertion supports the following specifications:

  • Swagger 2.0 (also known as OpenAPI 2.0)

  • OpenAPI 3.0.0 and 3.1.0

Availability

In... Checks... To learn more...
Functional tests The response. See Working With Assertions in Functional Tests.
Virtual services The request. See Assertions in Virtual Services.

Create an assertion

Follow these steps:

Functional test: The Assertions panel

Click the image to enlarge it.

  1. Open a test step.

  2. Click Add assertion.

In the New Assertions dialog, search for the Swagger Compliance assertion or select it manually in the Compliance, Status and Standards category.

Follow these steps:

Virtual service operation: The Assertions panel

Click the image to enlarge it.

  1. Open the virtual service.

  2. Select the operation you want to assert.

  3. Click in the Assertions panel.

In the New Assertions dialog, search for the Swagger Compliance Assertion assertion or select it manually in the Compliance, Status and Standards category.

You cannot apply this assertion to the entire virtual service, you can apply it only to individual operations.

Setting up properties

  1. In the Swagger URL field, specify the file name or URL of the desired OpenAPI or Swagger specification.

    If the definition's URL requires authentication, you will be prompted to enter credentials.

    Swagger Compliance assertion

    Click the image to enlarge it.

  2. If you enable the Strict Mode option, the assertion will fail if the definition does not contain the appropriate response. If you disable this option, the assertion passes if the response code is not specified in the definition.

  • How the assertion works:

    In functional tests

    1. The assertion gets a response code. Then, it searches for the corresponding status code specified in the definition and checks if the response has an appropriate content-type.

      If the definition specifies the response body, the assertion verifies if the response body coincides with the specified schema.

    2. (Only for Open 3.0.0 specifications) If the response status code is not defined in the definition, the assertion compares the response against the default response.

      Currently, the assertion does not support the range of responses.
    3. By default, if the assertion cannot find an appropriate HTTP status code, it passes. If you want the assertion to fail in such cases, enable the Strict mode option.

    In virtual services

    • The assertion checks whether the request has the appropriate content type.

      If the definition specifies the request body, the assertion checks whether the request body coincides with the specified schema.

  • When the assertion runs for the first time, ReadyAPI loads the definition into an internal cache. During the following runs, the assertion uses a cached version of the definition. ReadyAPI clears the cache when it is closed.

  • The JSON Schema Validation: A Vocabulary for Structural Validation of JSON is automatically used to validate any RegEx expressions included in your API definition file. That schema uses the ECMA-262 standard for RegEx encoding. The usage of that schema is a standard and it is not controlled by ReadyAPI, as per the official documentation linked above.

    It does now follow the Glossary | ReadyAPI Documentation RegEx encoding so it does not follow the Java Regular Expressions encoding. As a consequence, it does not support Unicode encoding for RegEx.

Add other schema compliance assertions:

See Also

Swagger Integration
Compliance Assertions

Highlight search results