Repository: BRIKEV/express-jsdoc-swagger
Pull request #149 (2021-04-17 22:36:24)

Feat/expose transform methods
### What kind of change does this PR introduce? (check at least one)
 - [x] Feature
 - [x] Test

### Description:
This PR includes ->  Transforms `getPaths`, `getComponents`, `getTags` and also the consumer `jsdocInfo` are exposed.


Patch:
diff --git a/index.js b/index.js
index 359955b..6084c59 100644
--- a/index.js
+++ b/index.js
@@ -19,10 +19,15 @@ const expressJSDocSwagger = app => (userOptions = {}, userSwagger = {}) => {
     .then(result => {
       swaggerObject = {
         ...swaggerObject,
-        ...result,
+        ...result.swaggerObject,
       };
       swaggerObject = merge.recursive(true, swaggerObject, userSwagger);
-      events.finish(swaggerObject);
+      events.finish(swaggerObject, {
+        jsdocInfo: result.jsdocInfo,
+        getPaths: result.getPaths,
+        getComponents: result.getComponents,
+        getTags: result.getTags,
+      });
     })
     .catch(events.error);
 
diff --git a/processSwagger.js b/processSwagger.js
index aafa8dd..f441bd1 100644
--- a/processSwagger.js
+++ b/processSwagger.js
@@ -36,7 +36,9 @@ const processSwagger = (options, logger = defaultLogger) => {
       logger({ entity: 'components', swaggerObject });
       swaggerObject = getTags(swaggerObject, data);
       logger({ entity: 'tags', swaggerObject });
-      return swaggerObject;
+      return {
+        swaggerObject, jsdocInfo, getPaths, getComponents, getTags,
+      };
     });
 };
 
diff --git a/swaggerEvents.js b/swaggerEvents.js
index ba1e347..2067e51 100644
--- a/swaggerEvents.js
+++ b/swaggerEvents.js
@@ -14,8 +14,8 @@ const processFile = eventEmitter => info => (
   eventEmitter.emit(PROCESS_EVENT_NAME, info)
 );
 
-const finish = eventEmitter => info => (
-  eventEmitter.emit(FINISH_EVENT_NAME, info)
+const finish = eventEmitter => (info, methods) => (
+  eventEmitter.emit(FINISH_EVENT_NAME, info, methods)
 );
 
 const swaggerEvents = () => {


Test patch:
diff --git a/test/e2e/components/components.test.js b/test/e2e/components/components.test.js
index 9fd2a56..828750a 100644
--- a/test/e2e/components/components.test.js
+++ b/test/e2e/components/components.test.js
@@ -86,5 +86,5 @@ test('should parse components jsdoc from jsdoc-example', async () => {
     },
   };
   const result = await processSwagger(options);
-  expect(result).toEqual(expected);
+  expect(result.swaggerObject).toEqual(expected);
 });
diff --git a/test/e2e/configuration/configuration.test.js b/test/e2e/configuration/configuration.test.js
index fcf1bc6..a2311c3 100644
--- a/test/e2e/configuration/configuration.test.js
+++ b/test/e2e/configuration/configuration.test.js
@@ -90,5 +90,12 @@ test('should parse basic info', async () => {
     },
   };
   const result = await processSwagger(options);
-  expect(result).toEqual(expected);
+  expect(result.swaggerObject).toEqual(expected);
+});
+test('should get transforms(jsdocInfo, getPaths, getComponents, getTags) methods', async () => {
+  const result = await processSwagger(options);
+  expect(result).toHaveProperty('jsdocInfo');
+  expect(result).toHaveProperty('getPaths');
+  expect(result).toHaveProperty('getComponents');
+  expect(result).toHaveProperty('getTags');
 });
diff --git a/test/e2e/parameters/parameters.test.js b/test/e2e/parameters/parameters.test.js
index 35aff8f..0426476 100644
--- a/test/e2e/parameters/parameters.test.js
+++ b/test/e2e/parameters/parameters.test.js
@@ -119,5 +119,5 @@ test('should parse parameters from jsdoc-example', async () => {
     },
   };
   const result = await processSwagger(options);
-  expect(result).toEqual(expected);
+  expect(result.swaggerObject).toEqual(expected);
 });