How to do JSON schema validation while API testing in Telerik Test Studio

2 Answers 406 Views
General Discussions Verification
Siddalingesh
Top achievements
Rank 1
Siddalingesh asked on 28 May 2021, 01:13 PM
Can anyone please let me know how to do JSON schema validation while API testing in Telerik Test Studio? (I have a given schema)

2 Answers, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 01 Jun 2021, 12:49 PM

Hello Siddalingesh,

Thank you for contacting us with your question. I will share more details about our product and what it supports.

Test Studio for APIs is designed to help you automate the API of your application. You can send requests and validate the response that is returned by the server. You can find more details and examples in the linked documentation of our product.

Let me get back to your questions. I must say that I am not an expert on JSON schema, but I did some research. I believe that it is not possible to validate the JSON schema within the API project, since it does not exist in the response. I might be misunderstanding your test scenario, so please share more details and examples to help me understand it better. 

Thank you for your cooperation in advance.

Regards,
Plamen Mitrev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Siddalingesh
Top achievements
Rank 1
commented on 01 Jun 2021, 03:31 PM | edited

Hello Plamen Mitrev,

Thank you so much for your response !!!

My exact question is, I have a test which returns JSON response after hitting an API. Now I need to validate the response with the JSON schema given by client in Telerik Test Studio.

(In some tests I am already verifying the "JSON response" with the given "expected result" from the client side by using "Verification module/section" in the Telerik Test Studio)

But in some tests they have said to validate JSON schema (not the expected JSON). So how can I validate that JSON schema?


Thanks !!
Siddalingesh
0
Plamen Mitrev
Telerik team
answered on 02 Jun 2021, 09:18 AM

Hi Siddalingesh,

Thank you for sharing additional information about the test scenario.

From what I understand, you want to verify if the returned response has an object that matches the expected JSON schema. Lets look at the example for the Product object here and see what kind of verifications you can use.

In this example, the Product's schema has "productID", "productName', "price" and "tags" properties. In order to verify the schema, you can do a verification for each of those properties and ensure that the object in the response complies with the expected schema. Lets look at the example below.

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.com/product.schema.json",
  "title": "Product",
  "description": "A product from Acme's catalog",
  "type": "object",
  "properties": {
    "productId": {
      "description": "The unique identifier for a product",
      "type": "integer"
    },
    "productName": {
      "description": "Name of the product",
      "type": "string"
    }
  },
  "required": [ "productId", "productName" ]
}

Here the "productID" should be an integer and the "productName" should be a string. You can use RegEx to verify that the returned value for "productID" has only characters from 0 to 9 or that the "productName" has a certain string value. That is just one way to check if the returned object matches the expected JSON schema. 

I hope the above details and suggestion will be helpful to you.

Regards,
Plamen Mitrev
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
General Discussions Verification
Asked by
Siddalingesh
Top achievements
Rank 1
Answers by
Plamen Mitrev
Telerik team
Share this question
or