Skip to main content

New Feature Announcement - Swagger Contract Validation

Β· 2 min read
Kyrillos Nageh
SHAFT_Engine maintainer
SHAFT_Engine

Say goodbye to manual schema checksβ€”contract testing is now automated and built right into SHAFT!​


πŸ›‘οΈ What is Contract Validation?​

Contract testing ensures your API requests and responses follow the defined structure (contract), helping prevent:

  • Unexpected field changes
  • Data type mismatches
  • Missing or extra fields
  • Runtime errors in API consumers

With the latest release, SHAFT now integrates Swagger/OpenAPI schema validation for all API tests. It will fail your test automatically if the request or response doesn’t match the OpenAPI spec you provide. πŸ”₯


πŸ”§ How to Enable It​

πŸ“‚ Via custom.properties​

src/main/resources/properties/custom.properties
swagger.validation.enabled=true
swagger.validation.url=https://petstore.swagger.io/v2/swagger.json

πŸ§ͺ Or via Code​

SHAFT.Properties.api.set().swaggerValidationEnabled(true);
SHAFT.Properties.api.set().swaggerValidationUrl("https://petstore.swagger.io/v2/swagger.json");

You can toggle validation dynamically per test or test class.


βœ… What Gets Validated?​

  • Request structure (body, headers, parameters)
  • Response structure (status, body schema)
  • Alignment with your OpenAPI/Swagger definition

πŸ“„ Sample Test​

@Test
public void testCreateUserWithContractValidation() {
SHAFT.API api = new SHAFT.API("https://petstore.swagger.io/v2");

String invalidPayload = "[{\"id\":\"INVALID_ID\"}]";

api.post("/user/createWithList")
.setRequestBody(invalidPayload)
.setContentType("application/json")
.perform();

api.assertThatResponse().statusCode().isEqualTo(400).perform();
}

SHAFT will automatically validate the above request and response against the Swagger schema. ❌ If anything is off, your test will fail and report the contract violation.


🧐 Why It Matters​

BenefitDescription
πŸ§ͺ Test reliabilityEnsure tests align with backend changes
πŸ” Catch regressionsCI/CD-ready contract enforcement
❌ Reduce flakinessEliminate schema mismatch failures
πŸ” API governanceHold your APIs to their contract

New Feature Announcement - Virtual Threads

Β· 2 min read
Mustafa Agamy
SHAFT_Engine maintainer

We're starting off 2024 with a huge announcement!

SHAFT_Engine

🀝

Oracle

- The future of automation frameworks is here, and it's all about working smarter, not harder.​

- SHAFT_ENGINE, your trusty automation solution, just got a major upgrade with virtual threads, a clever trick that makes it more efficient and helpful than ever.​

- What is a Virtual Thread?​

  • Virtual-Threads, introduced with Java 21 are a new way to handle multiple tasks concurrently within a single program or application. They're the new java way for asynchronous operations.
  • Think of it like hiring a whole crew of tiny helpers. While one tractor's plowing, another can check the soil, and another can keep an eye on the weather.
  • These lightweight assistants don't need fancy equipment or guzzle up resources, meaning SHAFT_ENGINE can now handle a ton more tasks without breaking a sweat.

Now let's think of test automation. In automating a registration form, envision employing a crew of virtual threads as tiny helpers :​

  • Rather than idly waiting for the entire site to load, each virtual thread can be assigned specific tasks as soon as the relevant elements become available. For instance, one thread focuses on inputting the username, another simultaneously handles the email input, and yet another sets the password. This parallel execution optimizes efficiency, ensures prompt responsiveness to dynamically changing elements, and efficiently utilizes resources.
  • As the crew of virtual threads collaborates seamlessly, the registration form is filled and submitted swiftly, providing a more agile and responsive automation process compared to traditional sequential approaches.

- Save your execution Time :​

  • That's not all, SHAFT_ENGINE utilities the Virtual Threads for Engine launch and configuration which will make your overall experience a lot faster and swifter.