Adding descriptions as fallback in webhooks name, Avoid webhooks folder creation when there are not any webhook in the file and includeWebhooks is true, ignoring local and global servers in webhooks

This commit is contained in:
Erik Mendoza
2022-02-10 11:29:33 -06:00
parent 110b52cc68
commit 0aaa953e35
4 changed files with 5045 additions and 3 deletions

View File

@@ -660,6 +660,10 @@ module.exports = {
variableStore = {},
webhooksVariables = [];
if (Object.keys(webhooksTree.root.children).length === 0) {
return;
}
for (let child in webhooksTree.root.children) {
if (
webhooksTree.root.children.hasOwnProperty(child) &&
@@ -2232,10 +2236,10 @@ module.exports = {
pmBody,
authMeta,
swagResponse,
localServers = _.get(operationItem, 'properties.servers'),
localServers = fromWebhooks ? '' : _.get(operationItem, 'properties.servers'),
exampleRequestBody,
sanitizeResult,
globalServers = _.get(operationItem, 'servers'),
globalServers = fromWebhooks ? '' : _.get(operationItem, 'servers'),
responseMediaTypes,
acceptHeader;
@@ -2341,7 +2345,7 @@ module.exports = {
if (fromWebhooks) {
reqName = utils.insertSpacesInName(operation.operationId) ||
operation.summary ||
`${this.cleanWebhookName(operationItem.path)} - ${operationItem.method}`;
operation.description;
}
else {
reqName = operation.summary || utils.insertSpacesInName(operation.operationId) || reqUrl;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -822,4 +822,53 @@ describe('Webhooks support', function() {
.with.length(3);
});
});
it('Should resolve correctly a file with only paths, with includeWebhooks in true',
function() {
const fileSource = path.join(__dirname, OPENAPI_31_FOLDER + '/webhooks/only-paths.yaml'),
fileData = fs.readFileSync(fileSource, 'utf8'),
input = {
type: 'string',
data: fileData
},
converter = new SchemaPack(input, { includeWebhooks: true });
converter.convert((err, result) => {
expect(err).to.be.null;
expect(result.result).to.be.true;
expect(result.output[0].data.item).to.be.an('array')
.with.length(1);
expect(result.output[0].data.item).to.be.an('array').with.length(1);
expect(result.output[0].data.item[0].name).to.equal('pets');
expect(result.output[0].data.item[0].item).to.be.an('array')
.with.length(3);
});
});
it('Should resolve correctly a file and ignore servers object in webhook, with includeWebhooks in true',
function() {
const fileSource = path.join(__dirname, OPENAPI_31_FOLDER +
'/webhooks/payments-webhook-with-servers-in-webhook.yaml'),
fileData = fs.readFileSync(fileSource, 'utf8'),
input = {
type: 'string',
data: fileData
},
converter = new SchemaPack(input, { includeWebhooks: true });
converter.convert((err, result) => {
expect(err).to.be.null;
expect(result.result).to.be.true;
expect(result.output[0].data.item).to.be.an('array')
.with.length(1);
expect(result.output[0].data.item).to.be.an('array').with.length(1);
expect(result.output[0].data.item[0].name).to.equal('Webhooks');
expect(result.output[0].data.item[0].item[0].request.url.host).to.be.an('array')
.with.length(1);
expect(result.output[0].data.item[0].item[0].request.url.host[0])
.to.be.equal('{{ACCOUNT_CLOSED}}');
expect(result.output[0].data.item[0].item).to.be.an('array')
.with.length(19);
});
});
});