Setup spotlight project
This commit is contained in:
50
.stoplight/custom-functions/oasUnusedComponent.js
Normal file
50
.stoplight/custom-functions/oasUnusedComponent.js
Normal file
@@ -0,0 +1,50 @@
|
||||
import { unreferencedReusableObject } from '@stoplight/spectral-functions';
|
||||
import { createRulesetFunction } from '@stoplight/spectral-core';
|
||||
|
||||
function isObject(value) {
|
||||
return value !== null && typeof value === 'object';
|
||||
}
|
||||
|
||||
export default createRulesetFunction(
|
||||
{
|
||||
input: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
components: {
|
||||
type: 'object',
|
||||
},
|
||||
},
|
||||
required: ['components'],
|
||||
},
|
||||
options: null,
|
||||
},
|
||||
function oasUnusedComponent(targetVal, opts, context) {
|
||||
const results = [];
|
||||
const componentTypes = [
|
||||
'schemas',
|
||||
'responses',
|
||||
'parameters',
|
||||
'examples',
|
||||
'requestBodies',
|
||||
'headers',
|
||||
'links',
|
||||
'callbacks',
|
||||
];
|
||||
|
||||
for (const type of componentTypes) {
|
||||
const value = targetVal.components[type];
|
||||
if (!isObject(value)) continue;
|
||||
|
||||
const resultsForType = unreferencedReusableObject(
|
||||
value,
|
||||
{ reusableObjectsLocation: `#/components/${type}` },
|
||||
context,
|
||||
);
|
||||
if (resultsForType !== void 0 && Array.isArray(resultsForType)) {
|
||||
results.push(...resultsForType);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user