x-webhooks generates only one entry in resulting JSON
aleksey-a-maltsev opened this issue · 0 comments
aleksey-a-maltsev commented
Describe the bug
I have more than one 'x-webhooks' entries in swagger files. After compilation only one webhook remains in resulting JSON.
To Reproduce
- Create swagger file with 2 or more 'x-webhhoks' sections
- Run compilation
- Check the 'x-webhooks' section in result JSON - it contains only latest webhook information
Expected behavior
'x-webhooks' section contains all the webhooks from source YAMLs.
Desktop:
- MaOS 12.6
- Node 18.0.0
- swagger-jsdoc@6.2.5
Additional context
YAML example:
// wh-example.js
/**
* Example 1
*
* @swagger
* x-webhooks:
* newCat:
* post:
* description: Information about a new cat in the systems
* tags:
* - pet
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/Cat"
* responses:
* "200":
* description: Return a 200 status to indicate that the data was received successfully
*/
/**
* Example 2
*
* @swagger
* x-webhooks:
* newDog:
* post:
* description: Information about a new dog in the systems
* tags:
* - pet
* requestBody:
* content:
* application/json:
* schema:
* $ref: "#/components/schemas/Dog"
* responses:
* "200":
* description: Return a 200 status to indicate that the data was received successfully
*/
Executable code example:
// wh-compile.js
const swaggerJsDoc = require('swagger-jsdoc')
const result = swaggerJsDoc({
swaggerDefinition: {
info: {
title: 'Example with extensions',
version: '0.0.1'
}
},
apis: ['./wh-example.js']
})
console.assert(result['x-webhooks'].newCat, 'Cat is here')
console.assert(result['x-webhooks'].newDog, 'Dog is here')
console.log(result['x-webhooks'])
Command:
node wh-compile
Current result:
Assertion failed: Cat is here
{
newDog: {
post: {
description: 'Information about a new dog in the systems',
tags: [Array],
requestBody: [Object],
responses: [Object]
}
}
}
Expected result:
{
newCat: {
post: {
description: 'Information about a new cat in the systems',
tags: [Array],
requestBody: [Object],
responses: [Object]
}
},
newDog: {
post: {
description: 'Information about a new dog in the systems',
tags: [Array],
requestBody: [Object],
responses: [Object]
}
}
}
Hints
Where the problem is:
specification.js
swaggerObject[property] = annotation[property];
How to fix it:
swaggerObject[property] = mergeDeep(
swaggerObject[property],
annotation[property]
)