Skip to content

Commit 571a7a1

Browse files
committed
fix: fix issue with some changed sections not listed properly
1 parent 4979026 commit 571a7a1

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-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
});

0 commit comments

Comments
 (0)