Repository: BRIKEV/express-jsdoc-swagger (js)

Issue:
[BUG] Errors with empty required properties
**Describe the bug**
When we add a JSON object that we generate with our library into Swagger Editor we see this error.

<img width="702" alt="Screen Shot 2020-07-31 at 19 03 26" src="https://user-images.githubusercontent.com/12685053/89058933-8a5ea100-d360-11ea-8483-94a44ee72866.png">

This is because we always add required key for components value. This line is the method we need to modify.

https://github.com/BRIKEV/express-jsdoc-swagger/blob/master/transforms/components/index.js#L54

This method needs to be changed to erase the required property when it hasn't values.

**To Reproduce**
If you want to reproduce this you can use this JSON file in Swagger Editor.

```js
{
  "openapi": "3.0.0",
  "info": {
    "title": "Albums store",
    "description": "Add your description",
    "license": {
      "name": "MIT",
      "url": ""
    },
    "termsOfService": "",
    "version": "1.0.0"
  },
  "servers": [],
  "paths": {},
  "tags": [],
  "components": {
    "schemas": {
      "Song": {
        "description": "A song",
        "required": [
          "title"
        ],
        "type": "object",
        "properties": {
          "title": {
            "description": "The title",
            "type": "string"
          },
          "artist": {
            "description": "The artist",
            "type": "string"
          },
          "year": {
            "description": "The year",
            "type": "number",
            "format": "double"
          }
        }
      },
      "Author": {
        "description": "Author model",
        "required": [
          "name"
        ],
        "type": "object",
        "properties": {
          "name": {
            "description": "Author name",
            "type": "string"
          },
          "age": {
            "description": "Author age",
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "Album": {
        "description": "Album",
        "required": [],
        "type": "object",
        "properties": {
          "firstSong": {
            "description": "",
            "$ref": "#/components/schemas/Song"
          },
          "author": {
            "description": "",
            "$ref": "#/components/schemas/Author"
          }
        }
      }
    }
  }
}
```

**Expected behavior**
Not having Swagger Editor errors.

**Screenshots**
<img width="702" alt="Screen Shot 2020-07-31 at 19 03 26" src="https://user-images.githubusercontent.com/12685053/89058933-8a5ea100-d360-11ea-8483-94a44ee72866.png">


Pull request description:
Required properties
### What kind of change does this PR introduce? (check at least one)
 - [x] Bugfix
 - [ ] Feature
 - [x] Test
 - [ ] Docs
 - [ ] Refactor
 - [ ] Build-related changes
 - [ ] Other, please describe:

### Description:
This PR fixes #79 

Patch:
diff --git a/transforms/components/index.js b/transforms/components/index.js
index 0cfd466..96cb244 100644
--- a/transforms/components/index.js
+++ b/transforms/components/index.js
@@ -51,14 +51,17 @@ const formatProperties = properties => {
   }, {});
 };
 
-const isPropertyRequired = properties => {
-  if (!properties || !Array.isArray(properties)) return [];
-  return properties.filter(({ name }) => name.includes(REQUIRED)).map(getPropertyName);
-};
+const getRequiredProperties = properties => (
+  properties.filter(({ name }) => name.includes(REQUIRED))
+);
+
+const formatRequiredProperties = requiredProperties => requiredProperties.map(getPropertyName);
+
 
 const parseSchema = schema => {
   const typedef = getTagInfo(schema.tags, 'typedef');
   const propertyValues = getTagsInfo(schema.tags, 'property');
+  const requiredProperties = getRequiredProperties(propertyValues);
   if (!typedef || !typedef.name) return {};
   const {
     elements,
@@ -67,7 +70,9 @@ const parseSchema = schema => {
     [typedef.name]: {
       ...combineSchema(elements),
       description: schema.description,
-      required: isPropertyRequired(propertyValues),
+      ...(requiredProperties.length ? {
+        required: formatRequiredProperties(requiredProperties),
+      } : {}),
       type: 'object',
       properties: formatProperties(propertyValues),
     },


Test patch:
diff --git a/test/e2e/components/components.test.js b/test/e2e/components/components.test.js
index 8bd5614..9fd2a56 100644
--- a/test/e2e/components/components.test.js
+++ b/test/e2e/components/components.test.js
@@ -70,7 +70,6 @@ test('should parse components jsdoc from jsdoc-example', async () => {
         },
         Album: {
           description: 'Album',
-          required: [],
           type: 'object',
           properties: {
             firstSong: {
diff --git a/test/transforms/components/index.test.js b/test/transforms/components/index.test.js
index 94b88a1..825bd6e 100644
--- a/test/transforms/components/index.test.js
+++ b/test/transforms/components/index.test.js
@@ -60,7 +60,6 @@ describe('parseComponents method', () => {
         schemas: {
           Song: {
             type: 'object',
-            required: [],
             description: 'A song',
             properties: {
               title: {
@@ -100,7 +99,6 @@ describe('parseComponents method', () => {
         schemas: {
           Song: {
             type: 'object',
-            required: [],
             description: 'A song',
             properties: {
               title: {
@@ -145,7 +143,6 @@ describe('parseComponents method', () => {
         schemas: {
           Song: {
             type: 'object',
-            required: [],
             description: 'A song',
             properties: {
               title: {
@@ -330,7 +327,6 @@ describe('parseComponents method', () => {
           },
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               firstSong: {
@@ -390,7 +386,6 @@ describe('parseComponents method', () => {
           },
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               firstSong: {
@@ -478,7 +473,6 @@ describe('parseComponents method', () => {
           },
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               firstSong: {
@@ -513,7 +507,6 @@ describe('parseComponents method', () => {
         schemas: {
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               title: {
@@ -551,7 +544,6 @@ describe('parseComponents method', () => {
         schemas: {
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               title: {
@@ -589,7 +581,6 @@ describe('parseComponents method', () => {
         schemas: {
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               title: {
@@ -626,7 +617,6 @@ describe('parseComponents method', () => {
         schemas: {
           Album: {
             type: 'object',
-            required: [],
             description: 'Album',
             properties: {
               Songs: {
@@ -664,7 +654,6 @@ describe('parseComponents method', () => {
               },
             ],
             type: 'object',
-            required: [],
             description: 'SingleAlbum',
             properties: {
               Songs: {
@@ -705,7 +694,6 @@ describe('parseComponents method', () => {
               },
             ],
             type: 'object',
-            required: [],
             description: 'SongOrAlbum',
             properties: {
               Songs: {
diff --git a/test/transforms/paths/combineSchemas.test.js b/test/transforms/paths/combineSchemas.test.js
index 08df0c2..32d34d4 100644
--- a/test/transforms/paths/combineSchemas.test.js
+++ b/test/transforms/paths/combineSchemas.test.js
@@ -129,7 +129,6 @@ test('should not parse component with anyOf keyword', () => {
         },
         Album: {
           type: 'object',
-          required: [],
           description: 'Album',
           properties: {
             firstSong: {