openapi-spec-master
Version:
🚀 Professional OpenAPI specification analyzer and MCP server. The ultimate toolkit for API developers with VS Code extension integration.
61 lines (60 loc) • 2.35 kB
JavaScript
export function generateAnalytics(endpoints) {
const methodDistribution = {};
const tagDistribution = {};
const complexityDistribution = {};
const responseCodeDistribution = {};
const securitySchemes = new Set();
const pathPatterns = new Set();
let deprecatedCount = 0;
let totalParameters = 0;
endpoints.forEach(endpoint => {
// Method distribution
methodDistribution[endpoint.method] = (methodDistribution[endpoint.method] || 0) + 1;
// Tag distribution
endpoint.tags.forEach(tag => {
tagDistribution[tag] = (tagDistribution[tag] || 0) + 1;
});
// Complexity distribution
const complexity = endpoint.complexity || 'medium';
complexityDistribution[complexity] = (complexityDistribution[complexity] || 0) + 1;
// Response code distribution
Object.keys(endpoint.responses).forEach(code => {
responseCodeDistribution[code] = (responseCodeDistribution[code] || 0) + 1;
});
// Security schemes
if (endpoint.security) {
endpoint.security.forEach(sec => {
Object.keys(sec).forEach(scheme => {
securitySchemes.add(scheme);
});
});
}
// Path patterns
const pathSegments = endpoint.path.split('/').filter(Boolean);
if (pathSegments.length > 0) {
// Extract base path pattern
const basePattern = `/${pathSegments[0]}`;
pathPatterns.add(basePattern);
// Extract common patterns
const pattern = endpoint.path.replace(/\{[^}]+\}/g, '{id}');
pathPatterns.add(pattern);
}
// Count deprecated
if (endpoint.deprecated) {
deprecatedCount++;
}
// Count parameters
totalParameters += endpoint.parameters.length;
});
return {
totalEndpoints: endpoints.length,
methodDistribution,
tagDistribution,
complexityDistribution,
deprecatedCount,
securitySchemes: Array.from(securitySchemes),
averageParametersPerEndpoint: endpoints.length > 0 ? totalParameters / endpoints.length : 0,
pathPatterns: Array.from(pathPatterns).slice(0, 20), // Limit to top 20 patterns
responseCodeDistribution
};
}