53 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
const { getPluginsThatNeedDocumentation } = require('./utils/get-plugins-that-need-documentation');
module.exports = ({ strapi }) => {
2023-03-20 15:49:30 +01:00
const registeredOverrides = [];
const excludedFromGeneration = [];
2023-03-22 11:30:48 +01:00
return {
registeredOverrides,
excludedFromGeneration,
/**
*
* @param {string | string[]} api - The name of the api or and array of apis to exclude from generation
*/
excludeFromGeneration(api) {
if (Array.isArray(api)) {
excludedFromGeneration.push(...api);
2023-03-22 11:30:48 +01:00
return;
}
2023-03-22 11:30:48 +01:00
excludedFromGeneration.push(api);
},
/**
* @TODO pluginOrigin should be required in next major release
* @param {object} doc - The openapi specifcation to override
* @param {object} options - The options to override the documentation
* @param {string} options.pluginOrigin - The name of the plugin that is overriding the documentation
* @param {string[]} options.excludeFromGeneration - The name of the plugin that is overriding the documentation
*/
registerOverride(override, { pluginOrigin, excludeFromGeneration = [] }) {
const pluginsThatNeedDocumentation = getPluginsThatNeedDocumentation(
strapi.config.get('plugin.documentation')
);
// Don't apply the override if the plugin is not in the list of plugins that need documentation
if (pluginOrigin && !pluginsThatNeedDocumentation.includes(pluginOrigin)) return;
2023-03-22 11:30:48 +01:00
if (excludeFromGeneration.length) {
this.excludeFromGeneration(excludeFromGeneration);
}
2023-03-22 11:30:48 +01:00
let overrideToRegister = override;
// Parse yaml if we receive a string
if (typeof override === 'string') {
overrideToRegister = require('yaml').parse(overrideToRegister);
}
// receive an object we can register it directly
registeredOverrides.push(overrideToRegister);
},
};
};