|
| 1 | +# API Schema Documentation |
| 2 | + |
| 3 | +This directory contains JSON Schema definitions for validating API responses from the ReqRes API. |
| 4 | + |
| 5 | +## Schema Files |
| 6 | + |
| 7 | +### 1. user_list_schema.json |
| 8 | +- **Endpoint**: GET /api/users?page={page} |
| 9 | +- **Purpose**: Validates paginated user list responses |
| 10 | +- **Key Properties**: |
| 11 | + - page: Current page number |
| 12 | + - per_page: Items per page |
| 13 | + - total: Total number of users |
| 14 | + - data: Array of user objects |
| 15 | + - support: Support information |
| 16 | + |
| 17 | +### 2. single_user_schema.json |
| 18 | +- **Endpoint**: GET /api/users/{id} |
| 19 | +- **Purpose**: Validates single user responses |
| 20 | +- **Key Properties**: |
| 21 | + - data: Single user object |
| 22 | + - support: Support information |
| 23 | + |
| 24 | +### 3. create_user_schema.json |
| 25 | +- **Endpoint**: POST /api/users |
| 26 | +- **Purpose**: Validates user creation response |
| 27 | +- **Key Properties**: |
| 28 | + - name: User's name |
| 29 | + - job: User's job |
| 30 | + - id: Generated user ID |
| 31 | + - createdAt: Creation timestamp |
| 32 | + |
| 33 | +## Schema Validation |
| 34 | +All schemas are JSON Schema Draft-07 compliant and are used in the test suite for response validation. They ensure that: |
| 35 | +- Required fields are present |
| 36 | +- Field types are correct |
| 37 | +- Data structures are consistent |
| 38 | +- Additional properties are handled appropriately |
| 39 | + |
| 40 | +## Usage Example |
| 41 | +```python |
| 42 | +from jsonschema import validate |
| 43 | +from utils.api_utils import load_schema |
| 44 | + |
| 45 | +# Load schema |
| 46 | +schema = load_schema('user_list_schema.json') |
| 47 | + |
| 48 | +# Validate response |
| 49 | +validate(instance=response.json(), schema=schema) |
| 50 | +``` |
0 commit comments