Skip to main content
REST API

OpenAPI Conformance Hunt

RequestValidateMedium

What you will learn

  • Validate responses against the published contract/schema, not just the HTTP status code
  • Catch type drift, missing required fields, and wrong status codes with property/schema assertions
  • Recognise that happy-path-only suites pass real spec violations โ€” assert the whole shape

Description

Validate responses against a published contract and prove your schema assertions catch intentional drift (wrong type, missing field, wrong status).

Test Scenario

const okBody = await (await request.get('/api/v1/conformance')).json();
expect(typeof okBody.score).toBe('number');
expect(okBody.name).toBeDefined();

const typeDrift = await (await request.get('/api/v1/conformance?drift=type')).json();
expect(typeof typeDrift.score).toBe('string'); // your schema matcher must FAIL on this

const status = await request.get('/api/v1/conformance?drift=status');
expect(status.status()).toBe(503);
Endpoint/api/v1/conformance

Testing Tips

  • โ€ขGET ?contract=1 returns the JSON-schema-ish contract to assert every response against
  • โ€ขEach ?drift= value ships one violation: type (score as string), missing (no name), status (503)
  • โ€ขA happy-path-only test passes all of these โ€” assert the full schema, not just status 200
// Playwright API Testing - REST
import { test, expect } from '@playwright/test';
test('REST API request', async ({ request }) => {
const response = await request.get('/api/v1/resource');
expect(response.ok()).toBeTruthy();
expect(response.status()).toBe(200);
const data = await response.json();
expect(data).toBeDefined();
});

Challenge ID: rest-openapi-conformance

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/conformance

Press Enter to send