Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions scripts/api-diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,34 +180,34 @@ function findComponentUsage(details, componentName) {

// Check parameters
if (details.parameters) {
const hasComponent = details.parameters.some(p =>
(p.$ref && schemaReferencesComponent({ $ref: p.$ref }, componentName)) ||
(p.schema && schemaReferencesComponent(p.schema, componentName))
);
const hasComponent = details.parameters.some(p => {
// Check direct parameter reference
if (p.$ref && p.$ref.includes(`/parameters/${componentName}`)) return true;
// Check schema reference if it exists
if (p.schema && p.schema.$ref && p.schema.$ref.includes(`/schemas/${componentName}`)) return true;
return false;
});
if (hasComponent) usage.push('parameters');
}

// Check requestBody
if (details.requestBody) {
let hasComponent = false;
if (details.requestBody.$ref) {
hasComponent = schemaReferencesComponent({ $ref: details.requestBody.$ref }, componentName);
if (details.requestBody.$ref && details.requestBody.$ref.includes(componentName)) {
usage.push('requestBody');
} else if (details.requestBody.content) {
hasComponent = Object.values(details.requestBody.content).some(c =>
c.schema && schemaReferencesComponent(c.schema, componentName)
);
const hasComponent = Object.values(details.requestBody.content).some(c =>
c.schema && c.schema.$ref && c.schema.$ref.includes(`/schemas/${componentName}`));
if (hasComponent) usage.push('requestBody');
}
if (hasComponent) usage.push('requestBody');
}

// Check responses
if (details.responses) {
const hasComponent = Object.entries(details.responses).some(([code, r]) => {
if (r.$ref) return schemaReferencesComponent({ $ref: r.$ref }, componentName);
if (r.content) {
return Object.values(r.content).some(c =>
c.schema && schemaReferencesComponent(c.schema, componentName)
);
const hasComponent = Object.entries(details.responses).some(([code, response]) => {
if (response.$ref && response.$ref.includes(`/responses/${componentName}`)) return true;
if (response.content) {
return Object.values(response.content).some(c =>
c.schema && c.schema.$ref && c.schema.$ref.includes(`/schemas/${componentName}`));
}
return false;
});
Expand Down
71 changes: 71 additions & 0 deletions tests/fixtures/modified-parameter-component/current.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"openapi": "3.0.0",
"info": {
"title": "Test API",
"description": "A sample API for testing"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/user/{userId}": {
"get": {
"summary": "Get a user by ID",
"parameters": [
{
"$ref": "#/components/parameters/UserId"
}
],
"responses": {
"200": {
"description": "A user object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"404": {
"description": "User not found"
}
}
}
}
},
"components": {
"parameters": {
"UserId": {
"name": "userID",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
},
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"email": {
"$ref": "#/components/schemas/Email"
}
}
},
"Email": {
"type": "string",
"format": "email"
}
}
}
}
3 changes: 3 additions & 0 deletions tests/fixtures/modified-parameter-component/expected.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Modified
- [GET] `/user/{userId}`
- `UserId` modified in parameters
71 changes: 71 additions & 0 deletions tests/fixtures/modified-parameter-component/previous.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"openapi": "3.0.0",
"info": {
"title": "Test API",
"description": "A sample API for testing"
},
"servers": [
{
"url": "https://api.example.com/v1"
}
],
"paths": {
"/user/{userId}": {
"get": {
"summary": "Get a user by ID",
"parameters": [
{
"$ref": "#/components/parameters/UserId"
}
],
"responses": {
"200": {
"description": "A user object",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
}
}
}
},
"404": {
"description": "User not found"
}
}
}
}
},
"components": {
"parameters": {
"UserId": {
"name": "userId",
"in": "path",
"required": true,
"schema": {
"type": "string"
}
}
},
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
},
"email": {
"$ref": "#/components/schemas/Email"
}
}
},
"Email": {
"type": "string",
"format": "email"
}
}
}
}
Loading