Repository: BRIKEV/express-jsdoc-swagger
Pull request #209 (2022-03-22 19:47:59)

Add support for non-object typedefs
### What kind of change does this PR introduce? (check at least one)
 - [X] Bugfix
 - [ ] Feature
 - [ ] Test
 - [ ] Docs
 - [ ] Refactor
 - [ ] Build-related changes
 - [ ] Other, please describe:

### Description:
 This adds support for non-object typedefs such as string - previously it would emit an "object" type for non-object typedefs

sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; ![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL) [1 Code Smell](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209) No Coverage information  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&metric=new_duplicated_lines_density&view=list)


sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; ![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209) No Coverage information  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&metric=new_duplicated_lines_density&view=list)


sonarcloud[bot]: Kudos, SonarCloud Quality Gate passed!&nbsp; &nbsp; [![Quality Gate passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/passed-16px.png 'Quality Gate passed')](https://sonarcloud.io/dashboard?id=BRIKEV_express-jsdoc-swagger&pullRequest=209)

[![Bug](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/bug-16px.png 'Bug')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG) [0 Bugs](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=BUG)  
[![Vulnerability](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/vulnerability-16px.png 'Vulnerability')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY) [0 Vulnerabilities](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=VULNERABILITY)  
[![Security Hotspot](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/security_hotspot-16px.png 'Security Hotspot')](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT) [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=SECURITY_HOTSPOT)  
[![Code Smell](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/code_smell-16px.png 'Code Smell')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL) [![A](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/RatingBadge/A-16px.png 'A')](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL) [0 Code Smells](https://sonarcloud.io/project/issues?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&resolved=false&types=CODE_SMELL)

[![No Coverage information](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/CoverageChart/NoCoverageInfo-16px.png 'No Coverage information')](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209) No Coverage information  
[![0.0%](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/Duplications/3-16px.png '0.0%')](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&metric=new_duplicated_lines_density&view=list) [0.0% Duplication](https://sonarcloud.io/component_measures?id=BRIKEV_express-jsdoc-swagger&pullRequest=209&metric=new_duplicated_lines_density&view=list)


kevinccbsg: I will try to include it in the example folder before releasing it. Thanks @sbingner 

Patch:
diff --git a/transforms/components/index.js b/transforms/components/index.js
index e159b3f..320281b 100644
--- a/transforms/components/index.js
+++ b/transforms/components/index.js
@@ -68,19 +68,27 @@ const parseSchema = (schema, options = {}) => {
   const typedef = getTagInfo(schema.tags, 'typedef');
   const propertyValues = getTagsInfo(schema.tags, 'property');
   const requiredProperties = getRequiredProperties(propertyValues);
+  const [descriptionValue, enumValues, jsonOptions] = formatDescription(schema.description);
+  const [description, format] = mapDescription(descriptionValue);
   if (!typedef || !typedef.name) return {};
   const {
     elements,
   } = typedef.type;
+  const type = typedef.type.name || 'object';
   return {
     [typedef.name]: {
       ...combineSchema(elements),
-      description: schema.description,
+      description,
       ...(requiredProperties.length ? {
         required: formatRequiredProperties(requiredProperties),
       } : {}),
-      type: 'object',
-      properties: formatProperties(propertyValues, options),
+      type,
+      ...(type === 'object' ? {
+        properties: formatProperties(propertyValues, options),
+      } : {}),
+      ...(format ? { format } : {}),
+      ...addEnumValues(enumValues),
+      ...(jsonOptions || {}),
     },
   };
 };


Test patch:
diff --git a/test/transforms/components/index.test.js b/test/transforms/components/index.test.js
index 8a6987d..b336cb3 100644
--- a/test/transforms/components/index.test.js
+++ b/test/transforms/components/index.test.js
@@ -799,4 +799,52 @@ describe('parseComponents method', () => {
     const result = parseComponents({}, parsedJSDocs, { notRequiredAsNullable: true });
     expect(result).toEqual(expected);
   });
+
+  it('Should parse jsdoc component spec with string type', () => {
+    const jsodInput = [`
+      /**
+       * A song
+       * @typedef {string} Song
+       */
+    `];
+    const expected = {
+      components: {
+        schemas: {
+          Song: {
+            type: 'string',
+            description: 'A song',
+          },
+        },
+      },
+    };
+    const parsedJSDocs = jsdocInfo()(jsodInput);
+    const result = parseComponents({}, parsedJSDocs);
+    expect(result).toEqual(expected);
+  });
+
+  it('Should parse jsdoc component spec with string type and a format', () => {
+    const jsodInput = [`
+      /**
+       * A song - enum:value1,value2
+       * @typedef {string} Song
+       */
+    `];
+    const expected = {
+      components: {
+        schemas: {
+          Song: {
+            type: 'string',
+            description: 'A song',
+            enum: [
+              'value1',
+              'value2',
+            ],
+          },
+        },
+      },
+    };
+    const parsedJSDocs = jsdocInfo()(jsodInput);
+    const result = parseComponents({}, parsedJSDocs);
+    expect(result).toEqual(expected);
+  });
 });