route-docs.ejs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. <%
  2. const { config, route, utils } = it;
  3. const { _, formatDescription, fmtToJSDocLine, pascalCase, require } = utils;
  4. const { raw, request, routeName } = route;
  5. const jsDocDescription = raw.description ?
  6. ` * @description ${formatDescription(raw.description, true)}` :
  7. fmtToJSDocLine('No description', { eol: false });
  8. const jsDocLines = _.compact([
  9. _.size(raw.tags) && ` * @tags ${raw.tags.join(", ")}`,
  10. ` * @name ${pascalCase(routeName.usage)}`,
  11. raw.summary && ` * @summary ${raw.summary}`,
  12. ` * @request ${_.upperCase(request.method)}:${raw.route}`,
  13. raw.deprecated && ` * @deprecated`,
  14. routeName.duplicate && ` * @originalName ${routeName.original}`,
  15. routeName.duplicate && ` * @duplicate`,
  16. request.security && ` * @secure`,
  17. ...(config.generateResponses && raw.responsesTypes.length
  18. ? raw.responsesTypes.map(
  19. ({ type, status, description, isSuccess }) =>
  20. ` * @response \`${status}\` \`${_.replace(_.replace(type, /\/\*/g, "\\*"), /\*\//g, "*\\")}\` ${description}`,
  21. )
  22. : []),
  23. ]).map(str => str.trimEnd()).join("\n");
  24. return {
  25. description: jsDocDescription,
  26. lines: jsDocLines,
  27. }
  28. %>