From ba8d35acc3e7f41d2a1119803e56c66c8a39eb17 Mon Sep 17 00:00:00 2001 From: Luis Fernando Planella Gonzalez Date: Mon, 15 Jan 2018 10:56:25 -0200 Subject: [PATCH] More work on generating correct MarkDown comments (#26) --- README.md | 5 ++--- ng-swagger-gen.js | 37 +++++++++++++++++++++++-------------- package-lock.json | 5 ----- package.json | 1 - 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index dd2b1b3..0bbba55 100644 --- a/README.md +++ b/README.md @@ -59,9 +59,8 @@ Here are a few notes: ## Requirements The generator itself has very few requirements, basically -[argparse](https://www.npmjs.com/package/argparse), -[mustache](https://www.npmjs.com/package/mustache) and -[linewrap](https://www.npmjs.com/package/linewrap). +[argparse](https://www.npmjs.com/package/argparse) and +[mustache](https://www.npmjs.com/package/mustache). However, the generated code requires: diff --git a/ng-swagger-gen.js b/ng-swagger-gen.js index 3b6ea56..0a0ed6a 100644 --- a/ng-swagger-gen.js +++ b/ng-swagger-gen.js @@ -6,10 +6,6 @@ const http = require('http'); const https = require('https'); const path = require('path'); const Mustache = require('mustache'); -const linewrap = require('linewrap'); -const wrapComments = linewrap(78, { - lineBreak: '\n' -}); /** * Main generate function @@ -407,15 +403,12 @@ function toComments(text, level) { if (text == null || text.length === 0) { return indent; } + const lines = text.trim().split('\n'); var result = indent + "/**\n"; - var lines = wrapComments(text).split('\n'); - for (i = 0; i < lines.length; i++) { - var line = lines[i]; - if (line.length > 0) { - result += indent + " * " + line + '\n'; - } - } - result += indent + " */\n" + indent; + lines.forEach(line => { + result += indent + " *" + (line === '' ? '' : ' ' + line) + "\n"; + }); + result += indent + " */\n " + indent; return result; } @@ -909,13 +902,29 @@ function processServices(swagger, models, options) { } var operationResponses = processResponses(def, path, models); var resultType = operationResponses.resultType; - var docString = def.description || ""; + var docString = (def.description || "").trim(); if (paramsClass == null) { for (i = 0; i < operationParameters.length; i++) { param = operationParameters[i]; - docString += "\n@param " + param.paramName + " - " + + docString += "\n@param " + param.paramName + " " + param.paramDescription; } + } else { + docString += "\n@param params The `" + descriptor.serviceClass + + "." + paramsClass + "` containing the following parameters:\n"; + for (i = 0; i < operationParameters.length; i++) { + param = operationParameters[i]; + docString += "\n- `" + param.paramName + "`: "; + var lines = (param.paramDescription || "").trim().split("\n"); + for (var l = 0; l < lines.length; l++) { + var line = lines[l]; + if (line === "") { + docString += "\n"; + } else { + docString += (l == 0 ? "" : " ") + line + "\n"; + } + } + } } if (operationResponses.resultDescription) { docString += "\n@return " + operationResponses.resultDescription; diff --git a/package-lock.json b/package-lock.json index dffab57..22bb2fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,11 +12,6 @@ "sprintf-js": "1.0.3" } }, - "linewrap": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/linewrap/-/linewrap-0.2.1.tgz", - "integrity": "sha1-XK7xV5ODubX8toKy1JjcnXTFRc8=" - }, "mustache": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/mustache/-/mustache-2.3.0.tgz", diff --git a/package.json b/package.json index 7ba895e..2fbad06 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,6 @@ }, "dependencies": { "argparse": "^1.0.9", - "linewrap": "^0.2.1", "mustache": "^2.3.0" }, "bin": {