Skip to content

Commit 5600473

Browse files
Merge pull request #39 from BitGo/fix-section-identification
fix: fix issue with some changed sections not listed properly
2 parents b5134f1 + dc5589a commit 5600473

File tree

4 files changed

+192
-5
lines changed

4 files changed

+192
-5
lines changed

scripts/api-diff.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,13 @@ function schemaReferencesComponent(schema, componentName, visitedRefs = new Set(
170170
if (schema.items && schemaReferencesComponent(schema.items, componentName, visitedRefs)) {
171171
return true;
172172
}
173+
174+
// Check additionalProperties
175+
if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
176+
if (schemaReferencesComponent(schema.additionalProperties, componentName, visitedRefs)) {
177+
return true;
178+
}
179+
}
173180

174181
return false;
175182
}
@@ -184,7 +191,10 @@ function findComponentUsage(details, componentName) {
184191
// Check direct parameter reference
185192
if (p.$ref && p.$ref.includes(`/parameters/${componentName}`)) return true;
186193
// Check schema reference if it exists
187-
if (p.schema && p.schema.$ref && p.schema.$ref.includes(`/schemas/${componentName}`)) return true;
194+
if (p.schema && schemaReferencesComponent(p.schema, componentName)) return true;
195+
// Check examples
196+
if (p.examples && Object.values(p.examples).some(e =>
197+
e.$ref && e.$ref.includes(`/examples/${componentName}`))) return true;
188198
return false;
189199
});
190200
if (hasComponent) usage.push('parameters');
@@ -195,8 +205,12 @@ function findComponentUsage(details, componentName) {
195205
if (details.requestBody.$ref && details.requestBody.$ref.includes(componentName)) {
196206
usage.push('requestBody');
197207
} else if (details.requestBody.content) {
198-
const hasComponent = Object.values(details.requestBody.content).some(c =>
199-
c.schema && c.schema.$ref && c.schema.$ref.includes(`/schemas/${componentName}`));
208+
const hasComponent = Object.values(details.requestBody.content).some(c => {
209+
if (c.schema && schemaReferencesComponent(c.schema, componentName)) return true;
210+
if (c.examples && Object.values(c.examples).some(e =>
211+
e.$ref && e.$ref.includes(`/examples/${componentName}`))) return true;
212+
return false;
213+
});
200214
if (hasComponent) usage.push('requestBody');
201215
}
202216
}
@@ -206,8 +220,16 @@ function findComponentUsage(details, componentName) {
206220
const hasComponent = Object.entries(details.responses).some(([code, response]) => {
207221
if (response.$ref && response.$ref.includes(`/responses/${componentName}`)) return true;
208222
if (response.content) {
209-
return Object.values(response.content).some(c =>
210-
c.schema && c.schema.$ref && c.schema.$ref.includes(`/schemas/${componentName}`));
223+
return Object.values(response.content).some(c => {
224+
if (c.schema && schemaReferencesComponent(c.schema, componentName)) return true;
225+
if (c.examples && Object.values(c.examples).some(e =>
226+
e.$ref && e.$ref.includes(`/examples/${componentName}`))) return true;
227+
return false;
228+
});
229+
}
230+
if (response.headers) {
231+
return Object.values(response.headers).some(h =>
232+
schemaReferencesComponent(h.schema, componentName));
211233
}
212234
return false;
213235
});
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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/{id}": {
14+
"get": {
15+
"summary": "Get user by ID",
16+
"parameters": [
17+
{
18+
"$ref": "#/components/parameters/StringUserId"
19+
},
20+
{
21+
"$ref": "#/components/parameters/NumberUserId"
22+
}
23+
],
24+
"responses": {
25+
"200": {
26+
"description": "User found",
27+
"content": {
28+
"application/json": {
29+
"schema": {
30+
"type": "object",
31+
"properties": {
32+
"userCreated": {
33+
"type": "array",
34+
"items": {
35+
"$ref": "#/components/schemas/User"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
},
47+
"components": {
48+
"parameters": {
49+
"StringUserId": {
50+
"type": "string",
51+
"description": "The unique identifier for a user",
52+
"example": 1234
53+
},
54+
"NumberUserId": {
55+
"type": "number",
56+
"description": "The unique identifier for a user",
57+
"example": 1234
58+
}
59+
},
60+
"schemas": {
61+
"User": {
62+
"type": "object",
63+
"properties": {
64+
"id": {
65+
"type": "string"
66+
},
67+
"name": {
68+
"type": "string"
69+
},
70+
"email": {
71+
"$ref": "#/components/schemas/Email"
72+
}
73+
}
74+
},
75+
"Email": {
76+
"type": "string",
77+
"format": "email"
78+
}
79+
}
80+
}
81+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Modified
2+
- [GET] `/user/{id}`
3+
- `NumberUserId` modified in parameters
4+
- `User` modified in responses
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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/{id}": {
14+
"get": {
15+
"summary": "Get user by ID",
16+
"parameters": [
17+
{
18+
"$ref": "#/components/parameters/StringUserId"
19+
},
20+
{
21+
"$ref": "#/components/parameters/NumberUserId"
22+
}
23+
],
24+
"responses": {
25+
"200": {
26+
"description": "User found",
27+
"content": {
28+
"application/json": {
29+
"schema": {
30+
"type": "object",
31+
"properties": {
32+
"userCreated": {
33+
"type": "array",
34+
"items": {
35+
"$ref": "#/components/schemas/User"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
}
46+
},
47+
"components": {
48+
"parameters": {
49+
"StringUserId": {
50+
"type": "string",
51+
"description": "The unique identifier for a user",
52+
"example": 1234
53+
},
54+
"NumberUserId": {
55+
"type": "number",
56+
"description": "The unique identifier for a user",
57+
"example": 12345
58+
}
59+
},
60+
"schemas": {
61+
"User": {
62+
"type": "object",
63+
"properties": {
64+
"id": {
65+
"type": "string"
66+
},
67+
"name": {
68+
"type": "string"
69+
},
70+
"email": {
71+
"$ref": "#/components/schemas/Email"
72+
}
73+
}
74+
},
75+
"Email": {
76+
"type": "string"
77+
}
78+
}
79+
}
80+
}

0 commit comments

Comments
 (0)