Skip to content

Commit b2c788e

Browse files
kevinccbsgclaude
andcommitted
feat: add contract testing with OpenAPI spec for Todos API
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a1f2f09 commit b2c788e

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

contracts/todos-3.0.json

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Todos API",
5+
"version": "1.0.0"
6+
},
7+
"paths": {
8+
"/todos": {
9+
"get": {
10+
"operationId": "getTodos",
11+
"responses": {
12+
"200": {
13+
"description": "List of todos",
14+
"content": {
15+
"application/json": {
16+
"schema": {
17+
"type": "array",
18+
"items": {
19+
"$ref": "#/components/schemas/Todo"
20+
}
21+
}
22+
}
23+
}
24+
}
25+
}
26+
},
27+
"post": {
28+
"operationId": "createTodo",
29+
"requestBody": {
30+
"required": true,
31+
"content": {
32+
"application/json": {
33+
"schema": {
34+
"$ref": "#/components/schemas/NewTodo"
35+
}
36+
}
37+
}
38+
},
39+
"responses": {
40+
"200": {
41+
"description": "Created todo",
42+
"content": {
43+
"application/json": {
44+
"schema": {
45+
"$ref": "#/components/schemas/Todo"
46+
}
47+
}
48+
}
49+
}
50+
}
51+
}
52+
},
53+
"/todos/{id}": {
54+
"delete": {
55+
"operationId": "deleteTodo",
56+
"parameters": [
57+
{
58+
"name": "id",
59+
"in": "path",
60+
"required": true,
61+
"schema": {
62+
"type": "string"
63+
}
64+
}
65+
],
66+
"responses": {
67+
"200": {
68+
"description": "Todo deleted"
69+
}
70+
}
71+
}
72+
}
73+
},
74+
"components": {
75+
"schemas": {
76+
"Todo": {
77+
"type": "object",
78+
"required": ["id", "title", "description", "date"],
79+
"properties": {
80+
"id": {
81+
"type": "string"
82+
},
83+
"title": {
84+
"type": "string"
85+
},
86+
"description": {
87+
"type": "string"
88+
},
89+
"date": {
90+
"type": "string"
91+
}
92+
}
93+
},
94+
"NewTodo": {
95+
"type": "object",
96+
"required": ["title", "description", "date"],
97+
"properties": {
98+
"title": {
99+
"type": "string"
100+
},
101+
"description": {
102+
"type": "string"
103+
},
104+
"date": {
105+
"type": "string"
106+
}
107+
}
108+
}
109+
}
110+
}
111+
}

twd.config.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"url": "http://localhost:5173",
3+
"contractReportPath": ".twd/contract-report.md",
4+
"contracts": [
5+
{
6+
"source": "./contracts/todos-3.0.json",
7+
"baseUrl": "/api",
8+
"mode": "error",
9+
"strict": true
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)