diff --git a/python-schema-match/README.md b/python-schema-match/README.md index 8fa1497..5c11156 100644 --- a/python-schema-match/README.md +++ b/python-schema-match/README.md @@ -1,4 +1,4 @@ -# Python Schema Match +# Python Schema Match A sample HTTP server application designed to test and validate JSON schema matching capabilities with Keploy. This application serves multiple diverse endpoints with various response schemas to comprehensively test schema structure validation and compatibility. diff --git a/python-schema-match/app-test.py b/python-schema-match/app-test.py index 7442ebe..c10e101 100644 --- a/python-schema-match/app-test.py +++ b/python-schema-match/app-test.py @@ -89,6 +89,32 @@ # 10. PASS: Exact match '/edge/nested_null': { "data": {"value": None} + }, + + # 11. FAIL: Complex User (Type mismatch + Missing nested key) + '/complex/user': { + "id": "500", # FAIL: Expected int, got string + "name": "Jane Doe", + "contact": { + "email": "jane@example.com" + # FAIL: Missing "phone" key + }, + "tags": ["vip", "early-adopter"], + "metadata": { + "created_at": "2023-01-01T00:00:00Z", + "login_count": 42 + } + }, + + # 12. FAIL: Complex Product (Array item mismatch) + '/complex/product': { + "sku": "XYZ-999", + "specs": [ + {"key": "weight", "value": "1.5kg", "unit": "kg"}, # FAIL: value expected float, got string + {"key": "warranty", "value": 2, "unit": "years"} + ], + "in_stock": True, + "dimensions": [10, "20", 5.5] # FAIL: 2nd element expected int/float, got string } } @@ -127,7 +153,7 @@ def handle_request(client_socket): else: body = json.dumps(body_data) - response = f"HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nContent-Length: {len(body)}\r\n\r\n{body}" + response = f"HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nContent-Length: {len(body)}\r\nConnection: close\r\n\r\n{body}" client_socket.sendall(response.encode('utf-8')) except Exception as e: diff --git a/python-schema-match/app.py b/python-schema-match/app.py index b160d94..5d98c28 100644 --- a/python-schema-match/app.py +++ b/python-schema-match/app.py @@ -65,6 +65,28 @@ # Added 10th endpoint for clean 7/3 split '/edge/nested_null': { "data": {"value": None} + }, + '/complex/user': { + "id": 500, + "name": "Jane Doe", + "contact": { + "email": "jane@example.com", + "phone": {"home": "555-0123", "mobile": "555-0987"} + }, + "tags": ["vip", "early-adopter"], + "metadata": { + "created_at": "2023-01-01T00:00:00Z", + "login_count": 42 + } + }, + '/complex/product': { + "sku": "XYZ-999", + "specs": [ + {"key": "weight", "value": 1.5, "unit": "kg"}, + {"key": "warranty", "value": 2, "unit": "years"} + ], + "in_stock": True, + "dimensions": [10, 20, 5.5] } } diff --git a/python-schema-match/check-endpoints.py b/python-schema-match/check-endpoints.py index d64180b..219bb73 100644 --- a/python-schema-match/check-endpoints.py +++ b/python-schema-match/check-endpoints.py @@ -13,7 +13,9 @@ '/edge/empty_response', '/edge/null_root', '/edge/special_chars', - '/edge/nested_null' + '/edge/nested_null', + '/complex/user', + '/complex/product' ] def check_endpoints():