Skip to content

Commit 9d449dc

Browse files
Merge pull request #30 from BitGo/fix-parameter-change-detection
fix: fixed an issue with component change in parameter not showing up correctly
2 parents aae01fc + a0c369b commit 9d449dc

File tree

4 files changed

+162
-17
lines changed

4 files changed

+162
-17
lines changed

scripts/api-diff.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -180,34 +180,34 @@ function findComponentUsage(details, componentName) {
180180

181181
// Check parameters
182182
if (details.parameters) {
183-
const hasComponent = details.parameters.some(p =>
184-
(p.$ref && schemaReferencesComponent({ $ref: p.$ref }, componentName)) ||
185-
(p.schema && schemaReferencesComponent(p.schema, componentName))
186-
);
183+
const hasComponent = details.parameters.some(p => {
184+
// Check direct parameter reference
185+
if (p.$ref && p.$ref.includes(`/parameters/${componentName}`)) return true;
186+
// Check schema reference if it exists
187+
if (p.schema && p.schema.$ref && p.schema.$ref.includes(`/schemas/${componentName}`)) return true;
188+
return false;
189+
});
187190
if (hasComponent) usage.push('parameters');
188191
}
189192

190193
// Check requestBody
191194
if (details.requestBody) {
192-
let hasComponent = false;
193-
if (details.requestBody.$ref) {
194-
hasComponent = schemaReferencesComponent({ $ref: details.requestBody.$ref }, componentName);
195+
if (details.requestBody.$ref && details.requestBody.$ref.includes(componentName)) {
196+
usage.push('requestBody');
195197
} else if (details.requestBody.content) {
196-
hasComponent = Object.values(details.requestBody.content).some(c =>
197-
c.schema && schemaReferencesComponent(c.schema, componentName)
198-
);
198+
const hasComponent = Object.values(details.requestBody.content).some(c =>
199+
c.schema && c.schema.$ref && c.schema.$ref.includes(`/schemas/${componentName}`));
200+
if (hasComponent) usage.push('requestBody');
199201
}
200-
if (hasComponent) usage.push('requestBody');
201202
}
202203

203204
// Check responses
204205
if (details.responses) {
205-
const hasComponent = Object.entries(details.responses).some(([code, r]) => {
206-
if (r.$ref) return schemaReferencesComponent({ $ref: r.$ref }, componentName);
207-
if (r.content) {
208-
return Object.values(r.content).some(c =>
209-
c.schema && schemaReferencesComponent(c.schema, componentName)
210-
);
206+
const hasComponent = Object.entries(details.responses).some(([code, response]) => {
207+
if (response.$ref && response.$ref.includes(`/responses/${componentName}`)) return true;
208+
if (response.content) {
209+
return Object.values(response.content).some(c =>
210+
c.schema && c.schema.$ref && c.schema.$ref.includes(`/schemas/${componentName}`));
211211
}
212212
return false;
213213
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Test API",
5+
"description": "A sample API for testing"
6+
},
7+
"servers": [
8+
{
9+
"url": "https://api.example.com/v1"
10+
}
11+
],
12+
"paths": {
13+
"/user/{userId}": {
14+
"get": {
15+
"summary": "Get a user by ID",
16+
"parameters": [
17+
{
18+
"$ref": "#/components/parameters/UserId"
19+
}
20+
],
21+
"responses": {
22+
"200": {
23+
"description": "A user object",
24+
"content": {
25+
"application/json": {
26+
"schema": {
27+
"$ref": "#/components/schemas/User"
28+
}
29+
}
30+
}
31+
},
32+
"404": {
33+
"description": "User not found"
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"components": {
40+
"parameters": {
41+
"UserId": {
42+
"name": "userID",
43+
"in": "path",
44+
"required": true,
45+
"schema": {
46+
"type": "string"
47+
}
48+
}
49+
},
50+
"schemas": {
51+
"User": {
52+
"type": "object",
53+
"properties": {
54+
"id": {
55+
"type": "string"
56+
},
57+
"name": {
58+
"type": "string"
59+
},
60+
"email": {
61+
"$ref": "#/components/schemas/Email"
62+
}
63+
}
64+
},
65+
"Email": {
66+
"type": "string",
67+
"format": "email"
68+
}
69+
}
70+
}
71+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Modified
2+
- [GET] `/user/{userId}`
3+
- `UserId` modified in parameters
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"title": "Test API",
5+
"description": "A sample API for testing"
6+
},
7+
"servers": [
8+
{
9+
"url": "https://api.example.com/v1"
10+
}
11+
],
12+
"paths": {
13+
"/user/{userId}": {
14+
"get": {
15+
"summary": "Get a user by ID",
16+
"parameters": [
17+
{
18+
"$ref": "#/components/parameters/UserId"
19+
}
20+
],
21+
"responses": {
22+
"200": {
23+
"description": "A user object",
24+
"content": {
25+
"application/json": {
26+
"schema": {
27+
"$ref": "#/components/schemas/User"
28+
}
29+
}
30+
}
31+
},
32+
"404": {
33+
"description": "User not found"
34+
}
35+
}
36+
}
37+
}
38+
},
39+
"components": {
40+
"parameters": {
41+
"UserId": {
42+
"name": "userId",
43+
"in": "path",
44+
"required": true,
45+
"schema": {
46+
"type": "string"
47+
}
48+
}
49+
},
50+
"schemas": {
51+
"User": {
52+
"type": "object",
53+
"properties": {
54+
"id": {
55+
"type": "string"
56+
},
57+
"name": {
58+
"type": "string"
59+
},
60+
"email": {
61+
"$ref": "#/components/schemas/Email"
62+
}
63+
}
64+
},
65+
"Email": {
66+
"type": "string",
67+
"format": "email"
68+
}
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)