Json Schema Assertion
*JSON Schema Assertion: This feature allows you to create schema tests for your API response. By providing your API response, you can generate tests using either SDKs or REST APIs.
Usage 🚀
Refer to Setup Guide for installing dependecies for both Java and Python.
JAVA
There are 2 clients available with the Java SDK: SyncClient and AsyncClient
Java Client Code
# for async client
import org.qyrus.ai_sdk.Clients.AsyncClient;
AsyncClient client = new AsyncClient(<API_TOKEN>, null);
# for sync client
import org.qyrus.ai_sdk.Clients.SyncClient;
SyncClient client = new SyncClient(<API_TOKEN>, null);Using SyncClient
Here's an example of utilizing JSON Schema Assertion with SyncClient.
Java SyncClient Code
private static void testJSONSchemaAssertions() {
Dotenv dotenv = Dotenv.load();
String QYRUS_AI_SDK_API_TOKEN = dotenv.get("QYRUS_AI_SDK_API_TOKEN");
SyncClient client = new SyncClient(QYRUS_AI_SDK_API_TOKEN, null);
Map<String, Object> loanApplication = Map.of(
"loanId", 101,
"userId", 1,
"loanAmount", 200000,
"loanTerm", 30,
"propertyValue", 250000,
"income", 100000,
"creditScore", 750,
"status", "pending"
);
long startTime = System.currentTimeMillis();
int numberOfRequests = 2;
for (int i = 0; i < numberOfRequests; i++) {
try {
// Assuming that the client has a method for JSON schema assertions
JSONSchemaAssertion.JsonSchemaResponse response = client.api_assertions.jsonschema.create(loanApplication);
// Process and print JSON schema properties and required fields
System.out.println("Schema: " + response.getSchema());
response.getProperties().forEach((key, property) ->
System.out.println("Field: " + key + ", Type: " + property.getType())
);
System.out.println("Required fields: " + String.join(", ", response.getRequired()));
} catch (Exception e) {
e.printStackTrace();
}
}
long endTime = System.currentTimeMillis();
System.out.println("Synchronous Total time for JSON Schema Assertion request: " + (endTime - startTime) + " ms");
}Using AsyncClient
Here's an example of utilizing JSON Schema Assertion with AsyncClient.
PYTHON
There are two clients available with the Python SDK: SyncQyrusAI and AsyncQyrusAI.
Using SyncQyrusAI
Here's an example of utilizing JSON Schema Assertion with SyncQyrusAI.
Using AsyncQyrusAI
Here's an example of utilizing JSON Schema Assertion with AsyncQyrusAI.
REST APIs
This API allows users to create test based on provided API JSON Schema.
Endpoint
URL : POST {{GATEWAY_URL}}/api-assertion-gpt-sdk/v1/api/assertion/jsonschema
Headers
Authorization: [Your Authorization Token]
Custom: [Your Custom Header Value]
Request Body: { "response": { "loanId": 101, "userId": 1, "loanAmount": 200000, "loanTerm": 30, "propertyValue": 250000, "income": 100000, "creditScore": 750, "status": "pending" } }
Response:
Last updated