mirror of
https://github.com/strapi/strapi.git
synced 2025-11-03 11:25:17 +00:00
Test excludeFromGeneration and customizer
This commit is contained in:
parent
da3b4ed42d
commit
f8a631d84e
@ -319,5 +319,50 @@ describe('Documentation service', () => {
|
||||
'test-new-component'
|
||||
);
|
||||
});
|
||||
it('excludes apis and plugins from generation', async () => {
|
||||
const overrideService = override({ strapi: global.strapi });
|
||||
|
||||
overrideService.excludeFromGeneration('kitchensink');
|
||||
|
||||
global.strapi.plugins.documentation = {
|
||||
service: jest.fn((name) => {
|
||||
const mockServices = {
|
||||
override: overrideService,
|
||||
};
|
||||
|
||||
return mockServices[name];
|
||||
}),
|
||||
};
|
||||
|
||||
const docService = documentation({ strapi: global.strapi });
|
||||
await docService.generateFullDoc();
|
||||
const lastMockCall = fse.writeJson.mock.calls[fse.writeJson.mock.calls.length - 1];
|
||||
const mockFinalDoc = lastMockCall[1];
|
||||
|
||||
expect(
|
||||
Object.keys(mockFinalDoc.paths).find((path) => path.includes('kitchensink'))
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
Object.keys(mockFinalDoc.components.schemas).find((compo) => compo.includes('Kitchensink'))
|
||||
).toBeUndefined();
|
||||
});
|
||||
it("applies a user's customizer function", async () => {
|
||||
global.strapi.config.get = () => ({
|
||||
...defaultConfig,
|
||||
'x-strapi-config': {
|
||||
...defaultConfig['x-strapi-config'],
|
||||
customizer(draft) {
|
||||
draft.paths['/kitchensinks'] = { get: { responses: { 200: { description: 'test' } } } };
|
||||
},
|
||||
},
|
||||
});
|
||||
const docService = documentation({ strapi: global.strapi });
|
||||
await docService.generateFullDoc();
|
||||
const lastMockCall = fse.writeJson.mock.calls[fse.writeJson.mock.calls.length - 1];
|
||||
const mockFinalDoc = lastMockCall[1];
|
||||
expect(mockFinalDoc.paths['/kitchensinks']).toEqual({
|
||||
get: { responses: { 200: { description: 'test' } } },
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -138,8 +138,9 @@ module.exports = ({ strapi }) => {
|
||||
let paths = {};
|
||||
let schemas = {};
|
||||
const apis = this.getPluginAndApiInfo();
|
||||
|
||||
const apisThatNeedGeneratedDocumentation = apis.filter(
|
||||
({ name }) => !overrideService.excludedApisAndPlugins.includes(name)
|
||||
({ name }) => !overrideService.excludedFromGeneration.includes(name)
|
||||
);
|
||||
for (const api of apisThatNeedGeneratedDocumentation) {
|
||||
const apiName = api.name;
|
||||
|
||||
@ -4,13 +4,19 @@ const { getPluginsThatNeedDocumentation } = require('./utils/get-plugins-that-ne
|
||||
|
||||
module.exports = ({ strapi }) => {
|
||||
const registeredOverrides = [];
|
||||
const excludedApisAndPlugins = [];
|
||||
const excludedFromGeneration = [];
|
||||
/**
|
||||
*
|
||||
* @param {string | string[]} api - The name of the api or and array of apis to exclude from generation
|
||||
*/
|
||||
const excludeFromGeneration = (api) => {
|
||||
excludedApisAndPlugins.concat(api);
|
||||
if (Array.isArray(api)) {
|
||||
excludedFromGeneration.push(...api);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
excludedFromGeneration.push(api);
|
||||
};
|
||||
/**
|
||||
* @TODO pluginOrigin should be required in next major release
|
||||
@ -46,6 +52,6 @@ module.exports = ({ strapi }) => {
|
||||
registeredOverrides,
|
||||
registerOverride,
|
||||
excludeFromGeneration,
|
||||
excludedApisAndPlugins,
|
||||
excludedFromGeneration,
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user