Skip to content

Commit 57856de

Browse files
feat: Keploy schema-match sample app (#99)
* feat: Keploy schema-match sample app Signed-off-by: Harshit Pathak <harshit07pathak@gmail.com> * feat: added read me file Signed-off-by: Harshit Pathak <harshit07pathak@gmail.com> * fix(sample-app): add connection header to response in python-schema-match * Added few more testcases * commit test --------- Signed-off-by: Harshit Pathak <harshit07pathak@gmail.com>
1 parent 9a6c336 commit 57856de

4 files changed

Lines changed: 53 additions & 3 deletions

File tree

python-schema-match/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Python Schema Match
1+
# Python Schema Match
22

33
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.
44

python-schema-match/app-test.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,32 @@
8989
# 10. PASS: Exact match
9090
'/edge/nested_null': {
9191
"data": {"value": None}
92+
},
93+
94+
# 11. FAIL: Complex User (Type mismatch + Missing nested key)
95+
'/complex/user': {
96+
"id": "500", # FAIL: Expected int, got string
97+
"name": "Jane Doe",
98+
"contact": {
99+
"email": "jane@example.com"
100+
# FAIL: Missing "phone" key
101+
},
102+
"tags": ["vip", "early-adopter"],
103+
"metadata": {
104+
"created_at": "2023-01-01T00:00:00Z",
105+
"login_count": 42
106+
}
107+
},
108+
109+
# 12. FAIL: Complex Product (Array item mismatch)
110+
'/complex/product': {
111+
"sku": "XYZ-999",
112+
"specs": [
113+
{"key": "weight", "value": "1.5kg", "unit": "kg"}, # FAIL: value expected float, got string
114+
{"key": "warranty", "value": 2, "unit": "years"}
115+
],
116+
"in_stock": True,
117+
"dimensions": [10, "20", 5.5] # FAIL: 2nd element expected int/float, got string
92118
}
93119
}
94120

@@ -127,7 +153,7 @@ def handle_request(client_socket):
127153
else:
128154
body = json.dumps(body_data)
129155

130-
response = f"HTTP/1.0 200 OK\r\nContent-Type: application/json\r\nContent-Length: {len(body)}\r\n\r\n{body}"
156+
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}"
131157
client_socket.sendall(response.encode('utf-8'))
132158

133159
except Exception as e:

python-schema-match/app.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,28 @@
6565
# Added 10th endpoint for clean 7/3 split
6666
'/edge/nested_null': {
6767
"data": {"value": None}
68+
},
69+
'/complex/user': {
70+
"id": 500,
71+
"name": "Jane Doe",
72+
"contact": {
73+
"email": "jane@example.com",
74+
"phone": {"home": "555-0123", "mobile": "555-0987"}
75+
},
76+
"tags": ["vip", "early-adopter"],
77+
"metadata": {
78+
"created_at": "2023-01-01T00:00:00Z",
79+
"login_count": 42
80+
}
81+
},
82+
'/complex/product': {
83+
"sku": "XYZ-999",
84+
"specs": [
85+
{"key": "weight", "value": 1.5, "unit": "kg"},
86+
{"key": "warranty", "value": 2, "unit": "years"}
87+
],
88+
"in_stock": True,
89+
"dimensions": [10, 20, 5.5]
6890
}
6991
}
7092

python-schema-match/check-endpoints.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
'/edge/empty_response',
1414
'/edge/null_root',
1515
'/edge/special_chars',
16-
'/edge/nested_null'
16+
'/edge/nested_null',
17+
'/complex/user',
18+
'/complex/product'
1719
]
1820

1921
def check_endpoints():

0 commit comments

Comments
 (0)