52 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 excludedApisAndPlugins = [];
/**
*
* @param {string | string[]} api - The name of the api or and array of apis to exclude from generation
*/
const excludeFromGeneration = (api) => {
excludedApisAndPlugins.concat(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
*/
const 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-20 15:49:30 +01:00
if (excludeFromGeneration.length) {
strapi
.plugin('documentation')
.service('override')
.excludeFromGeneration(excludeFromGeneration);
}
2023-03-20 15:49:30 +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);
};
2023-03-20 15:49:30 +01:00
return {
registeredOverrides,
registerOverride,
excludeFromGeneration,
excludedApisAndPlugins,
};
};