data-contract-jsdoc.ejs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <%
  2. const { data, utils } = it;
  3. const { formatDescription, require, _ } = utils;
  4. const stringify = (value) => _.isObject(value) ? JSON.stringify(value) : _.isString(value) ? `"${value}"` : value
  5. const jsDocLines = _.compact([
  6. data.title,
  7. data.description && formatDescription(data.description),
  8. !_.isUndefined(data.deprecated) && data.deprecated && '@deprecated',
  9. !_.isUndefined(data.format) && `@format ${data.format}`,
  10. !_.isUndefined(data.minimum) && `@min ${data.minimum}`,
  11. !_.isUndefined(data.multipleOf) && `@multipleOf ${data.multipleOf}`,
  12. !_.isUndefined(data.exclusiveMinimum) && `@exclusiveMin ${data.exclusiveMinimum}`,
  13. !_.isUndefined(data.maximum) && `@max ${data.maximum}`,
  14. !_.isUndefined(data.minLength) && `@minLength ${data.minLength}`,
  15. !_.isUndefined(data.maxLength) && `@maxLength ${data.maxLength}`,
  16. !_.isUndefined(data.exclusiveMaximum) && `@exclusiveMax ${data.exclusiveMaximum}`,
  17. !_.isUndefined(data.maxItems) && `@maxItems ${data.maxItems}`,
  18. !_.isUndefined(data.minItems) && `@minItems ${data.minItems}`,
  19. !_.isUndefined(data.uniqueItems) && `@uniqueItems ${data.uniqueItems}`,
  20. !_.isUndefined(data.default) && `@default ${stringify(data.default)}`,
  21. !_.isUndefined(data.pattern) && `@pattern ${data.pattern}`,
  22. !_.isUndefined(data.example) && `@example ${stringify(data.example)}`
  23. ]).join('\n').split('\n');
  24. %>
  25. <% if (jsDocLines.every(_.isEmpty)) { %>
  26. <% } else if (jsDocLines.length === 1) { %>
  27. /** <%~ jsDocLines[0] %> */
  28. <% } else if (jsDocLines.length) { %>
  29. /**
  30. <% for (jsDocLine of jsDocLines) { %>
  31. * <%~ jsDocLine %>
  32. <% } %>
  33. */
  34. <% } %>