@cparra/apexdocs 2.24.0 → 2.25.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/.eslintrc.js +12 -12
  2. package/.github/workflows/ci.yaml +22 -0
  3. package/.github/workflows/close_stale.yml +22 -22
  4. package/.prettierrc.js +7 -7
  5. package/LICENSE +21 -21
  6. package/README.md +742 -718
  7. package/apexdocs.config.ts +13 -13
  8. package/docs/{README.md → __old/README.md} +1 -1
  9. package/docs/{restapi.json → __old/restapi.json} +589 -589
  10. package/docs/{types → __old/types}/Classes/nspc.ChildClass.md +97 -97
  11. package/docs/{types → __old/types}/Main/nspc.SampleClass.md +189 -189
  12. package/examples/force-app/main/default/classes/AnotherInterface.cls +16 -16
  13. package/examples/force-app/main/default/classes/ChildClass.cls +42 -42
  14. package/examples/force-app/main/default/classes/EscapedAnnotations.cls +5 -5
  15. package/examples/force-app/main/default/classes/GrandparentClass.cls +4 -4
  16. package/examples/force-app/main/default/classes/GroupedClass.cls +8 -8
  17. package/examples/force-app/main/default/classes/MemberGrouping.cls +17 -17
  18. package/examples/force-app/main/default/classes/ParentClass.cls +16 -16
  19. package/examples/force-app/main/default/classes/SampleClass.cls +166 -166
  20. package/examples/force-app/main/default/classes/SampleClass.cls-meta.xml +5 -5
  21. package/examples/force-app/main/default/classes/SampleClassWithoutModifier.cls +9 -9
  22. package/examples/force-app/main/default/classes/SampleInterface.cls +16 -16
  23. package/examples/force-app/main/default/restapi/SampleRestResource.cls +195 -195
  24. package/examples/force-app/main/default/restapi/SampleRestResourceToSkip.cls +35 -35
  25. package/examples/force-app/main/default/restapi/SampleRestResourceWithInnerClass.cls +24 -24
  26. package/examples/force-app/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +15 -15
  27. package/examples/force-app/main/default/restapi/references/Reference1.cls +9 -9
  28. package/examples/force-app/main/default/restapi/references/Reference2.cls +9 -9
  29. package/examples/force-app/main/default/restapi/references/Reference3.cls +3 -3
  30. package/examples/force-app/main/default/restapi/references/Reference4.cls +3 -3
  31. package/examples/force-app/main/default/restapi/references/Reference5.cls +3 -3
  32. package/examples/force-app/main/default/restapi/references/Reference6.cls +6 -6
  33. package/examples/force-app/main/default/restapi/references/Reference7.cls +3 -3
  34. package/examples/includes/header.md +3 -3
  35. package/examples/plain-markdown/.forceignore +12 -0
  36. package/examples/plain-markdown/README.md +301 -0
  37. package/examples/plain-markdown/config/project-scratch-def.json +5 -0
  38. package/examples/plain-markdown/force-app/classes/BaseClass.cls +3 -0
  39. package/examples/plain-markdown/force-app/classes/ParentInterface.cls +3 -0
  40. package/examples/plain-markdown/force-app/classes/ReferencedEnum.cls +3 -0
  41. package/examples/plain-markdown/force-app/classes/SampleClass.cls +35 -0
  42. package/examples/plain-markdown/force-app/classes/SampleEnum.cls +30 -0
  43. package/examples/plain-markdown/force-app/classes/SampleException.cls +1 -0
  44. package/examples/plain-markdown/force-app/classes/SampleInterface.cls +46 -0
  45. package/examples/plain-markdown/package-lock.json +665 -0
  46. package/examples/plain-markdown/package.json +24 -0
  47. package/examples/plain-markdown/sfdx-project.json +12 -0
  48. package/examples/plain-markdown/template.md +3 -0
  49. package/jest.config.js +5 -5
  50. package/lib/adapters/apex-types.d.ts +5 -0
  51. package/lib/adapters/apex-types.js +34 -0
  52. package/lib/adapters/apex-types.js.map +1 -0
  53. package/lib/adapters/documentables.d.ts +6 -0
  54. package/lib/adapters/documentables.js +41 -0
  55. package/lib/adapters/documentables.js.map +1 -0
  56. package/lib/adapters/fields-and-properties.d.ts +3 -0
  57. package/lib/adapters/fields-and-properties.js +10 -0
  58. package/lib/adapters/fields-and-properties.js.map +1 -0
  59. package/lib/adapters/methods-and-constructors.d.ts +4 -0
  60. package/lib/adapters/methods-and-constructors.js +49 -0
  61. package/lib/adapters/methods-and-constructors.js.map +1 -0
  62. package/lib/adapters/references.d.ts +5 -0
  63. package/lib/adapters/references.js +82 -0
  64. package/lib/adapters/references.js.map +1 -0
  65. package/lib/adapters/type-utils.d.ts +2 -0
  66. package/lib/adapters/type-utils.js +8 -0
  67. package/lib/adapters/type-utils.js.map +1 -0
  68. package/lib/application/Apexdocs.d.ts +13 -13
  69. package/lib/application/Apexdocs.js +79 -76
  70. package/lib/application/Apexdocs.js.map +1 -1
  71. package/lib/cli/generate.d.ts +2 -2
  72. package/lib/cli/generate.js +156 -130
  73. package/lib/cli/generate.js.map +1 -1
  74. package/lib/index.d.ts +1 -1
  75. package/lib/index.js +17 -17
  76. package/lib/model/apex-bundle.d.ts +6 -6
  77. package/lib/model/apex-bundle.js +10 -10
  78. package/lib/model/apex-type-wrappers/ClassMirrorWrapper.d.ts +7 -7
  79. package/lib/model/apex-type-wrappers/ClassMirrorWrapper.js +13 -13
  80. package/lib/model/apex-type-wrappers/MethodMirrorWrapper.d.ts +7 -7
  81. package/lib/model/apex-type-wrappers/MethodMirrorWrapper.js +11 -11
  82. package/lib/model/inheritance.d.ts +8 -8
  83. package/lib/model/inheritance.js +2 -2
  84. package/lib/model/manifest.d.ts +22 -22
  85. package/lib/model/manifest.js +46 -46
  86. package/lib/model/manifest.js.map +1 -1
  87. package/lib/model/markdown-file.d.ts +16 -16
  88. package/lib/model/markdown-file.js +109 -106
  89. package/lib/model/markdown-file.js.map +1 -1
  90. package/lib/model/markdown-generation-util/doc-comment-annotation-util.d.ts +8 -8
  91. package/lib/model/markdown-generation-util/doc-comment-annotation-util.js +46 -43
  92. package/lib/model/markdown-generation-util/doc-comment-annotation-util.js.map +1 -1
  93. package/lib/model/markdown-generation-util/field-declaration-util.d.ts +3 -3
  94. package/lib/model/markdown-generation-util/field-declaration-util.js +54 -54
  95. package/lib/model/markdown-generation-util/index.d.ts +3 -3
  96. package/lib/model/markdown-generation-util/index.js +19 -19
  97. package/lib/model/markdown-generation-util/method-declaration-util.d.ts +4 -4
  98. package/lib/model/markdown-generation-util/method-declaration-util.js +114 -114
  99. package/lib/model/markdown-generation-util/type-declaration-util.d.ts +3 -3
  100. package/lib/model/markdown-generation-util/type-declaration-util.js +81 -81
  101. package/lib/model/markdown-home-file.d.ts +11 -11
  102. package/lib/model/markdown-home-file.js +56 -53
  103. package/lib/model/markdown-home-file.js.map +1 -1
  104. package/lib/model/markdown-type-file.d.ts +26 -26
  105. package/lib/model/markdown-type-file.js +136 -133
  106. package/lib/model/markdown-type-file.js.map +1 -1
  107. package/lib/model/openapi/apex-doc-types.d.ts +19 -19
  108. package/lib/model/openapi/apex-doc-types.js +4 -4
  109. package/lib/model/openapi/open-api-types.d.ts +93 -93
  110. package/lib/model/openapi/open-api-types.js +2 -2
  111. package/lib/model/openapi/open-api.d.ts +16 -16
  112. package/lib/model/openapi/open-api.js +33 -33
  113. package/lib/model/openapi/openapi-type-file.d.ts +7 -7
  114. package/lib/model/openapi/openapi-type-file.js +16 -16
  115. package/lib/model/outputFile.d.ts +10 -10
  116. package/lib/model/outputFile.js +28 -28
  117. package/lib/model/types-repository.d.ts +16 -16
  118. package/lib/model/types-repository.js +53 -53
  119. package/lib/service/apex-file-reader.d.ts +14 -14
  120. package/lib/service/apex-file-reader.js +48 -45
  121. package/lib/service/apex-file-reader.js.map +1 -1
  122. package/lib/service/file-system.d.ts +14 -14
  123. package/lib/service/file-system.js +47 -24
  124. package/lib/service/file-system.js.map +1 -1
  125. package/lib/service/file-writer.d.ts +6 -6
  126. package/lib/service/file-writer.js +56 -33
  127. package/lib/service/file-writer.js.map +1 -1
  128. package/lib/service/manifest-factory.d.ts +10 -10
  129. package/lib/service/manifest-factory.js +16 -13
  130. package/lib/service/manifest-factory.js.map +1 -1
  131. package/lib/service/metadata-processor.d.ts +3 -3
  132. package/lib/service/metadata-processor.js +16 -16
  133. package/lib/service/parser.d.ts +21 -21
  134. package/lib/service/parser.js +137 -134
  135. package/lib/service/parser.js.map +1 -1
  136. package/lib/service/state.d.ts +9 -9
  137. package/lib/service/state.js +19 -19
  138. package/lib/service/walkers/class-walker.d.ts +4 -4
  139. package/lib/service/walkers/class-walker.js +32 -32
  140. package/lib/service/walkers/enum-walker.d.ts +4 -4
  141. package/lib/service/walkers/enum-walker.js +10 -10
  142. package/lib/service/walkers/interface-walker.d.ts +4 -4
  143. package/lib/service/walkers/interface-walker.js +14 -14
  144. package/lib/service/walkers/walker-factory.d.ts +5 -5
  145. package/lib/service/walkers/walker-factory.js +20 -20
  146. package/lib/service/walkers/walker.d.ts +19 -19
  147. package/lib/service/walkers/walker.js +16 -16
  148. package/lib/settings.d.ts +70 -64
  149. package/lib/settings.js +99 -88
  150. package/lib/settings.js.map +1 -1
  151. package/lib/templating/compile.d.ts +7 -0
  152. package/lib/templating/compile.js +98 -0
  153. package/lib/templating/compile.js.map +1 -0
  154. package/lib/templating/helpers.d.ts +2 -0
  155. package/lib/templating/helpers.js +18 -0
  156. package/lib/templating/helpers.js.map +1 -0
  157. package/lib/test-helpers/AnnotationBuilder.d.ts +12 -12
  158. package/lib/test-helpers/AnnotationBuilder.js +30 -30
  159. package/lib/test-helpers/ClassMirrorBuilder.d.ts +18 -18
  160. package/lib/test-helpers/ClassMirrorBuilder.js +53 -53
  161. package/lib/test-helpers/DocCommentAnnotationBuilder.d.ts +8 -8
  162. package/lib/test-helpers/DocCommentAnnotationBuilder.js +25 -25
  163. package/lib/test-helpers/DocCommentBuilder.d.ts +12 -12
  164. package/lib/test-helpers/DocCommentBuilder.js +37 -37
  165. package/lib/test-helpers/FieldMirrorBuilder.d.ts +18 -18
  166. package/lib/test-helpers/FieldMirrorBuilder.js +53 -53
  167. package/lib/test-helpers/InterfaceMirrorBuilder.d.ts +16 -0
  168. package/lib/test-helpers/InterfaceMirrorBuilder.js +43 -0
  169. package/lib/test-helpers/InterfaceMirrorBuilder.js.map +1 -0
  170. package/lib/test-helpers/MethodMirrorBuilder.d.ts +29 -10
  171. package/lib/test-helpers/MethodMirrorBuilder.js +71 -36
  172. package/lib/test-helpers/MethodMirrorBuilder.js.map +1 -1
  173. package/lib/test-helpers/SettingsBuilder.d.ts +8 -8
  174. package/lib/test-helpers/SettingsBuilder.js +26 -26
  175. package/lib/transpiler/factory.d.ts +6 -6
  176. package/lib/transpiler/factory.js +34 -31
  177. package/lib/transpiler/factory.js.map +1 -1
  178. package/lib/transpiler/file-container.d.ts +6 -6
  179. package/lib/transpiler/file-container.js +15 -15
  180. package/lib/transpiler/generator-choices.d.ts +1 -1
  181. package/lib/transpiler/generator-choices.js +2 -2
  182. package/lib/transpiler/markdown/class-file-generatorHelper.d.ts +11 -8
  183. package/lib/transpiler/markdown/class-file-generatorHelper.js +74 -55
  184. package/lib/transpiler/markdown/class-file-generatorHelper.js.map +1 -1
  185. package/lib/transpiler/markdown/docsify/docsify-docs-processor.d.ts +6 -6
  186. package/lib/transpiler/markdown/docsify/docsify-docs-processor.js +12 -12
  187. package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.d.ts +11 -11
  188. package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.js +50 -50
  189. package/lib/transpiler/markdown/markdown-transpiler-base.d.ts +11 -11
  190. package/lib/transpiler/markdown/markdown-transpiler-base.js +26 -23
  191. package/lib/transpiler/markdown/markdown-transpiler-base.js.map +1 -1
  192. package/lib/transpiler/markdown/plain-markdown/class-template.d.ts +1 -0
  193. package/lib/transpiler/markdown/plain-markdown/class-template.js +36 -0
  194. package/lib/transpiler/markdown/plain-markdown/class-template.js.map +1 -0
  195. package/lib/transpiler/markdown/plain-markdown/constructors-partial-template.d.ts +1 -0
  196. package/lib/transpiler/markdown/plain-markdown/constructors-partial-template.js +39 -0
  197. package/lib/transpiler/markdown/plain-markdown/constructors-partial-template.js.map +1 -0
  198. package/lib/transpiler/markdown/plain-markdown/documentable-partial-template.d.ts +1 -0
  199. package/lib/transpiler/markdown/plain-markdown/documentable-partial-template.js +25 -0
  200. package/lib/transpiler/markdown/plain-markdown/documentable-partial-template.js.map +1 -0
  201. package/lib/transpiler/markdown/plain-markdown/enum-template.d.ts +1 -0
  202. package/lib/transpiler/markdown/plain-markdown/enum-template.js +15 -0
  203. package/lib/transpiler/markdown/plain-markdown/enum-template.js.map +1 -0
  204. package/lib/transpiler/markdown/plain-markdown/fieldsPartialTemplate.d.ts +1 -0
  205. package/lib/transpiler/markdown/plain-markdown/fieldsPartialTemplate.js +24 -0
  206. package/lib/transpiler/markdown/plain-markdown/fieldsPartialTemplate.js.map +1 -0
  207. package/lib/transpiler/markdown/plain-markdown/interface-template.d.ts +1 -0
  208. package/lib/transpiler/markdown/plain-markdown/interface-template.js +20 -0
  209. package/lib/transpiler/markdown/plain-markdown/interface-template.js.map +1 -0
  210. package/lib/transpiler/markdown/plain-markdown/methods-partial-template.d.ts +1 -0
  211. package/lib/transpiler/markdown/plain-markdown/methods-partial-template.js +49 -0
  212. package/lib/transpiler/markdown/plain-markdown/methods-partial-template.js.map +1 -0
  213. package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.d.ts +13 -6
  214. package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.js +121 -13
  215. package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.js.map +1 -1
  216. package/lib/transpiler/markdown/plain-markdown/type-level-apex-doc-partial-template.d.ts +1 -0
  217. package/lib/transpiler/markdown/plain-markdown/type-level-apex-doc-partial-template.js +31 -0
  218. package/lib/transpiler/markdown/plain-markdown/type-level-apex-doc-partial-template.js.map +1 -0
  219. package/lib/transpiler/openapi/open-api-docs-processor.d.ts +13 -13
  220. package/lib/transpiler/openapi/open-api-docs-processor.js +77 -74
  221. package/lib/transpiler/openapi/open-api-docs-processor.js.map +1 -1
  222. package/lib/transpiler/openapi/parsers/Builder.d.ts +16 -16
  223. package/lib/transpiler/openapi/parsers/Builder.js +29 -29
  224. package/lib/transpiler/openapi/parsers/Builder.js.map +1 -1
  225. package/lib/transpiler/openapi/parsers/MethodParser.d.ts +20 -20
  226. package/lib/transpiler/openapi/parsers/MethodParser.js +189 -166
  227. package/lib/transpiler/openapi/parsers/MethodParser.js.map +1 -1
  228. package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.d.ts +7 -7
  229. package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.js +10 -10
  230. package/lib/transpiler/openapi/parsers/ReferenceBuilder.d.ts +39 -39
  231. package/lib/transpiler/openapi/parsers/ReferenceBuilder.js +248 -225
  232. package/lib/transpiler/openapi/parsers/ReferenceBuilder.js.map +1 -1
  233. package/lib/transpiler/openapi/parsers/RequestBodyBuilder.d.ts +10 -10
  234. package/lib/transpiler/openapi/parsers/RequestBodyBuilder.js +19 -19
  235. package/lib/transpiler/openapi/parsers/ResponsesBuilder.d.ts +7 -7
  236. package/lib/transpiler/openapi/parsers/ResponsesBuilder.js +21 -21
  237. package/lib/transpiler/processor-type-transpiler.d.ts +10 -10
  238. package/lib/transpiler/processor-type-transpiler.js +8 -8
  239. package/lib/transpiler/transpiler.d.ts +5 -5
  240. package/lib/transpiler/transpiler.js +29 -26
  241. package/lib/transpiler/transpiler.js.map +1 -1
  242. package/lib/util/error-logger.d.ts +8 -8
  243. package/lib/util/error-logger.js +89 -89
  244. package/lib/util/error-logger.js.map +1 -1
  245. package/lib/util/logger.d.ts +21 -21
  246. package/lib/util/logger.js +60 -57
  247. package/lib/util/logger.js.map +1 -1
  248. package/lib/util/string-utils.d.ts +2 -2
  249. package/lib/util/string-utils.js +14 -14
  250. package/package.json +79 -78
  251. package/src/adapters/__tests__/interface-adapter.spec.ts +76 -0
  252. package/src/adapters/__tests__/references.spec.ts +115 -0
  253. package/src/adapters/apex-types.ts +67 -0
  254. package/src/adapters/documentables.ts +58 -0
  255. package/src/adapters/fields-and-properties.ts +14 -0
  256. package/src/adapters/methods-and-constructors.ts +78 -0
  257. package/src/adapters/references.ts +113 -0
  258. package/src/adapters/type-utils.ts +5 -0
  259. package/src/adapters/types.d.ts +8 -0
  260. package/src/cli/generate.ts +3 -0
  261. package/src/model/__tests__/manifest.spec.ts +1 -0
  262. package/src/model/manifest.ts +3 -3
  263. package/src/model/markdown-file.ts +1 -1
  264. package/src/model/openapi/open-api-types.ts +2 -2
  265. package/src/service/__tests__/apex-file-reader.spec.ts +4 -4
  266. package/src/service/__tests__/manifest-factory.spec.ts +1 -2
  267. package/src/settings.ts +15 -0
  268. package/src/templating/__tests__/compile.spec.ts +741 -0
  269. package/src/templating/compile.ts +187 -0
  270. package/src/templating/helpers.ts +14 -0
  271. package/src/templating/types.d.ts +104 -0
  272. package/src/test-helpers/FieldMirrorBuilder.ts +1 -1
  273. package/src/test-helpers/InterfaceMirrorBuilder.ts +44 -0
  274. package/src/test-helpers/MethodMirrorBuilder.ts +46 -6
  275. package/src/transpiler/markdown/class-file-generatorHelper.ts +22 -2
  276. package/src/transpiler/markdown/plain-markdown/class-template.ts +32 -0
  277. package/src/transpiler/markdown/plain-markdown/constructors-partial-template.ts +35 -0
  278. package/src/transpiler/markdown/plain-markdown/documentable-partial-template.ts +21 -0
  279. package/src/transpiler/markdown/plain-markdown/enum-template.ts +11 -0
  280. package/src/transpiler/markdown/plain-markdown/fieldsPartialTemplate.ts +20 -0
  281. package/src/transpiler/markdown/plain-markdown/interface-template.ts +16 -0
  282. package/src/transpiler/markdown/plain-markdown/methods-partial-template.ts +45 -0
  283. package/src/transpiler/markdown/plain-markdown/plain-docsProcessor.ts +122 -0
  284. package/src/transpiler/markdown/plain-markdown/type-level-apex-doc-partial-template.ts +27 -0
  285. package/src/transpiler/openapi/parsers/Builder.ts +1 -1
  286. package/src/transpiler/openapi/parsers/MethodParser.ts +1 -1
  287. package/src/transpiler/openapi/parsers/ReferenceBuilder.ts +1 -1
  288. package/src/util/error-logger.ts +4 -4
  289. package/src/util/logger.ts +3 -3
  290. package/tsconfig.json +21 -20
  291. package/tslint.json +5 -5
  292. package/lib/model/manifest-diff.d.ts +0 -27
  293. package/lib/model/manifest-diff.js +0 -69
  294. package/lib/model/manifest-diff.js.map +0 -1
  295. package/src/model/__tests__/manifest-diff.spec.ts +0 -139
  296. package/src/model/manifest-diff.ts +0 -94
  297. /package/docs/{index.html → __old/index.html} +0 -0
  298. /package/docs/{types → __old/types}/Classes/nspc.AnotherInterface.md +0 -0
  299. /package/docs/{types → __old/types}/Main/nspc.GroupedClass.md +0 -0
  300. /package/docs/{types → __old/types}/Misc-Group/nspc.EscapedAnnotations.md +0 -0
  301. /package/docs/{types → __old/types}/Misc-Group/nspc.GrandparentClass.md +0 -0
  302. /package/docs/{types → __old/types}/Misc-Group/nspc.InterfaceWithInheritance.md +0 -0
  303. /package/docs/{types → __old/types}/Misc-Group/nspc.MemberGrouping.md +0 -0
  304. /package/docs/{types → __old/types}/Misc-Group/nspc.ParentClass.md +0 -0
  305. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference1.md +0 -0
  306. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference2.md +0 -0
  307. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference3.md +0 -0
  308. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference4.md +0 -0
  309. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference5.md +0 -0
  310. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference6.md +0 -0
  311. /package/docs/{types → __old/types}/Misc-Group/nspc.Reference7.md +0 -0
  312. /package/docs/{types → __old/types}/Misc-Group/nspc.SampleClassWithoutModifier.md +0 -0
  313. /package/docs/{types → __old/types}/Misc-Group/nspc.SampleRestResource.md +0 -0
  314. /package/docs/{types → __old/types}/Misc-Group/nspc.SampleRestResourceWithInnerClass.md +0 -0
  315. /package/docs/{types → __old/types}/Misc-Group/nspc.SampleRestResourceWithoutApexDocs.md +0 -0
  316. /package/docs/{types → __old/types}/README.md +0 -0
  317. /package/docs/{types → __old/types}/Sample-Interfaces/nspc.SampleInterface.md +0 -0
package/README.md CHANGED
@@ -1,718 +1,742 @@
1
- # ApexDocs
2
-
3
- <p align="center">
4
- <b>ApexDocs is a Node.js library with CLI capabilities to docGenerator documentation for Salesforce Apex classes.</b>
5
- </p>
6
-
7
- [![License](https://img.shields.io/github/license/cesarParra/apexdocs)](https://github.com/cesarParra/apexdocs/blob/master/LICENSE)
8
-
9
- ## Description
10
-
11
- ApexDocs was originally built as an alternative to
12
- the [Java based ApexDoc tool](https://github.com/SalesforceFoundation/ApexDoc) originally created by Aslam Bari and
13
- later maintained by Salesforce.org, as that tool is no longer being maintained.
14
-
15
- ApexDocs is a Node.js library built on Typescript and hosted on [npm](https://www.npmjs.com/package/@cparra/apexdocs).
16
- It offers CLI capabilities to automatically document your source code, based on the ApexDoc style of documentation.
17
- Additionally, it can be imported and consumed directly by your JavaScript code.
18
-
19
- There are some key differences between ApexDocs and the Java based ApexDoc tool:
20
-
21
- - **Recursive file search through your module directory structure**. In an `sfdx` based project, all of your classes
22
- will be documented by specifying the top-most directory where file search should begin.
23
- - **Unopinionated documentation site generation**. Instead of creating HTML files, ApexDocs generates a Markdown (.md)
24
- file per Apex class being documented. This means you can host your files in static web hosting services that parse
25
- Markdown like Github Pages or Netlify, and use site generators like Jekyll or Gatsby. This gives you the freedom to
26
- decide how to style your site to match your needs.
27
-
28
- #### Features
29
-
30
- * Custom Annotations
31
-
32
- Any custom annotation defined in the Apexdoc is at the class level are supported, for example the following will be
33
- output to the resulting markdown file:
34
-
35
- ```apex
36
- /**
37
- * @MyCustomAnnotation This is a custom annotation
38
- */
39
- public class MyClass {
40
- }
41
- ```
42
-
43
- * Single Line ApexDoc Blocks
44
-
45
- 📒 Note: If you wish to have multiple `@` tags in a single line but don't want them to be treated as ApexDoc annotations, you can
46
- escape them by adding wrapping the annotation in ticks, for example
47
-
48
- ```apex
49
- /**
50
- * @MyCustomAnnotation This is a custom annotation with an `@embedded` annotation
51
- */
52
- ```
53
-
54
- * Support for grouping blocks of related code within a class
55
- * Support for HTML tags
56
- * OpenApi REST specification generation
57
- * Support for ignoring files and members from being documented
58
- * Namespace support
59
- * Configuration file support
60
- * And much, much more!
61
-
62
- ### Demo
63
-
64
- ApexDocs currently supports generating markdown files for Jekyll and Docsify sites, as well as generating plain markdown
65
- files.
66
-
67
- ### In the wild
68
-
69
- - [Expression](https://cesarparra.github.io/expression/)
70
- - [Nimble AMS Docs](https://nimbleuser.github.io/nams-api-docs/#/api-reference/)
71
- - [Yet Another Salesforce Logger](https://cesarparra.github.io/yet-another-salesforce-logger/#/)
72
-
73
- ### [Docsify](https://docsify.js.org/)
74
-
75
- Demo
76
-
77
- - [Docsify](https://cesarparra.github.io/apexdocs/)
78
-
79
- ### [Jekyll](https://jekyllrb.com/)
80
-
81
- Demo
82
-
83
- - [Jekyll](https://cesarparra.github.io/apexdocs-docsify-example/)
84
-
85
- ## Installation
86
-
87
- ```bash
88
- npm i -g @cparra/apexdocs
89
- ```
90
-
91
- ## Usage
92
-
93
- ### CLI
94
-
95
- ```bash
96
- apexdocs-generate
97
- -s src
98
- -t docs
99
- -p global
100
- -g docsify
101
- ```
102
-
103
- The CLI supports the following parameters:
104
-
105
- | Parameter | Alias | Description | Default | Required |
106
- |-----------------------------|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|
107
- | --sourceDir | -s | The directory location which contains your apex .cls classes. | N/A | Yes |
108
- | --targetDir | -t | The directory location where documentation will be generated to. | `docs` | No |
109
- | --recursive | -r | Whether .cls classes will be searched for recursively in the directory provided. | `true` | No |
110
- | --scope | -p | A list of scopes to document. Values should be separated by a space, e.g --scope public private. Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource. | `global` | No |
111
- | --targetGenerator | -g | Define the static file generator for which the documents will be created. Currently supports: `jekyll`, `docsify`, `plain-markdown`, and `openapi`. | `jekyll` | No |
112
- | --indexOnly | N/A | Defines whether only the index file should be generated. | `false` | No |
113
- | --defaultGroupName | N/A | Defines the `@group` name to be used when a file does not specify it. | `Miscellaneous` | No |
114
- | --sanitizeHtml | N/A | When on, any special character within your ApexDocs is converted into its HTML code representation. This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" because otherwise the content within < and > would be treated as HTML tags and not shown in the output. Content in @example blocks are never sanitized. | true | No |
115
- | --openApiTitle | N/A | If using "openapi" as the target generator, this allows you to specify the OpenApi title value. | `Apex REST Api` | No |
116
- | --title | N/A | Allows you to specify the home page main title. If using "openapi" this acts as an alias to the openApiTitle parameter | `Classes` | No |
117
- | --namespace | N/A | The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url. | N/A | No |
118
- | --openApiFileName | N/A | If using "openapi" as the target generator, this allows you to specify the name of the output file. | `openapi` | No |
119
- | --sortMembersAlphabetically | N/A | Whether to sort the members of a class alphabetically. | `false` | No |
120
- | --includeMetadata | N/A | Whether to include the file's meta.xml information: Whether it is active and and the API version | false | No |
121
- | --documentationRootDir | N/A | The root directory where the documentation will be generated. This is useful when you want to generate the documentation in a subdirectory of your project. | N/A | No |
122
-
123
- ### Using a configuration file
124
-
125
- You can also use a configuration file to define the parameters that will be used when generating the documentation. Apexdocs
126
- uses [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) to load the configuration file, which means it supports
127
- the following formats:
128
-
129
- - A `package.json` property, e.g. `{ "apexdocs": { "sourceDir": "src", "targetDir": "docs" } }`
130
- - A `.apexdocsrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`
131
- - An `apexdocs.config.js` file that exports an object
132
- - A `apexdocs.config.ts` file that exports an object
133
-
134
- The configuration file should be placed in the root directory of your project.
135
-
136
- **Note that when using a configuration file, you can still override any of the parameters by passing them through the CLI.**
137
-
138
- When defining a `.js` or `.ts` configuration file, your object export can also contain the following functions that will
139
- allow you to override some of the default behavior:
140
-
141
- - `onBeforeFileWrite` - A function that will be called before a file is written to disk. It receives a `TargetFile` object
142
- that contains the file's content, path, and name, etc. It should return a `TargetFile` object with the updated content.
143
- The full object definition can be imported from `@cparra/apexdocs/lib/settings`
144
- - `onAfterProcess` - A function that will be called after all files have been processed. It receives a `TargetFile[]` array
145
- with all of the files that were processed and does not return anything.
146
- - `frontMatterHeader` - A function that will be called before the front matter is written to the file (when using the Jekyll generator).
147
- It receives a `TargetType` object
148
- and should return a list of strings that will be written to the file as the front matter.
149
- The full object definition can be imported from `@cparra/apexdocs/lib/settings`
150
- and contains the following properties:
151
- - `name` - The name of the type
152
- - `typeName` - Can be 'class', 'interface', or 'enum'
153
- - `accessModifier` - The access modifier of the type
154
- - `group` - The group to which the type belongs (if any)
155
- - `description` - The description of the type as defined in the ApexDoc
156
-
157
- ```typescript
158
- import {TargetFile} from "@cparra/apexdocs/lib/settings";
159
- export default {
160
- onBeforeFileWrite: (file: TargetFile): TargetFile => {
161
- console.log('onBefore writing', file);
162
- return file;
163
- },
164
- onAfterProcess: (files: TargetFile[]) => {
165
- console.log('onAfterProcess files', files);
166
- },
167
- };
168
-
169
- ```
170
-
171
- ### Importing to your project
172
-
173
- If you are just interested in the Apex parsing capabilities, you can use the
174
- standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
175
- which is what gets used by this library behind the scenes to generate the documentation files.
176
-
177
- ## Documentation Format
178
-
179
- ApexDocs picks up blocks of comments throughout your `.cls` files. The block must begin with `/**` and end with `*/`.
180
-
181
- ### Documenting Classes
182
-
183
- The following tags are supported on the class level:
184
-
185
- **Note** Any custom generated tag is also supported. Custom tags can be added with at symbol (`@`) followed by the name
186
- of the tag. For example `@custom-tag`
187
-
188
- | Tag | Description |
189
- |----------------|--------------------------------------------------------------------------------------------------------------------------------------------|
190
- | `@description` | One or more lines describing the class. |
191
- | `@see` | The name of a related class. |
192
- | `@group` | The group to which the class belongs to. |
193
- | `@author` | The author of the class. Note that this only gets added if it is explicitly defined through the configuration class that it should. |
194
- | `@date` | The date the class was created. Note that this only gets added if it is explicitly defined through the configuration class that it should. |
195
-
196
- **Example**
197
-
198
- ```apex
199
- /**
200
- * @description This is my class description.
201
- */
202
- public with sharing class TestClass {
203
- }
204
- ```
205
-
206
- ### Documenting Enums
207
-
208
- The following tags are supported on the enum level:
209
-
210
- | Tag | Description |
211
- |----------------|----------------------------------------|
212
- | `@description` | One or more lines describing the enum. |
213
-
214
- **Example**
215
-
216
- ```apex
217
- /**
218
- * @description This is my enum description.
219
- */
220
- public Enum ExampleEnum {
221
- VALUE_1, VALUE_2
222
- }
223
- ```
224
-
225
- ### Documenting Properties
226
-
227
- The following tags are supported on the property level:
228
-
229
- | Tag | Description |
230
- |----------------|--------------------------------------------|
231
- | `@description` | One or more lines describing the property. |
232
-
233
- **Example**
234
-
235
- ```apex
236
- /**
237
- * @description This is my property description.
238
- */
239
- public String ExampleProperty { get; set; }
240
- ```
241
-
242
- ### Documenting Methods and Constructors
243
-
244
- Methods and constructors support the same tags.
245
-
246
- The following tags are supported on the method level:
247
-
248
- | Tag | Description |
249
- |------------------------------|---------------------------------------------------|
250
- | `@description` | One or more lines describing the method. |
251
- | `@param` _paramName_ | Description of a single parameter. |
252
- | `@return` | Description of the return value of the method. |
253
- | `@example` | Example of how the code can be used or called. |
254
- | `@throws` _ExceptionName_ | Description of an exception thrown by the method. |
255
- | `@exception` _ExceptionName_ | Same as `@throws`. V2 only |
256
-
257
- **Example**
258
-
259
- ```apex
260
- /**
261
- * @description This is my method description.
262
- * @param action The action to execute.
263
- * @return The result of the operation.
264
- * @example
265
- * Object result = SampleClass.call('exampleAction');
266
- */
267
- public static Object call(String action) {
268
- }
269
- ```
270
-
271
- ### Grouping Declarations Within A Class
272
-
273
- A class might have members that should be grouped together. For example, you can have a class for constants with
274
- groups of constants that should be grouped together because they share a common behavior (e.g. different groups
275
- of constants representing the possible values for different picklists.)
276
-
277
- You can group things together within a class by using the following syntax:
278
-
279
- ```apex
280
- // @start-group Group Name or Description
281
- public static final String CONSTANT_FOO = 'Foo';
282
- public static final String CONSTANT_BAR = 'Bar';
283
- // @end-group
284
- ```
285
-
286
- Groups of members are displayed together under their own subsection after its name or description.
287
-
288
- Some notes about grouping:
289
-
290
- * This is only supported on classes, NOT enums and interfaces
291
- * Supports
292
- * Properties
293
- * Fields (variables and constants)
294
- * Constructors
295
- * Methods
296
- * BUT only members of the same type are grouped together. For example,
297
- if you have a group that contains properties and methods the properties will be grouped together under Properties ->
298
- Group Name, and the methods will be grouped together under Methods -> Group Name
299
- * Does not support inner types (inner classes, interfaces, and enums)
300
- * It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for
301
- that file.
302
-
303
- ### Inline linking
304
-
305
- Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that
306
- class file for easy navigation.
307
-
308
- Apexdocs recognizes 2 different syntax when linking files:
309
-
310
- - Javadoc's `{@link FileName}` syntax
311
- - A class name wrapped in between `<<` `>>`.
312
-
313
- **Example**
314
-
315
- ```apex
316
- /**
317
- * @description This is my method description. This method receives an <<ExampleClass>>.
318
- * @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
319
- * @return The result of the operation.
320
- */
321
- public static Object doSomething(ExampleClass param1) {}
322
- ```
323
-
324
- ---
325
-
326
- Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
327
-
328
- ### HTML support
329
-
330
- For the most part all HTML is sanitized when the `--sanitizeHtml` flag is passed a true value (which is the default).
331
- But there are some tags are allowed to have for the possibility of better
332
- styling long text.
333
-
334
- - Allowed tags are: `br`, `p`, `ul`, `li`, and `code`
335
-
336
- Example
337
-
338
- ```apex
339
- /**
340
- * @description <p>This is a paragraph</p>
341
- * <p>And this is another paragraph</p>
342
- * <ul>
343
- * <li>This is a list item</li>
344
- * <li>This is another list item</li>
345
- * </ul>
346
- */
347
- class MyClass {
348
- }
349
- ```
350
-
351
- ⚠️When the `--sanitizeHtml` flag is ON, any special character between code blocks (i.e. \```, \`, or `<code>`) will also
352
- be escaped.
353
- So if you have references to Apex generic collections (Set, List, or Maps) they will not look right, as the < and >
354
- symbols will be escaped.
355
- To prevent this you can turn the flag off, but be aware of the special considerations when doing this described below.
356
-
357
- ---
358
-
359
- For full control over the output you can also turn off the `--sanitizeHtml` flag, which will allow you
360
- to have any desired HTML within your docs.
361
-
362
- ⚠️When the `--sanitizeHtml` flag is OFF, references to Apex generic collections (Set, List or Maps) can be problematic
363
- as they will be treated as an HTML tag and not displayed. For example if you have something
364
- like `@description Returns a List<String>`
365
- the `<String>` portion will be treated as HTML and thus not appear on the page.
366
-
367
- To fix this issue, when not sanitizing HTML, you should wrap any code that contain special characters that can be
368
- treated as HTML within '\`'
369
- or within `<code>` tags.
370
-
371
- ### Displaying diagrams
372
-
373
- You can display diagrams in your documentation by leveraging Github's built-in [Mermaid](https://mermaid-js.github.io/mermaid/#/) support.
374
-
375
- If you are using a markdown generator that supports Mermaid (e.g. [Github's markdown](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/),
376
- you can add diagrams to your documentation by using the
377
- `@mermaid` tag.
378
-
379
- **Example**
380
-
381
- ```apex
382
- /**
383
- * @mermaid
384
- * graph TD
385
- * A[Christmas] -->|Get money| B(Go shopping)
386
- * B --> C{Let me think}
387
- * C -->|One| D[Laptop]
388
- * C -->|Two| E[iPhone]
389
- * C -->|Three| F[Car]
390
- */
391
- public class MyClass {
392
- }
393
- ```
394
-
395
- [Here's an example of how that looks](/docs/types/Classes/nspc.AnotherInterface.md)
396
-
397
- ### Ignoring files and members
398
-
399
- You can ignore files and members by using the `@ignore` tag on any ApexDoc block. If used at the class level, the entire
400
- file will be ignored. If used at the member level, only that member will be ignored.
401
-
402
- Example
403
-
404
- ```apex
405
- /**
406
- * @ignore
407
- */
408
- public class MyClass {
409
- public static void myMethod() {}
410
- }
411
- ```
412
-
413
- ## Generating OpenApi REST Definitions
414
-
415
- ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
416
-
417
- ### Usage
418
-
419
- To create an OpenApi specification file, run the `apexdocs-generate` and pass `openapi` to the `--targetGenerator` parameter.
420
- When using this generator, you can also pass a custom title through the `--openApiTitle` parameter. This title will be placed
421
- in the output file's `info.title` property, as defined by the [OpenApi documentation for the Info Object](https://spec.openapis.org/oas/v3.1.0#info-object)
422
-
423
-
424
- ```shell
425
- apexdocs-generate -s ./src -t docs -g openapi --openApiTitle "Custom OpenApi Title"
426
- ```
427
-
428
- ### How It Works
429
-
430
- When generating an OpenApi document, since `@RestResource` classes need to be global in Apex, the `--scope` parameter will be ignored.
431
- Instead, ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
432
-
433
- Once it finishes running, a file named `openapi.json` will be created in the specified `--targetDir`.
434
-
435
- ### Configuring What Gets Created
436
-
437
- ApexDocs will automatically parse your source code and generate the OpenApi definition based on the HTTP related Apex
438
- annotations (RestResource, HttpDelete, HttpGet, HttpPatch, HttpPost, HttpGet). The different HTTP annotations will be used to generate a file that complies with the [OpenApi Specification v3.1.0](https://spec.openapis.org/oas/v3.1.0)
439
-
440
- Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs, relying on
441
- some custom annotations that are specific to generating OpenApi definitions:
442
-
443
- * `@http-request-body`
444
- * `@http-parameter`
445
- * `@http-response`
446
-
447
- #### @http-request-body
448
-
449
- Allows you to specify the HTTP request's expected request body. It supports receiving a `description`,
450
- whether it is `required` or not, and a `schema`, which defines the shape of the object that is expected.
451
-
452
- 📝 Note that only one `@http-request-body` should be defined per method. If you add more than one, only
453
- a single one will be used when generating the OpenApi definition.
454
-
455
- The `schema` can either be a reference to another class in your source code (see the `Class References` section below)
456
- or a fully defined custom schema (See the `Custom Schemas` section below).
457
-
458
- Example
459
- ```apex
460
- /**
461
- * @description This is a sample HTTP Post method
462
- * @http-request-body
463
- * description: This is an example of a request body
464
- * required: true
465
- * schema: ClassName
466
- */
467
- @HttpPost
468
- global static void doPost() {
469
- ///...
470
- }
471
- ```
472
-
473
- 📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
474
- so spacing is important.
475
-
476
- #### @http-parameter
477
-
478
- Allows you to specify any HTTP parameter expected by your method. It supports receiving a `name`,
479
- an `in` as defined by the supported [Parameter Locations](https://spec.openapis.org/oas/v3.1.0#parameter-locations),
480
- whether it is `required` or not, a `description`, and a `schema`.
481
-
482
- 📝 Note that you can specify as many `@http-parameter` annotations as needed.
483
-
484
- Example
485
- ```apex
486
- /**
487
- * @description This is a sample HTTP Post method
488
- * @return A String SObject.
489
- * @http-parameter
490
- * name: limit
491
- * in: query
492
- * required: true
493
- * description: Limits the number of items on a page
494
- * schema:
495
- * type: integer
496
- * @http-parameter
497
- * name: complex
498
- * in: cookie
499
- * schema: MyClassName
500
- */
501
- @HttpPost
502
- global static String doPost() {
503
- // ..
504
- }
505
- ```
506
-
507
- 📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
508
- so spacing is important.
509
-
510
- #### @http-response
511
-
512
- Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response code,
513
- a `description`, and a `schema`.
514
-
515
- If no `description` is provided then one will be automatically built using the `statusCode`.
516
-
517
- 📝 Note that you can specify as many `@http-parameter` annotations as needed.
518
-
519
- ```apex
520
- /**
521
- * @description This is a sample HTTP Post method
522
- * @return A String SObject.
523
- * @http-response
524
- * statusCode: 200
525
- * schema: SuccessfulResponseClassName
526
- * @http-response
527
- * statusCode: 500
528
- * description: Status Code 500 - An internal server error occurred.
529
- * schema:
530
- * type: string
531
- */
532
- @HttpPost
533
- global static String doPost() {
534
- // ...
535
- }
536
- ```
537
-
538
- #### Class References
539
-
540
- Whenever specifying a `schema` parameter, you can pass as a string the name of any class in your source code. This
541
- class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi definition.
542
-
543
- The tool will parse the class and create a reference that complies with [Apex's support for User-Defined Types](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm#ApexRESTUserDefinedTypes)
544
-
545
- ##### Reference Overrides
546
-
547
- When dealing with references, there might be cases when you want to manually tell the parser what type of object a property
548
- or field is. For example, let's say we have a class that looks as follows
549
-
550
- ```apex
551
- public class MyClass {
552
- public Object myObject;
553
- public Account myAccountRecord;
554
- }
555
- ```
556
-
557
- In this case `myObject` has a type of `Object`, and `myAccountRecord` is an SObject. Neither of these will be accurately
558
- parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any properties.
559
-
560
- To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override its
561
- type during parsing. In this annotation you can specify the same thing you would in any `schema` property when dealing with any
562
- of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
563
-
564
- ```apex
565
- public class MyClass {
566
- /**
567
- * @description This is a generic reference to another class
568
- * @http-schema MyOtherClassName
569
- */
570
- public Object myObject;
571
-
572
- /**
573
- * @description This is a reference to an Account SObject
574
- * @http-schema
575
- * type: object
576
- * properties:
577
- * Id:
578
- * type: string
579
- * Name:
580
- * type: string
581
- * CustomField__c:
582
- * type: number
583
- */
584
- public Account myAccountRecord;
585
- }
586
- ```
587
-
588
- ---
589
-
590
- If dealing with a collection, you can also specify the name of the reference either using the `List` or `Set` syntax.
591
-
592
- 📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
593
- deep are supported (e.g. List<List<String>> is not supported). This is only a limitation when referencing collections
594
- on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a referenced
595
- class as part of your codebase.
596
-
597
- Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
598
- to convert that to a valid specification. For this use case, define a Custom Schema as explained below.
599
-
600
- ```apex
601
- /**
602
- * @description This is a sample HTTP Post method
603
- * @http-request-body
604
- * description: This is an example of a request body
605
- * schema: List<ClassName>
606
- */
607
- @HttpPost
608
- global static void doPost() {
609
- ///...
610
- }
611
- ```
612
-
613
- Inner class references are also supported, but note that you need to pass the full name of the reference,
614
- by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP method
615
- referencing it.
616
-
617
- ```apex
618
- /**
619
- * @description This is a sample HTTP Post method
620
- * @http-request-body
621
- * description: This is an example of a request body
622
- * schema: ParentClass.InnerClass
623
- */
624
- @HttpPost
625
- global static void doPost() {
626
- ///...
627
- }
628
- ```
629
-
630
- #### Custom Schemas
631
-
632
- For any `schema` parameter in any of the HTTP ApexDocs annotations, besides specifying the name of a class, you
633
- can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an `array`
634
-
635
- **Primitives**
636
-
637
- For primitives, you should specify the `type` and an optional `format`, as defined by the [OpenApi Specification on Data Types](https://spec.openapis.org/oas/v3.1.0#data-types)
638
-
639
- ```apex
640
- /**
641
- * ...
642
- * schema:
643
- * type: string
644
- * format: password
645
- */
646
- ```
647
-
648
- **Objects**
649
-
650
- To specify a custom object schema, use `object` as the `type`, and specify as many properties as follows:
651
-
652
- ```apex
653
- /**
654
- * schema:
655
- * type: object
656
- * properties:
657
- * id:
658
- * type: string
659
- * description: The super Id.
660
- * name:
661
- * type: string
662
- * phone:
663
- * type: string
664
- * format: byte
665
- */
666
- ```
667
-
668
- Properties can be defined as primitives (as explained above), other objects, or arrays (explained below)
669
-
670
- **Arrays**
671
-
672
- To specify a custom array schema, use `array` as the `type`, and provide an `items` definition. In `items`
673
- you can specify the definition of any other custom type (primitives, objects, or other arrays).
674
-
675
- ```apex
676
- /**
677
- * schema:
678
- * type: array
679
- * items:
680
- * type: object
681
- * properties:
682
- * name:
683
- * type: string
684
- */
685
- ```
686
-
687
- #### SObject References
688
-
689
- ApexDocs is not able to automatically parse SObject references, as it can with class references, as it does
690
- not reach into your org to get existing SObject describes. Because of this, when dealing with SObject references
691
- you should create a Custom Schema as defined above. This will also allow you to specify which specific
692
- fields are being received or returned.
693
-
694
-
695
- ### Considerations
696
-
697
- Please be aware of the following when using ApexDocs to create an OpenApi definition:
698
-
699
- * Map references are resolved as `object` with no properties, as it is not possible to know which keys the map will contain.
700
- When using maps either create a class that better represents the shape of the object and use a Class Reference, or
701
- define a Custom Schema in the `schema` section of the ApexDoc itself.
702
- * Same thing when referencing SObjects, as SObject describe parsing is not supported by the ApexDocs tool. When referencing
703
- SObjects, consider defining a Custom Schema in the `schema` section of the ApexDoc.
704
- * ApexDoc is only able to parse through your source code, so references to other packages (namespaced classes) or any
705
- code that lives outside your source code is not supported. Consider creating a Custom Schema for those situations.
706
- * The return value and received parameters or your methods are currently not being considered when creating the OpenApi definition file.
707
- Instead, use the `@http-response` ApexDoc annotation to specify the return value, and `@http-parameter` to specify any
708
- expected parameter.
709
-
710
- ## Typescript
711
-
712
- ApexDocs provides all necessary type definitions.
713
-
714
- ---
715
-
716
- ## 1.X
717
-
718
- Looking for documentation for version 1.X? Please refer to its [branch](https://github.com/cesarParra/apexdocs/tree/1.x)
1
+ # ApexDocs
2
+
3
+ <p align="center">
4
+ <b>ApexDocs is a Node.js library with CLI capabilities to docGenerator documentation for Salesforce Apex classes.</b>
5
+ </p>
6
+
7
+ [![License](https://img.shields.io/github/license/cesarParra/apexdocs)](https://github.com/cesarParra/apexdocs/blob/master/LICENSE)
8
+
9
+ ## Description
10
+
11
+ ApexDocs was originally built as an alternative to
12
+ the [Java based ApexDoc tool](https://github.com/SalesforceFoundation/ApexDoc) originally created by Aslam Bari and
13
+ later maintained by Salesforce.org, as that tool is no longer being maintained.
14
+
15
+ ApexDocs is a Node.js library built on Typescript and hosted on [npm](https://www.npmjs.com/package/@cparra/apexdocs).
16
+ It offers CLI capabilities to automatically document your source code, based on the ApexDoc style of documentation.
17
+ Additionally, it can be imported and consumed directly by your JavaScript code.
18
+
19
+ There are some key differences between ApexDocs and the Java based ApexDoc tool:
20
+
21
+ - **Recursive file search through your module directory structure**. In an `sfdx` based project, all of your classes
22
+ will be documented by specifying the top-most directory where file search should begin.
23
+ - **Unopinionated documentation site generation**. Instead of creating HTML files, ApexDocs generates a Markdown (.md)
24
+ file per Apex class being documented. This means you can host your files in static web hosting services that parse
25
+ Markdown like Github Pages or Netlify, and use site generators like Jekyll or Gatsby. This gives you the freedom to
26
+ decide how to style your site to match your needs.
27
+
28
+ #### Features
29
+
30
+ * Custom Annotations
31
+
32
+ Any custom annotation defined in the Apexdoc is at the class level are supported, for example the following will be
33
+ output to the resulting markdown file:
34
+
35
+ ```apex
36
+ /**
37
+ * @MyCustomAnnotation This is a custom annotation
38
+ */
39
+ public class MyClass {
40
+ }
41
+ ```
42
+
43
+ * Single Line ApexDoc Blocks
44
+
45
+ 📒 Note: If you wish to have multiple `@` tags in a single line but don't want them to be treated as ApexDoc annotations, you can
46
+ escape them by adding wrapping the annotation in ticks, for example
47
+
48
+ ```apex
49
+ /**
50
+ * @MyCustomAnnotation This is a custom annotation with an `@embedded` annotation
51
+ */
52
+ ```
53
+
54
+ * Support for grouping blocks of related code within a class
55
+ * Support for HTML tags
56
+ * OpenApi REST specification generation
57
+ * Support for ignoring files and members from being documented
58
+ * Namespace support
59
+ * Configuration file support
60
+ * And much, much more!
61
+
62
+ ### Demo
63
+
64
+ ApexDocs currently supports generating markdown files for Jekyll and Docsify sites, as well as generating plain markdown
65
+ files.
66
+
67
+ ### In the wild
68
+
69
+ - [Expression](https://cesarparra.github.io/expression/)
70
+ - [Nimble AMS Docs](https://nimbleuser.github.io/nams-api-docs/#/api-reference/)
71
+ - [Yet Another Salesforce Logger](https://cesarparra.github.io/yet-another-salesforce-logger/#/)
72
+
73
+ ### [Docsify](https://docsify.js.org/)
74
+
75
+ Demo
76
+
77
+ - [Docsify](https://cesarparra.github.io/apexdocs/)
78
+
79
+ ### [Jekyll](https://jekyllrb.com/)
80
+
81
+ Demo
82
+
83
+ - [Jekyll](https://cesarparra.github.io/apexdocs-docsify-example/)
84
+
85
+ ## Installation
86
+
87
+ ```bash
88
+ npm i -g @cparra/apexdocs
89
+ ```
90
+
91
+ ## Usage
92
+
93
+ ### CLI
94
+
95
+ ```bash
96
+ apexdocs-generate
97
+ -s src
98
+ -t docs
99
+ -p global
100
+ -g docsify
101
+ ```
102
+
103
+ The CLI supports the following parameters:
104
+
105
+ | Parameter | Alias | Description | Default | Required |
106
+ |-----------------------------|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|
107
+ | --sourceDir | -s | The directory location which contains your apex .cls classes. | N/A | Yes |
108
+ | --targetDir | -t | The directory location where documentation will be generated to. | `docs` | No |
109
+ | --recursive | -r | Whether .cls classes will be searched for recursively in the directory provided. | `true` | No |
110
+ | --scope | -p | A list of scopes to document. Values should be separated by a space, e.g --scope public private. Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource. | `global` | No |
111
+ | --targetGenerator | -g | Define the static file generator for which the documents will be created. Currently supports: `jekyll`, `docsify`, `plain-markdown`, and `openapi`. | `jekyll` | No |
112
+ | --indexOnly | N/A | Defines whether only the index file should be generated. | `false` | No |
113
+ | --defaultGroupName | N/A | Defines the `@group` name to be used when a file does not specify it. | `Miscellaneous` | No |
114
+ | --sanitizeHtml | N/A | When on, any special character within your ApexDocs is converted into its HTML code representation. This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" because otherwise the content within < and > would be treated as HTML tags and not shown in the output. Content in @example blocks are never sanitized. | true | No |
115
+ | --openApiTitle | N/A | If using "openapi" as the target generator, this allows you to specify the OpenApi title value. | `Apex REST Api` | No |
116
+ | --title | N/A | Allows you to specify the home page main title. If using "openapi" this acts as an alias to the openApiTitle parameter | `Classes` | No |
117
+ | --namespace | N/A | The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url. | N/A | No |
118
+ | --openApiFileName | N/A | If using "openapi" as the target generator, this allows you to specify the name of the output file. | `openapi` | No |
119
+ | --sortMembersAlphabetically | N/A | Whether to sort the members of a class alphabetically. | `false` | No |
120
+ | --includeMetadata | N/A | Whether to include the file's meta.xml information: Whether it is active and and the API version | false | No |
121
+ | --documentationRootDir | N/A | The root directory where the documentation will be generated. This is useful when you want to generate the documentation in a subdirectory of your project. | N/A | No |
122
+
123
+ ### Using a configuration file
124
+
125
+ You can also use a configuration file to define the parameters that will be used when generating the documentation. Apexdocs
126
+ uses [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) to load the configuration file, which means it supports
127
+ the following formats:
128
+
129
+ - A `package.json` property, e.g. `{ "apexdocs": { "sourceDir": "src", "targetDir": "docs" } }`
130
+ - A `.apexdocsrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`
131
+ - An `apexdocs.config.js` file that exports an object
132
+ - A `apexdocs.config.ts` file that exports an object
133
+
134
+ The configuration file should be placed in the root directory of your project.
135
+
136
+ **Note that when using a configuration file, you can still override any of the parameters by passing them through the CLI.**
137
+
138
+ When defining a `.js` or `.ts` configuration file, your object export can also contain the following functions that will
139
+ allow you to override some of the default behavior:
140
+
141
+ - `onBeforeFileWrite` - A function that will be called before a file is written to disk. It receives a `TargetFile` object
142
+ that contains the file's content, path, and name, etc. It should return a `TargetFile` object with the updated content.
143
+ The full object definition can be imported from `@cparra/apexdocs/lib/settings`
144
+ - `onAfterProcess` - A function that will be called after all files have been processed. It receives a `TargetFile[]` array
145
+ with all of the files that were processed and does not return anything.
146
+ - `frontMatterHeader` - A function that will be called before the front matter is written to the file (when using the Jekyll generator).
147
+ It receives a `TargetType` object
148
+ and should return a list of strings that will be written to the file as the front matter.
149
+ The full object definition can be imported from `@cparra/apexdocs/lib/settings`
150
+ and contains the following properties:
151
+ - `name` - The name of the type
152
+ - `typeName` - Can be 'class', 'interface', or 'enum'
153
+ - `accessModifier` - The access modifier of the type
154
+ - `group` - The group to which the type belongs (if any)
155
+ - `description` - The description of the type as defined in the ApexDoc
156
+
157
+ ```typescript
158
+ import {TargetFile} from "@cparra/apexdocs/lib/settings";
159
+ export default {
160
+ onBeforeFileWrite: (file: TargetFile): TargetFile => {
161
+ console.log('onBefore writing', file);
162
+ return file;
163
+ },
164
+ onAfterProcess: (files: TargetFile[]) => {
165
+ console.log('onAfterProcess files', files);
166
+ },
167
+ };
168
+
169
+ ```
170
+
171
+ ### Importing to your project
172
+
173
+ If you are just interested in the Apex parsing capabilities, you can use the
174
+ standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
175
+ which is what gets used by this library behind the scenes to generate the documentation files.
176
+
177
+ ## Documentation Format
178
+
179
+ ApexDocs picks up blocks of comments throughout your `.cls` files. The block must begin with `/**` and end with `*/`.
180
+
181
+ ### Documenting Classes and Interfaces
182
+
183
+ The following tags are supported at the class or interface level:
184
+
185
+ **Note** Any custom generated tag is also supported. Custom tags can be added with at symbol (`@`) followed by the name
186
+ of the tag. For example `@custom-tag`
187
+
188
+ | Tag | Description |
189
+ |----------------|------------------------------------------|
190
+ | `@description` | One or more lines describing the class. |
191
+ | `@see` | The name of a related class. |
192
+ | `@group` | The group to which the class belongs to. |
193
+ | `@author` | The author of the class. |
194
+ | `@date` | The date the class was created. |
195
+
196
+ **Example**
197
+
198
+ ```apex
199
+ /**
200
+ * @description This is my class description.
201
+ */
202
+ public with sharing class TestClass {
203
+ }
204
+ ```
205
+
206
+ ### Documenting Enums
207
+
208
+ The following tags are supported on the enum level:
209
+
210
+ | Tag | Description |
211
+ |----------------|--------------------------------------------------|
212
+ | `@description` | One or more lines describing the enum. |
213
+ | `@see` | The name of a related class, enum, or interface. |
214
+ | `@group` | The group to which the enum belongs to. |
215
+ | `@author` | The author of the enum. |
216
+ | `@date` | The date the enum was created. |
217
+
218
+ **Example**
219
+
220
+ ```apex
221
+ /**
222
+ * @description This is my enum description.
223
+ */
224
+ public Enum ExampleEnum {
225
+ VALUE_1, VALUE_2
226
+ }
227
+ ```
228
+
229
+ ### Documenting Enum Values
230
+
231
+ The following tags are supported on the enum value level:
232
+
233
+ | Tag | Description |
234
+ |----------------|-----------------------------------------|
235
+ | `@description` | One or more lines describing the value. |
236
+
237
+ **Example**
238
+
239
+ ```apex
240
+ public enum ExampleEnum {
241
+ /** @description This is my enum value description. */
242
+ VALUE_1,
243
+ /** @description This is my other enum value description. */
244
+ VALUE_2
245
+ }
246
+ ```
247
+
248
+ ### Documenting Properties
249
+
250
+ The following tags are supported on the property level:
251
+
252
+ | Tag | Description |
253
+ |----------------|--------------------------------------------|
254
+ | `@description` | One or more lines describing the property. |
255
+
256
+ **Example**
257
+
258
+ ```apex
259
+ /**
260
+ * @description This is my property description.
261
+ */
262
+ public String ExampleProperty { get; set; }
263
+ ```
264
+
265
+ ### Documenting Methods and Constructors
266
+
267
+ Methods and constructors support the same tags.
268
+
269
+ The following tags are supported on the method level:
270
+
271
+ | Tag | Description |
272
+ |------------------------------|---------------------------------------------------|
273
+ | `@description` | One or more lines describing the method. |
274
+ | `@param` _paramName_ | Description of a single parameter. |
275
+ | `@return` | Description of the return value of the method. |
276
+ | `@example` | Example of how the code can be used or called. |
277
+ | `@throws` _ExceptionName_ | Description of an exception thrown by the method. |
278
+ | `@exception` _ExceptionName_ | Same as `@throws`. V2 only |
279
+ | `@mermaid` | Diagrams in Mermaid format. |
280
+
281
+ **Example**
282
+
283
+ ```apex
284
+ /**
285
+ * @description This is my method description.
286
+ * @param action The action to execute.
287
+ * @return The result of the operation.
288
+ * @example
289
+ * Object result = SampleClass.call('exampleAction');
290
+ */
291
+ public static Object call(String action) {
292
+ }
293
+ ```
294
+
295
+ ### Grouping Declarations Within A Class
296
+
297
+ A class might have members that should be grouped together. For example, you can have a class for constants with
298
+ groups of constants that should be grouped together because they share a common behavior (e.g. different groups
299
+ of constants representing the possible values for different picklists.)
300
+
301
+ You can group things together within a class by using the following syntax:
302
+
303
+ ```apex
304
+ // @start-group Group Name or Description
305
+ public static final String CONSTANT_FOO = 'Foo';
306
+ public static final String CONSTANT_BAR = 'Bar';
307
+ // @end-group
308
+ ```
309
+
310
+ Groups of members are displayed together under their own subsection after its name or description.
311
+
312
+ Some notes about grouping:
313
+
314
+ * This is only supported on classes, NOT enums and interfaces
315
+ * Supports
316
+ * Properties
317
+ * Fields (variables and constants)
318
+ * Constructors
319
+ * Methods
320
+ * BUT only members of the same type are grouped together. For example,
321
+ if you have a group that contains properties and methods the properties will be grouped together under Properties ->
322
+ Group Name, and the methods will be grouped together under Methods -> Group Name
323
+ * Does not support inner types (inner classes, interfaces, and enums)
324
+ * It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for
325
+ that file.
326
+
327
+ ### Inline linking
328
+
329
+ Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that
330
+ class file for easy navigation.
331
+
332
+ Apexdocs recognizes 2 different syntax when linking files:
333
+
334
+ - Javadoc's `{@link FileName}` syntax
335
+ - A class name wrapped in between `<<` `>>`.
336
+
337
+ **Example**
338
+
339
+ ```apex
340
+ /**
341
+ * @description This is my method description. This method receives an <<ExampleClass>>.
342
+ * @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
343
+ * @return The result of the operation.
344
+ */
345
+ public static Object doSomething(ExampleClass param1) {}
346
+ ```
347
+
348
+ ---
349
+
350
+ Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
351
+
352
+ ### HTML support
353
+
354
+ For the most part all HTML is sanitized when the `--sanitizeHtml` flag is passed a true value (which is the default).
355
+ But there are some tags are allowed to have for the possibility of better
356
+ styling long text.
357
+
358
+ - Allowed tags are: `br`, `p`, `ul`, `li`, and `code`
359
+
360
+ Example
361
+
362
+ ```apex
363
+ /**
364
+ * @description <p>This is a paragraph</p>
365
+ * <p>And this is another paragraph</p>
366
+ * <ul>
367
+ * <li>This is a list item</li>
368
+ * <li>This is another list item</li>
369
+ * </ul>
370
+ */
371
+ class MyClass {
372
+ }
373
+ ```
374
+
375
+ ⚠️When the `--sanitizeHtml` flag is ON, any special character between code blocks (i.e. \```, \`, or `<code>`) will also
376
+ be escaped.
377
+ So if you have references to Apex generic collections (Set, List, or Maps) they will not look right, as the < and >
378
+ symbols will be escaped.
379
+ To prevent this you can turn the flag off, but be aware of the special considerations when doing this described below.
380
+
381
+ ---
382
+
383
+ For full control over the output you can also turn off the `--sanitizeHtml` flag, which will allow you
384
+ to have any desired HTML within your docs.
385
+
386
+ ⚠️When the `--sanitizeHtml` flag is OFF, references to Apex generic collections (Set, List or Maps) can be problematic
387
+ as they will be treated as an HTML tag and not displayed. For example if you have something
388
+ like `@description Returns a List<String>`
389
+ the `<String>` portion will be treated as HTML and thus not appear on the page.
390
+
391
+ To fix this issue, when not sanitizing HTML, you should wrap any code that contain special characters that can be
392
+ treated as HTML within '\`'
393
+ or within `<code>` tags.
394
+
395
+ ### Displaying diagrams
396
+
397
+ You can display diagrams in your documentation by leveraging Github's built-in [Mermaid](https://mermaid-js.github.io/mermaid/#/) support.
398
+
399
+ If you are using a markdown generator that supports Mermaid (e.g. [Github's markdown](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/),
400
+ you can add diagrams to your documentation by using the
401
+ `@mermaid` tag.
402
+
403
+ **Example**
404
+
405
+ ```apex
406
+ /**
407
+ * @mermaid
408
+ * graph TD
409
+ * A[Christmas] -->|Get money| B(Go shopping)
410
+ * B --> C{Let me think}
411
+ * C -->|One| D[Laptop]
412
+ * C -->|Two| E[iPhone]
413
+ * C -->|Three| F[Car]
414
+ */
415
+ public class MyClass {
416
+ }
417
+ ```
418
+
419
+ [Here's an example of how that looks](/docs/types/Classes/nspc.AnotherInterface.md)
420
+
421
+ ### Ignoring files and members
422
+
423
+ You can ignore files and members by using the `@ignore` tag on any ApexDoc block. If used at the class level, the entire
424
+ file will be ignored. If used at the member level, only that member will be ignored.
425
+
426
+ Example
427
+
428
+ ```apex
429
+ /**
430
+ * @ignore
431
+ */
432
+ public class MyClass {
433
+ public static void myMethod() {}
434
+ }
435
+ ```
436
+
437
+ ## Generating OpenApi REST Definitions
438
+
439
+ ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
440
+
441
+ ### Usage
442
+
443
+ To create an OpenApi specification file, run the `apexdocs-generate` and pass `openapi` to the `--targetGenerator` parameter.
444
+ When using this generator, you can also pass a custom title through the `--openApiTitle` parameter. This title will be placed
445
+ in the output file's `info.title` property, as defined by the [OpenApi documentation for the Info Object](https://spec.openapis.org/oas/v3.1.0#info-object)
446
+
447
+
448
+ ```shell
449
+ apexdocs-generate -s ./src -t docs -g openapi --openApiTitle "Custom OpenApi Title"
450
+ ```
451
+
452
+ ### How It Works
453
+
454
+ When generating an OpenApi document, since `@RestResource` classes need to be global in Apex, the `--scope` parameter will be ignored.
455
+ Instead, ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
456
+
457
+ Once it finishes running, a file named `openapi.json` will be created in the specified `--targetDir`.
458
+
459
+ ### Configuring What Gets Created
460
+
461
+ ApexDocs will automatically parse your source code and generate the OpenApi definition based on the HTTP related Apex
462
+ annotations (RestResource, HttpDelete, HttpGet, HttpPatch, HttpPost, HttpGet). The different HTTP annotations will be used to generate a file that complies with the [OpenApi Specification v3.1.0](https://spec.openapis.org/oas/v3.1.0)
463
+
464
+ Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs, relying on
465
+ some custom annotations that are specific to generating OpenApi definitions:
466
+
467
+ * `@http-request-body`
468
+ * `@http-parameter`
469
+ * `@http-response`
470
+
471
+ #### @http-request-body
472
+
473
+ Allows you to specify the HTTP request's expected request body. It supports receiving a `description`,
474
+ whether it is `required` or not, and a `schema`, which defines the shape of the object that is expected.
475
+
476
+ 📝 Note that only one `@http-request-body` should be defined per method. If you add more than one, only
477
+ a single one will be used when generating the OpenApi definition.
478
+
479
+ The `schema` can either be a reference to another class in your source code (see the `Class References` section below)
480
+ or a fully defined custom schema (See the `Custom Schemas` section below).
481
+
482
+ Example
483
+ ```apex
484
+ /**
485
+ * @description This is a sample HTTP Post method
486
+ * @http-request-body
487
+ * description: This is an example of a request body
488
+ * required: true
489
+ * schema: ClassName
490
+ */
491
+ @HttpPost
492
+ global static void doPost() {
493
+ ///...
494
+ }
495
+ ```
496
+
497
+ 📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
498
+ so spacing is important.
499
+
500
+ #### @http-parameter
501
+
502
+ Allows you to specify any HTTP parameter expected by your method. It supports receiving a `name`,
503
+ an `in` as defined by the supported [Parameter Locations](https://spec.openapis.org/oas/v3.1.0#parameter-locations),
504
+ whether it is `required` or not, a `description`, and a `schema`.
505
+
506
+ 📝 Note that you can specify as many `@http-parameter` annotations as needed.
507
+
508
+ Example
509
+ ```apex
510
+ /**
511
+ * @description This is a sample HTTP Post method
512
+ * @return A String SObject.
513
+ * @http-parameter
514
+ * name: limit
515
+ * in: query
516
+ * required: true
517
+ * description: Limits the number of items on a page
518
+ * schema:
519
+ * type: integer
520
+ * @http-parameter
521
+ * name: complex
522
+ * in: cookie
523
+ * schema: MyClassName
524
+ */
525
+ @HttpPost
526
+ global static String doPost() {
527
+ // ..
528
+ }
529
+ ```
530
+
531
+ 📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
532
+ so spacing is important.
533
+
534
+ #### @http-response
535
+
536
+ Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response code,
537
+ a `description`, and a `schema`.
538
+
539
+ If no `description` is provided then one will be automatically built using the `statusCode`.
540
+
541
+ 📝 Note that you can specify as many `@http-parameter` annotations as needed.
542
+
543
+ ```apex
544
+ /**
545
+ * @description This is a sample HTTP Post method
546
+ * @return A String SObject.
547
+ * @http-response
548
+ * statusCode: 200
549
+ * schema: SuccessfulResponseClassName
550
+ * @http-response
551
+ * statusCode: 500
552
+ * description: Status Code 500 - An internal server error occurred.
553
+ * schema:
554
+ * type: string
555
+ */
556
+ @HttpPost
557
+ global static String doPost() {
558
+ // ...
559
+ }
560
+ ```
561
+
562
+ #### Class References
563
+
564
+ Whenever specifying a `schema` parameter, you can pass as a string the name of any class in your source code. This
565
+ class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi definition.
566
+
567
+ The tool will parse the class and create a reference that complies with [Apex's support for User-Defined Types](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm#ApexRESTUserDefinedTypes)
568
+
569
+ ##### Reference Overrides
570
+
571
+ When dealing with references, there might be cases when you want to manually tell the parser what type of object a property
572
+ or field is. For example, let's say we have a class that looks as follows
573
+
574
+ ```apex
575
+ public class MyClass {
576
+ public Object myObject;
577
+ public Account myAccountRecord;
578
+ }
579
+ ```
580
+
581
+ In this case `myObject` has a type of `Object`, and `myAccountRecord` is an SObject. Neither of these will be accurately
582
+ parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any properties.
583
+
584
+ To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override its
585
+ type during parsing. In this annotation you can specify the same thing you would in any `schema` property when dealing with any
586
+ of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
587
+
588
+ ```apex
589
+ public class MyClass {
590
+ /**
591
+ * @description This is a generic reference to another class
592
+ * @http-schema MyOtherClassName
593
+ */
594
+ public Object myObject;
595
+
596
+ /**
597
+ * @description This is a reference to an Account SObject
598
+ * @http-schema
599
+ * type: object
600
+ * properties:
601
+ * Id:
602
+ * type: string
603
+ * Name:
604
+ * type: string
605
+ * CustomField__c:
606
+ * type: number
607
+ */
608
+ public Account myAccountRecord;
609
+ }
610
+ ```
611
+
612
+ ---
613
+
614
+ If dealing with a collection, you can also specify the name of the reference either using the `List` or `Set` syntax.
615
+
616
+ 📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
617
+ deep are supported (e.g. List<List<String>> is not supported). This is only a limitation when referencing collections
618
+ on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a referenced
619
+ class as part of your codebase.
620
+
621
+ Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
622
+ to convert that to a valid specification. For this use case, define a Custom Schema as explained below.
623
+
624
+ ```apex
625
+ /**
626
+ * @description This is a sample HTTP Post method
627
+ * @http-request-body
628
+ * description: This is an example of a request body
629
+ * schema: List<ClassName>
630
+ */
631
+ @HttpPost
632
+ global static void doPost() {
633
+ ///...
634
+ }
635
+ ```
636
+
637
+ Inner class references are also supported, but note that you need to pass the full name of the reference,
638
+ by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP method
639
+ referencing it.
640
+
641
+ ```apex
642
+ /**
643
+ * @description This is a sample HTTP Post method
644
+ * @http-request-body
645
+ * description: This is an example of a request body
646
+ * schema: ParentClass.InnerClass
647
+ */
648
+ @HttpPost
649
+ global static void doPost() {
650
+ ///...
651
+ }
652
+ ```
653
+
654
+ #### Custom Schemas
655
+
656
+ For any `schema` parameter in any of the HTTP ApexDocs annotations, besides specifying the name of a class, you
657
+ can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an `array`
658
+
659
+ **Primitives**
660
+
661
+ For primitives, you should specify the `type` and an optional `format`, as defined by the [OpenApi Specification on Data Types](https://spec.openapis.org/oas/v3.1.0#data-types)
662
+
663
+ ```apex
664
+ /**
665
+ * ...
666
+ * schema:
667
+ * type: string
668
+ * format: password
669
+ */
670
+ ```
671
+
672
+ **Objects**
673
+
674
+ To specify a custom object schema, use `object` as the `type`, and specify as many properties as follows:
675
+
676
+ ```apex
677
+ /**
678
+ * schema:
679
+ * type: object
680
+ * properties:
681
+ * id:
682
+ * type: string
683
+ * description: The super Id.
684
+ * name:
685
+ * type: string
686
+ * phone:
687
+ * type: string
688
+ * format: byte
689
+ */
690
+ ```
691
+
692
+ Properties can be defined as primitives (as explained above), other objects, or arrays (explained below)
693
+
694
+ **Arrays**
695
+
696
+ To specify a custom array schema, use `array` as the `type`, and provide an `items` definition. In `items`
697
+ you can specify the definition of any other custom type (primitives, objects, or other arrays).
698
+
699
+ ```apex
700
+ /**
701
+ * schema:
702
+ * type: array
703
+ * items:
704
+ * type: object
705
+ * properties:
706
+ * name:
707
+ * type: string
708
+ */
709
+ ```
710
+
711
+ #### SObject References
712
+
713
+ ApexDocs is not able to automatically parse SObject references, as it can with class references, as it does
714
+ not reach into your org to get existing SObject describes. Because of this, when dealing with SObject references
715
+ you should create a Custom Schema as defined above. This will also allow you to specify which specific
716
+ fields are being received or returned.
717
+
718
+
719
+ ### Considerations
720
+
721
+ Please be aware of the following when using ApexDocs to create an OpenApi definition:
722
+
723
+ * Map references are resolved as `object` with no properties, as it is not possible to know which keys the map will contain.
724
+ When using maps either create a class that better represents the shape of the object and use a Class Reference, or
725
+ define a Custom Schema in the `schema` section of the ApexDoc itself.
726
+ * Same thing when referencing SObjects, as SObject describe parsing is not supported by the ApexDocs tool. When referencing
727
+ SObjects, consider defining a Custom Schema in the `schema` section of the ApexDoc.
728
+ * ApexDoc is only able to parse through your source code, so references to other packages (namespaced classes) or any
729
+ code that lives outside your source code is not supported. Consider creating a Custom Schema for those situations.
730
+ * The return value and received parameters or your methods are currently not being considered when creating the OpenApi definition file.
731
+ Instead, use the `@http-response` ApexDoc annotation to specify the return value, and `@http-parameter` to specify any
732
+ expected parameter.
733
+
734
+ ## Typescript
735
+
736
+ ApexDocs provides all necessary type definitions.
737
+
738
+ ---
739
+
740
+ ## 1.X
741
+
742
+ Looking for documentation for version 1.X? Please refer to its [branch](https://github.com/cesarParra/apexdocs/tree/1.x)