diff --git a/examples/extensions/extensions.spec.js b/examples/extensions/extensions.spec.js index 4479cbae..7001a7fc 100644 --- a/examples/extensions/extensions.spec.js +++ b/examples/extensions/extensions.spec.js @@ -1,8 +1,9 @@ const swaggerJsdoc = require('../..'); -const referenceSpecification = require('./reference-specification.json'); +const webhooksSingleSpecification = require('./x-webhooks-single-reference-specification.json'); +const webhooksMultipleSpecification = require('./x-webhooks-multiple-reference-specification.json'); describe('Example for using extensions', () => { - it('should support x-webhooks', () => { + it('should support single entry in x-webhooks', () => { const result = swaggerJsdoc({ swaggerDefinition: { info: { @@ -10,8 +11,21 @@ describe('Example for using extensions', () => { version: '0.0.1', }, }, - apis: ['./examples/extensions/example.js'], + apis: ['./examples/extensions/x-webhooks-single.js'], }); - expect(result).toEqual(referenceSpecification); + expect(result).toEqual(webhooksSingleSpecification); + }); + + it('should support multiple entries in x-webhooks', () => { + const result = swaggerJsdoc({ + swaggerDefinition: { + info: { + title: 'Example with extensions', + version: '0.0.1', + }, + }, + apis: ['./examples/extensions/x-webhooks-multiple.js'], + }); + expect(result).toEqual(webhooksMultipleSpecification); }); }); diff --git a/examples/extensions/x-webhooks-multiple-reference-specification.json b/examples/extensions/x-webhooks-multiple-reference-specification.json new file mode 100644 index 00000000..6f7d73d5 --- /dev/null +++ b/examples/extensions/x-webhooks-multiple-reference-specification.json @@ -0,0 +1,48 @@ +{ + "info": { "title": "Example with extensions", "version": "0.0.1" }, + "swagger": "2.0", + "paths": {}, + "definitions": {}, + "responses": {}, + "parameters": {}, + "securityDefinitions": {}, + "tags": [], + "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" + } + } + } + }, + "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" + } + } + } + } + } +} diff --git a/examples/extensions/x-webhooks-multiple.js b/examples/extensions/x-webhooks-multiple.js new file mode 100644 index 00000000..eacf9b33 --- /dev/null +++ b/examples/extensions/x-webhooks-multiple.js @@ -0,0 +1,41 @@ +/* istanbul ignore file */ + +/** + * Example of cat + * + * @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 of dog + * + * @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 + */ diff --git a/examples/extensions/reference-specification.json b/examples/extensions/x-webhooks-single-reference-specification.json similarity index 100% rename from examples/extensions/reference-specification.json rename to examples/extensions/x-webhooks-single-reference-specification.json diff --git a/examples/extensions/example.js b/examples/extensions/x-webhooks-single.js similarity index 100% rename from examples/extensions/example.js rename to examples/extensions/x-webhooks-single.js diff --git a/src/specification.js b/src/specification.js index bf0dedb1..9eaf1172 100644 --- a/src/specification.js +++ b/src/specification.js @@ -128,7 +128,10 @@ function organize(swaggerObject, annotation, property) { // Root property on purpose. // @see https://github.com/OAI/OpenAPI-Specification/blob/master/proposals/002_Webhooks.md#proposed-solution if (property === 'x-webhooks') { - swaggerObject[property] = annotation[property]; + swaggerObject[property] = mergeDeep( + swaggerObject[property], + annotation[property] + ); } // Other extensions can be in varying places depending on different vendors and opinions.