@cparra/apexdocs 3.0.0 → 3.1.1

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 (264) hide show
  1. package/README.md +11 -5
  2. package/dist/cli/generate.js +1 -1
  3. package/dist/index.js +1 -1
  4. package/dist/logger-BATX7-be.js +3278 -0
  5. package/package.json +4 -1
  6. package/.github/workflows/ci.yaml +0 -22
  7. package/.github/workflows/close_stale.yml +0 -22
  8. package/.prettierrc.js +0 -7
  9. package/__mocks__/chalk.js +0 -12
  10. package/__mocks__/log-update.js +0 -6
  11. package/eslint.config.mjs +0 -10
  12. package/examples/README.md +0 -5
  13. package/examples/docsify/README.md +0 -17
  14. package/examples/docsify/apexdocs.config.ts +0 -13
  15. package/examples/docsify/classes/ASampleClass.cls +0 -57
  16. package/examples/docsify/classes/CodeControl.cls +0 -19
  17. package/examples/docsify/classes/SampleClass.cls +0 -95
  18. package/examples/docsify/classes/SampleInterface.cls +0 -17
  19. package/examples/docsify/classes/SomeDto.cls +0 -122
  20. package/examples/docsify/docs/.nojekyll +0 -0
  21. package/examples/docsify/docs/README.md +0 -25
  22. package/examples/docsify/docs/_config.yml +0 -1
  23. package/examples/docsify/docs/index.html +0 -22
  24. package/examples/docsify/docs/miscellaneous/ASampleClass.md +0 -88
  25. package/examples/docsify/docs/miscellaneous/CodeControl.md +0 -107
  26. package/examples/docsify/docs/miscellaneous/SomeDto.md +0 -244
  27. package/examples/docsify/docs/sample-classes/SampleClass.md +0 -171
  28. package/examples/docsify/docs/sample-interfaces/SampleInterface.md +0 -36
  29. package/examples/docsify/package-lock.json +0 -2459
  30. package/examples/docsify/package.json +0 -14
  31. package/examples/imported/.forceignore +0 -12
  32. package/examples/imported/README.md +0 -6
  33. package/examples/imported/config/project-scratch-def.json +0 -5
  34. package/examples/imported/docs/index.md +0 -109
  35. package/examples/imported/docs/miscellaneous/BaseClass.md +0 -13
  36. package/examples/imported/docs/miscellaneous/MultiInheritanceClass.md +0 -69
  37. package/examples/imported/docs/miscellaneous/ParentInterface.md +0 -12
  38. package/examples/imported/docs/miscellaneous/ReferencedEnum.md +0 -5
  39. package/examples/imported/docs/miscellaneous/SampleException.md +0 -21
  40. package/examples/imported/docs/miscellaneous/SampleInterface.md +0 -113
  41. package/examples/imported/docs/miscellaneous/Url.md +0 -308
  42. package/examples/imported/docs/sample-enums/SampleEnum.md +0 -33
  43. package/examples/imported/docs/samplegroup/SampleClass.md +0 -167
  44. package/examples/imported/force-app/classes/BaseClass.cls +0 -3
  45. package/examples/imported/force-app/classes/MultiInheritanceClass.cls +0 -1
  46. package/examples/imported/force-app/classes/ParentInterface.cls +0 -3
  47. package/examples/imported/force-app/classes/ReferencedEnum.cls +0 -3
  48. package/examples/imported/force-app/classes/SampleClass.cls +0 -72
  49. package/examples/imported/force-app/classes/SampleEnum.cls +0 -30
  50. package/examples/imported/force-app/classes/SampleException.cls +0 -17
  51. package/examples/imported/force-app/classes/SampleInterface.cls +0 -50
  52. package/examples/imported/force-app/classes/Url.cls +0 -196
  53. package/examples/imported/package-lock.json +0 -665
  54. package/examples/imported/package.json +0 -6
  55. package/examples/imported/scripts/process-docs.mjs +0 -16
  56. package/examples/imported/sfdx-project.json +0 -12
  57. package/examples/markdown/.forceignore +0 -12
  58. package/examples/markdown/README.md +0 -7
  59. package/examples/markdown/config/project-scratch-def.json +0 -5
  60. package/examples/markdown/docs/index.md +0 -109
  61. package/examples/markdown/docs/miscellaneous/BaseClass.md +0 -16
  62. package/examples/markdown/docs/miscellaneous/MultiInheritanceClass.md +0 -72
  63. package/examples/markdown/docs/miscellaneous/ParentInterface.md +0 -15
  64. package/examples/markdown/docs/miscellaneous/ReferencedEnum.md +0 -8
  65. package/examples/markdown/docs/miscellaneous/SampleException.md +0 -24
  66. package/examples/markdown/docs/miscellaneous/SampleInterface.md +0 -116
  67. package/examples/markdown/docs/miscellaneous/Url.md +0 -311
  68. package/examples/markdown/docs/sample-enums/SampleEnum.md +0 -36
  69. package/examples/markdown/docs/samplegroup/SampleClass.md +0 -170
  70. package/examples/markdown/force-app/classes/BaseClass.cls +0 -3
  71. package/examples/markdown/force-app/classes/MultiInheritanceClass.cls +0 -1
  72. package/examples/markdown/force-app/classes/ParentInterface.cls +0 -3
  73. package/examples/markdown/force-app/classes/ReferencedEnum.cls +0 -3
  74. package/examples/markdown/force-app/classes/SampleClass.cls +0 -72
  75. package/examples/markdown/force-app/classes/SampleEnum.cls +0 -30
  76. package/examples/markdown/force-app/classes/SampleException.cls +0 -17
  77. package/examples/markdown/force-app/classes/SampleInterface.cls +0 -50
  78. package/examples/markdown/force-app/classes/Url.cls +0 -196
  79. package/examples/markdown/package-lock.json +0 -665
  80. package/examples/markdown/package.json +0 -20
  81. package/examples/markdown/sfdx-project.json +0 -12
  82. package/examples/markdown-jsconfig/.forceignore +0 -12
  83. package/examples/markdown-jsconfig/README.md +0 -9
  84. package/examples/markdown-jsconfig/apexdocs.config.mjs +0 -22
  85. package/examples/markdown-jsconfig/config/project-scratch-def.json +0 -5
  86. package/examples/markdown-jsconfig/docs/index.md +0 -12
  87. package/examples/markdown-jsconfig/docs/miscellaneous/Url.md +0 -315
  88. package/examples/markdown-jsconfig/force-app/classes/Url.cls +0 -196
  89. package/examples/markdown-jsconfig/package-lock.json +0 -665
  90. package/examples/markdown-jsconfig/package.json +0 -15
  91. package/examples/markdown-jsconfig/sfdx-project.json +0 -12
  92. package/examples/open-api/README.md +0 -5
  93. package/examples/open-api/config/project-scratch-def.json +0 -13
  94. package/examples/open-api/docs/openapi.json +0 -14
  95. package/examples/open-api/force-app/main/default/classes/ChildClass.cls +0 -42
  96. package/examples/open-api/force-app/main/default/classes/SampleClass.cls +0 -167
  97. package/examples/open-api/force-app/main/default/restapi/SampleRestResource.cls +0 -195
  98. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceToSkip.cls +0 -35
  99. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceWithInnerClass.cls +0 -24
  100. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +0 -15
  101. package/examples/open-api/force-app/main/default/restapi/references/Reference1.cls +0 -9
  102. package/examples/open-api/force-app/main/default/restapi/references/Reference2.cls +0 -9
  103. package/examples/open-api/force-app/main/default/restapi/references/Reference3.cls +0 -3
  104. package/examples/open-api/force-app/main/default/restapi/references/Reference4.cls +0 -3
  105. package/examples/open-api/force-app/main/default/restapi/references/Reference5.cls +0 -3
  106. package/examples/open-api/force-app/main/default/restapi/references/Reference6.cls +0 -6
  107. package/examples/open-api/force-app/main/default/restapi/references/Reference7.cls +0 -3
  108. package/examples/open-api/package-lock.json +0 -724
  109. package/examples/open-api/package.json +0 -20
  110. package/examples/open-api/sfdx-project.json +0 -12
  111. package/examples/vitepress/.forceignore +0 -12
  112. package/examples/vitepress/README.md +0 -25
  113. package/examples/vitepress/apexdocs.config.ts +0 -113
  114. package/examples/vitepress/config/project-scratch-def.json +0 -13
  115. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js +0 -259
  116. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  117. package/examples/vitepress/docs/.vitepress/cache/deps/_metadata.json +0 -40
  118. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js +0 -11474
  119. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js.map +0 -7
  120. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js +0 -9172
  121. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js.map +0 -7
  122. package/examples/vitepress/docs/.vitepress/cache/deps/package.json +0 -3
  123. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4339
  124. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  125. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -567
  126. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  127. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js +0 -323
  128. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js.map +0 -7
  129. package/examples/vitepress/docs/.vitepress/config.mts +0 -21
  130. package/examples/vitepress/docs/.vitepress/sidebar.json +0 -119
  131. package/examples/vitepress/docs/api-examples.md +0 -49
  132. package/examples/vitepress/docs/index-frontmatter.md +0 -16
  133. package/examples/vitepress/docs/index.md +0 -56
  134. package/examples/vitepress/docs/markdown-examples.md +0 -85
  135. package/examples/vitepress/docs/miscellaneous/BaseClass.md +0 -20
  136. package/examples/vitepress/docs/miscellaneous/MultiInheritanceClass.md +0 -76
  137. package/examples/vitepress/docs/miscellaneous/ParentInterface.md +0 -19
  138. package/examples/vitepress/docs/miscellaneous/ReferencedEnum.md +0 -15
  139. package/examples/vitepress/docs/miscellaneous/SampleException.md +0 -28
  140. package/examples/vitepress/docs/miscellaneous/SampleInterface.md +0 -116
  141. package/examples/vitepress/docs/miscellaneous/Url.md +0 -317
  142. package/examples/vitepress/docs/sample-enums/SampleEnum.md +0 -40
  143. package/examples/vitepress/docs/samplegroup/SampleClass.md +0 -174
  144. package/examples/vitepress/force-app/main/default/classes/BaseClass.cls +0 -3
  145. package/examples/vitepress/force-app/main/default/classes/MultiInheritanceClass.cls +0 -1
  146. package/examples/vitepress/force-app/main/default/classes/ParentInterface.cls +0 -3
  147. package/examples/vitepress/force-app/main/default/classes/ReferencedEnum.cls +0 -5
  148. package/examples/vitepress/force-app/main/default/classes/Url.cls +0 -198
  149. package/examples/vitepress/force-app/main/default/classes/feature-a/SampleClass.cls +0 -73
  150. package/examples/vitepress/force-app/main/default/classes/feature-a/SampleEnum.cls +0 -30
  151. package/examples/vitepress/force-app/main/default/classes/feature-a/SampleException.cls +0 -17
  152. package/examples/vitepress/force-app/main/default/classes/feature-a/SampleInterface.cls +0 -46
  153. package/examples/vitepress/package-lock.json +0 -2574
  154. package/examples/vitepress/package.json +0 -18
  155. package/examples/vitepress/sfdx-project.json +0 -12
  156. package/jest.config.js +0 -10
  157. package/jest.d.ts +0 -7
  158. package/src/application/Apexdocs.ts +0 -69
  159. package/src/application/__tests__/apex-file-reader.spec.ts +0 -128
  160. package/src/application/apex-file-reader.ts +0 -56
  161. package/src/application/file-system.ts +0 -69
  162. package/src/application/file-writer.ts +0 -43
  163. package/src/application/generators/markdown.ts +0 -45
  164. package/src/application/generators/openapi.ts +0 -75
  165. package/src/cli/args.ts +0 -55
  166. package/src/cli/commands/markdown.ts +0 -56
  167. package/src/cli/commands/openapi.ts +0 -36
  168. package/src/cli/generate.ts +0 -32
  169. package/src/core/__test__/manifest.spec.ts +0 -16
  170. package/src/core/manifest.ts +0 -90
  171. package/src/core/markdown/__test__/expect-extensions.ts +0 -32
  172. package/src/core/markdown/__test__/generating-class-docs.spec.ts +0 -362
  173. package/src/core/markdown/__test__/generating-docs.spec.ts +0 -378
  174. package/src/core/markdown/__test__/generating-enum-docs.spec.ts +0 -61
  175. package/src/core/markdown/__test__/generating-interface-docs.spec.ts +0 -169
  176. package/src/core/markdown/__test__/generating-reference-guide.spec.ts +0 -196
  177. package/src/core/markdown/__test__/inheritance-chain.test.ts +0 -54
  178. package/src/core/markdown/__test__/test-helpers.ts +0 -25
  179. package/src/core/markdown/adapters/__tests__/documentables.spec.ts +0 -109
  180. package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +0 -150
  181. package/src/core/markdown/adapters/__tests__/link-generator.spec.ts +0 -130
  182. package/src/core/markdown/adapters/__tests__/references.spec.ts +0 -136
  183. package/src/core/markdown/adapters/apex-types.ts +0 -238
  184. package/src/core/markdown/adapters/documentables.ts +0 -115
  185. package/src/core/markdown/adapters/fields-and-properties.ts +0 -45
  186. package/src/core/markdown/adapters/generate-link.ts +0 -82
  187. package/src/core/markdown/adapters/inline.ts +0 -143
  188. package/src/core/markdown/adapters/methods-and-constructors.ts +0 -133
  189. package/src/core/markdown/adapters/reference-guide.ts +0 -37
  190. package/src/core/markdown/adapters/renderable-bundle.ts +0 -61
  191. package/src/core/markdown/adapters/renderable-to-page-data.ts +0 -91
  192. package/src/core/markdown/adapters/type-utils.ts +0 -13
  193. package/src/core/markdown/adapters/types.d.ts +0 -180
  194. package/src/core/markdown/generate-docs.ts +0 -210
  195. package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +0 -290
  196. package/src/core/markdown/reflection/__test__/helpers.ts +0 -18
  197. package/src/core/markdown/reflection/__test__/remove-excluded-tags.spec.ts +0 -200
  198. package/src/core/markdown/reflection/filter-scope.ts +0 -13
  199. package/src/core/markdown/reflection/inheritance-chain-expanion.ts +0 -22
  200. package/src/core/markdown/reflection/inheritance-chain.ts +0 -23
  201. package/src/core/markdown/reflection/inherited-member-expansion.ts +0 -105
  202. package/src/core/markdown/reflection/reflect-source.ts +0 -123
  203. package/src/core/markdown/reflection/remove-excluded-tags.ts +0 -168
  204. package/src/core/markdown/reflection/sort-types-and-members.ts +0 -61
  205. package/src/core/markdown/templates/class-template.ts +0 -75
  206. package/src/core/markdown/templates/constructors-partial-template.ts +0 -32
  207. package/src/core/markdown/templates/documentable-partial-template.ts +0 -26
  208. package/src/core/markdown/templates/enum-template.ts +0 -12
  209. package/src/core/markdown/templates/fieldsPartialTemplate.ts +0 -23
  210. package/src/core/markdown/templates/grouped-members-partial-template.ts +0 -6
  211. package/src/core/markdown/templates/hookable.ts +0 -7
  212. package/src/core/markdown/templates/interface-template.ts +0 -16
  213. package/src/core/markdown/templates/methods-partial-template.ts +0 -43
  214. package/src/core/markdown/templates/reference-guide.ts +0 -14
  215. package/src/core/markdown/templates/template.ts +0 -114
  216. package/src/core/markdown/templates/type-doc-partial.ts +0 -27
  217. package/src/core/markdown/utils.ts +0 -3
  218. package/src/core/openApiSettings.ts +0 -41
  219. package/src/core/openapi/__tests__/manifest-factory.spec.ts +0 -16
  220. package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +0 -59
  221. package/src/core/openapi/__tests__/open-api.spec.ts +0 -22
  222. package/src/core/openapi/apex-doc-types.ts +0 -26
  223. package/src/core/openapi/apex-type-wrappers/ClassMirrorWrapper.ts +0 -12
  224. package/src/core/openapi/apex-type-wrappers/MethodMirrorWrapper.ts +0 -11
  225. package/src/core/openapi/apex-type-wrappers/__tests__/ClassMirrorWrapper.spec.ts +0 -15
  226. package/src/core/openapi/file-container.ts +0 -13
  227. package/src/core/openapi/manifest-factory.ts +0 -16
  228. package/src/core/openapi/open-api-docs-processor.ts +0 -93
  229. package/src/core/openapi/open-api-types.ts +0 -119
  230. package/src/core/openapi/open-api.ts +0 -45
  231. package/src/core/openapi/openapi-type-file.ts +0 -12
  232. package/src/core/openapi/parser.ts +0 -163
  233. package/src/core/openapi/parsers/Builder.ts +0 -40
  234. package/src/core/openapi/parsers/MethodParser.ts +0 -249
  235. package/src/core/openapi/parsers/ParameterObjectBuilder.ts +0 -13
  236. package/src/core/openapi/parsers/ReferenceBuilder.ts +0 -299
  237. package/src/core/openapi/parsers/RequestBodyBuilder.ts +0 -19
  238. package/src/core/openapi/parsers/ResponsesBuilder.ts +0 -21
  239. package/src/core/openapi/parsers/__tests__/MethodParser.spec.ts +0 -44
  240. package/src/core/openapi/parsers/__tests__/ParameterObjectBuilder.spec.ts +0 -68
  241. package/src/core/openapi/parsers/__tests__/ReferenceBuilder.spec.ts +0 -751
  242. package/src/core/openapi/parsers/__tests__/RequestBodyBuilder.spec.ts +0 -64
  243. package/src/core/openapi/parsers/__tests__/ResponsesBuilder.spec.ts +0 -55
  244. package/src/core/openapi/transpiler.ts +0 -17
  245. package/src/core/openapi/types-repository.ts +0 -54
  246. package/src/core/parse-apex-metadata.ts +0 -30
  247. package/src/core/shared/types.d.ts +0 -150
  248. package/src/core/shared/utils.ts +0 -5
  249. package/src/defaults.ts +0 -21
  250. package/src/index.ts +0 -110
  251. package/src/test-helpers/AnnotationBuilder.ts +0 -29
  252. package/src/test-helpers/ClassMirrorBuilder.ts +0 -69
  253. package/src/test-helpers/DocCommentAnnotationBuilder.ts +0 -24
  254. package/src/test-helpers/DocCommentBuilder.ts +0 -36
  255. package/src/test-helpers/FieldMirrorBuilder.ts +0 -59
  256. package/src/test-helpers/InterfaceMirrorBuilder.ts +0 -39
  257. package/src/test-helpers/MethodMirrorBuilder.ts +0 -77
  258. package/src/test-helpers/SettingsBuilder.ts +0 -17
  259. package/src/util/error-logger.ts +0 -92
  260. package/src/util/fp.ts +0 -3
  261. package/src/util/logger.ts +0 -51
  262. package/src/util/string-utils.ts +0 -7
  263. package/tsconfig.json +0 -25
  264. package/tslint.json +0 -6
@@ -1,119 +0,0 @@
1
- // verified
2
- export type InfoObject = {
3
- title: string;
4
- version: string;
5
- };
6
-
7
- // verified
8
- export type ServerObject = {
9
- url: string;
10
- };
11
-
12
- // verified
13
- export type PathsObject = {
14
- [index: string]: PathItemObject;
15
- };
16
-
17
- // verified
18
- export type PathItemObject = {
19
- description?: string;
20
- get?: OperationObject;
21
- put?: OperationObject;
22
- post?: OperationObject;
23
- delete?: OperationObject;
24
- patch?: OperationObject;
25
- };
26
-
27
- // verified
28
- export type OperationObject = {
29
- tags?: string[];
30
- description?: string;
31
- summary?: string;
32
- requestBody?: RequestBody;
33
- parameters?: ParameterObject[];
34
- responses?: ResponsesObject;
35
- };
36
-
37
- // Parameters
38
- export type ParameterObject = {
39
- name: string;
40
- in: 'query' | 'header' | 'path' | 'cookie';
41
- description?: string;
42
- required?: boolean;
43
- schema?: SchemaObject;
44
- };
45
-
46
- // Request Body
47
- export type RequestBody = {
48
- description?: string;
49
- content: RequestBodyContent;
50
- required?: boolean;
51
- };
52
-
53
- export type RequestBodyContent = {
54
- [index: string]: MediaTypeObject; // Only key supported is "application/json" for now.
55
- };
56
-
57
- export type MediaTypeObject = {
58
- schema?: SchemaObject;
59
- example?: unknown;
60
- examples?: { [index: string]: ExampleObject };
61
- };
62
-
63
- export type ExampleObject = {
64
- summary?: string;
65
- description?: string;
66
- value?: unknown;
67
- };
68
-
69
- // Responses
70
- export type ResponsesObject = {
71
- [index: string]: ResponseObject; // The key will be the status code number
72
- };
73
-
74
- export type ResponseObject = {
75
- description: string;
76
- content?: ContentObject;
77
- };
78
-
79
- export type ContentObject = {
80
- [index: string]: { schema: SchemaObject }; // key is usually 'application/json'
81
- };
82
-
83
- // Common
84
- export type SchemaObject = SchemaObjectObject | SchemaObjectArray | ReferenceObject;
85
-
86
- export type SchemaObjectObject = {
87
- type: string; // This can be "object" (which would require properties), or a primitive
88
- properties?: PropertiesObject;
89
- format?: string;
90
- description?: string;
91
- };
92
-
93
- export type PropertiesObject = {
94
- [index: string]: SchemaObject;
95
- };
96
-
97
- export type SchemaObjectArray = {
98
- type: 'array';
99
- items: SchemaObject;
100
- description?: string;
101
- };
102
-
103
- // Reference and components
104
-
105
- export type ReferenceObject = {
106
- $ref: string;
107
- description?: string;
108
- };
109
-
110
- export type ComponentsObject = {
111
- schemas: {
112
- [index: string]: SchemaObject;
113
- };
114
- };
115
-
116
- export type TagObject = {
117
- name: string;
118
- description?: string;
119
- };
@@ -1,45 +0,0 @@
1
- import { ComponentsObject, InfoObject, PathsObject, ServerObject, TagObject } from './open-api-types';
2
-
3
- const OPEN_API_VERSION = '3.1.0';
4
- const SERVER_URL = '/services/apexrest/';
5
-
6
- /**
7
- * Represents the OpenApi 3.1.0 spec
8
- * https://spec.openapis.org/oas/v3.1.0
9
- */
10
- export class OpenApi {
11
- openapi = OPEN_API_VERSION;
12
- info: InfoObject;
13
- tags: TagObject[];
14
- paths: PathsObject;
15
- servers: ServerObject[];
16
- components?: ComponentsObject;
17
-
18
- constructor(
19
- title: string,
20
- version: string,
21
- private namespace?: string,
22
- ) {
23
- this.info = {
24
- title: title,
25
- version: version,
26
- };
27
-
28
- this.servers = [
29
- {
30
- url: this.getServerUrl(),
31
- },
32
- ];
33
-
34
- this.paths = {};
35
- this.tags = [];
36
- }
37
-
38
- private getServerUrl(): string {
39
- if (!this.namespace) {
40
- return SERVER_URL;
41
- }
42
-
43
- return `${SERVER_URL}${this.namespace}/`;
44
- }
45
- }
@@ -1,12 +0,0 @@
1
- import { OpenApi } from './open-api';
2
- import { OpenApiPageData } from '../shared/types';
3
-
4
- export function createOpenApiFile(fileName: string, openApiModel: OpenApi): OpenApiPageData {
5
- const content = JSON.stringify({ ...openApiModel, namespace: undefined }, null, 2);
6
- return {
7
- outputDocPath: `${fileName}.json`,
8
- content,
9
- frontmatter: null,
10
- group: null,
11
- };
12
- }
@@ -1,163 +0,0 @@
1
- import { ClassMirror, InterfaceMirror, ReflectionResult, Type } from '@cparra/apex-reflection';
2
- import { Logger } from '#utils/logger';
3
- import { UnparsedSourceFile } from '../shared/types';
4
-
5
- export interface TypeParser {
6
- parse(reflect: (apexBundle: UnparsedSourceFile) => ReflectionResult): Type[];
7
- }
8
-
9
- type NameAware = { name: string };
10
-
11
- export class RawBodyParser implements TypeParser {
12
- constructor(
13
- private logger: Logger,
14
- public typeBundles: UnparsedSourceFile[],
15
- ) {}
16
-
17
- parse(reflect: (apexBundle: UnparsedSourceFile) => ReflectionResult): Type[] {
18
- const types = this.typeBundles
19
- .map((currentBundle) => {
20
- this.logger.log(`Parsing file: ${currentBundle.filePath}`);
21
- return reflect(currentBundle);
22
- })
23
- .filter((reflectionResult) => {
24
- return reflectionResult.typeMirror;
25
- })
26
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
27
- .map((reflectionResult) => reflectionResult.typeMirror!);
28
-
29
- return this.addFieldsFromParent(types);
30
- }
31
-
32
- addFieldsFromParent(types: Type[]): Type[] {
33
- const typesWithFields: Type[] = [];
34
- for (const currentType of types) {
35
- if (currentType.type_name !== 'class' && currentType.type_name !== 'interface') {
36
- typesWithFields.push(currentType);
37
- continue;
38
- }
39
-
40
- if (currentType.type_name === 'class') {
41
- let typeAsClass = currentType as ClassMirror;
42
- if (!typeAsClass.extended_class) {
43
- typesWithFields.push(currentType);
44
- continue;
45
- }
46
-
47
- typeAsClass = this.addMembersFromParent(typeAsClass, types);
48
- typesWithFields.push(typeAsClass);
49
- continue;
50
- }
51
-
52
- // At this stage, we can be sure we are dealing with an interface
53
- let typeAsInterface = currentType as InterfaceMirror;
54
- if (!typeAsInterface.extended_interfaces.length) {
55
- typesWithFields.push(currentType);
56
- continue;
57
- }
58
-
59
- typeAsInterface = this.addMethodsFromParent(typeAsInterface, types);
60
- typesWithFields.push(typeAsInterface);
61
- }
62
-
63
- return typesWithFields;
64
- }
65
-
66
- addMembersFromParent(currentClass: ClassMirror, allTypes: Type[]): ClassMirror {
67
- if (!currentClass.extended_class) {
68
- return currentClass;
69
- }
70
- const parent = allTypes.find((currentType: Type) => currentType.name === currentClass.extended_class);
71
- if (!parent || parent.type_name !== 'class') {
72
- return currentClass;
73
- }
74
-
75
- let parentAsClass = parent as ClassMirror;
76
- if (parentAsClass.extended_class) {
77
- parentAsClass = this.addMembersFromParent(parentAsClass, allTypes);
78
- }
79
-
80
- currentClass.fields = [...currentClass.fields, ...this.getInheritedFields(parentAsClass, currentClass)];
81
- currentClass.properties = [...currentClass.properties, ...this.getInheritedProperties(parentAsClass, currentClass)];
82
- currentClass.methods = [...currentClass.methods, ...this.getInheritedMethods(parentAsClass, currentClass)];
83
- return currentClass;
84
- }
85
-
86
- addMethodsFromParent(currentInterface: InterfaceMirror, allTypes: Type[]): InterfaceMirror {
87
- if (!currentInterface.extended_interfaces.length) {
88
- return currentInterface;
89
- }
90
-
91
- const parents = [];
92
- for (const currentInterfaceName of currentInterface.extended_interfaces) {
93
- const parent = allTypes.find((currentType: Type) => currentType.name === currentInterfaceName);
94
- if (parent) {
95
- parents.push(parent);
96
- }
97
- }
98
-
99
- for (const parent of parents) {
100
- let parentAsInterface = parent as InterfaceMirror;
101
- if (parentAsInterface.extended_interfaces.length) {
102
- parentAsInterface = this.addMethodsFromParent(parentAsInterface, allTypes);
103
- }
104
-
105
- currentInterface.methods = [
106
- ...currentInterface.methods,
107
- ...this.getInheritedMethods(parentAsInterface, currentInterface),
108
- ];
109
- }
110
-
111
- return currentInterface;
112
- }
113
-
114
- private getInheritedFields(parentAsClass: ClassMirror, currentClass: ClassMirror) {
115
- return (
116
- parentAsClass.fields
117
- // Filter out private fields
118
- .filter((currentField) => currentField.access_modifier.toLowerCase() !== 'private')
119
- // Filter out fields that also exist on the child
120
- .filter((currentField) => !this.memberExists(currentClass.fields, currentField.name))
121
- .map((currentField) => ({
122
- ...currentField,
123
- inherited: true,
124
- }))
125
- );
126
- }
127
-
128
- private getInheritedProperties(parentAsClass: ClassMirror, currentClass: ClassMirror) {
129
- return (
130
- parentAsClass.properties
131
- // Filter out private properties
132
- .filter((currentProperty) => currentProperty.access_modifier.toLowerCase() !== 'private')
133
- // Filter out properties that also exist on the child
134
- .filter((currentProperty) => !this.memberExists(currentClass.properties, currentProperty.name))
135
- .map((currentProperty) => ({
136
- ...currentProperty,
137
- inherited: true,
138
- }))
139
- );
140
- }
141
-
142
- private getInheritedMethods(
143
- parentAsClass: ClassMirror | InterfaceMirror,
144
- currentClass: ClassMirror | InterfaceMirror,
145
- ) {
146
- return (
147
- parentAsClass.methods
148
- // Filter out private methods
149
- .filter((currentMethod) => currentMethod.access_modifier.toLowerCase() !== 'private')
150
- // Filter out methods that also exist on the child
151
- .filter((currentMethod) => !this.memberExists(currentClass.methods, currentMethod.name))
152
- .map((currentMethod) => ({
153
- ...currentMethod,
154
- inherited: true,
155
- }))
156
- );
157
- }
158
-
159
- memberExists(members: NameAware[], fieldName: string): boolean {
160
- const fieldNames = members.map((currentMember) => currentMember.name);
161
- return fieldNames.includes(fieldName);
162
- }
163
- }
@@ -1,40 +0,0 @@
1
- import { Reference, ReferenceBuilder } from './ReferenceBuilder';
2
- import { ApexDocSchemaObject } from '../../../core/openapi/apex-doc-types';
3
- import { SchemaObject } from '../../../core/openapi/open-api-types';
4
-
5
- export type ApexDocSchemaAware = {
6
- schema: ApexDocSchemaObject;
7
- };
8
-
9
- export abstract class Builder<T, K> {
10
- build(schemaAware: ApexDocSchemaAware): Response<T> {
11
- let reference: Reference | undefined;
12
- if (this.isReferenceString(schemaAware.schema)) {
13
- reference = new ReferenceBuilder().build(schemaAware.schema);
14
- }
15
-
16
- return {
17
- reference: reference,
18
- body: this.buildBody(schemaAware as K, reference),
19
- };
20
- }
21
-
22
- abstract buildBody(apexDocObject: K, reference?: Reference): T;
23
-
24
- protected getOpenApiSchemaFromApexDocSchema(schemaAware: ApexDocSchemaAware, reference?: Reference): SchemaObject {
25
- if (this.isReferenceString(schemaAware.schema)) {
26
- // We are dealing with a reference
27
- return reference!.entrypointReferenceObject;
28
- }
29
- return schemaAware.schema;
30
- }
31
-
32
- private isReferenceString = (targetObject: unknown): targetObject is string => {
33
- return typeof targetObject === 'string' || targetObject instanceof String;
34
- };
35
- }
36
-
37
- export interface Response<T> {
38
- reference?: Reference;
39
- body: T;
40
- }
@@ -1,249 +0,0 @@
1
- import { ClassMirror, MethodMirror } from '@cparra/apex-reflection';
2
- import { OpenApi } from '../../../core/openapi/open-api';
3
- import * as yaml from 'js-yaml';
4
- import { ClassMirrorWrapper } from '../../../core/openapi/apex-type-wrappers/ClassMirrorWrapper';
5
- import { Reference, ReferenceBuilder } from './ReferenceBuilder';
6
- import { ParameterObjectBuilder } from './ParameterObjectBuilder';
7
- import { ResponsesBuilder } from './ResponsesBuilder';
8
- import {
9
- ApexDocHttpRequestBody,
10
- ApexDocHttpResponse,
11
- ApexDocParameterObject,
12
- } from '../../../core/openapi/apex-doc-types';
13
- import { RequestBodyBuilder } from './RequestBodyBuilder';
14
- import { ApexDocSchemaAware } from './Builder';
15
- import { PropertiesObject, ReferenceObject } from '../../../core/openapi/open-api-types';
16
- import { MethodMirrorWrapper } from '../../../core/openapi/apex-type-wrappers/MethodMirrorWrapper';
17
-
18
- type FallbackMethodParser = (methodMirror: MethodMirror) => void;
19
- type AddToOpenApi<T extends ApexDocSchemaAware> = (input: T, urlValue: string, httpMethodKey: HttpOperations) => void;
20
-
21
- type HttpOperations = 'get' | 'put' | 'post' | 'delete' | 'patch';
22
-
23
- /**
24
- * Parses ApexDocs with HTTP REST annotations and turns them into an OpenApi specification.
25
- */
26
- export class MethodParser {
27
- constructor(public openApiModel: OpenApi) {}
28
-
29
- public parseMethod(classMirror: ClassMirror, httpUrlEndpoint: string, httpMethodKey: HttpOperations, tag: string) {
30
- const classMirrorWrapper = new ClassMirrorWrapper(classMirror);
31
- // Apex supports HttpGet, HttpPut, HttpPost, HttpDelete, and HttpPatch, so we search for a method
32
- // that has one of those annotations.
33
- const httpMethods = classMirrorWrapper.getMethodsByAnnotation(`http${httpMethodKey}`);
34
- if (!httpMethods.length) {
35
- return;
36
- }
37
-
38
- // We can assume there is at most one method per annotation, as this is an Apex rule.
39
- const httpMethod = httpMethods[0];
40
-
41
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey] = {};
42
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.tags = [tag];
43
- if (httpMethod.docComment?.description) {
44
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.description = httpMethod.docComment.description;
45
- }
46
- const methodMirrorWrapper = new MethodMirrorWrapper(httpMethod);
47
- if (methodMirrorWrapper.hasDocCommentAnnotation('summary')) {
48
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.summary =
49
- methodMirrorWrapper.getDocCommentAnnotation('summary')?.body;
50
- }
51
-
52
- this.parseHttpAnnotation<ApexDocHttpRequestBody>(
53
- httpMethod,
54
- httpUrlEndpoint,
55
- httpMethodKey,
56
- 'http-request-body',
57
- this.addRequestBodyToOpenApi.bind(this),
58
- this.fallbackHttpRequestBodyParser(httpUrlEndpoint, httpMethodKey),
59
- );
60
-
61
- this.parseHttpAnnotation<ApexDocParameterObject>(
62
- httpMethod,
63
- httpUrlEndpoint,
64
- httpMethodKey,
65
- 'http-parameter',
66
- this.addParametersToOpenApi.bind(this),
67
- );
68
-
69
- this.parseHttpAnnotation<ApexDocHttpResponse>(
70
- httpMethod,
71
- httpUrlEndpoint,
72
- httpMethodKey,
73
- 'http-response',
74
- this.addHttpResponsesToOpenApi.bind(this),
75
- this.getFallbackHttpResponseParser(httpUrlEndpoint, httpMethodKey),
76
- );
77
- }
78
-
79
- private parseHttpAnnotation<T extends ApexDocSchemaAware>(
80
- httpMethod: MethodMirror,
81
- urlValue: string,
82
- httpMethodKey: HttpOperations,
83
- annotationName: string,
84
- addToOpenApi: AddToOpenApi<T>,
85
- fallbackParser?: FallbackMethodParser,
86
- ) {
87
- const annotations = httpMethod.docComment?.annotations.filter((annotation) => annotation.name === annotationName);
88
-
89
- if (!annotations?.length) {
90
- if (fallbackParser) {
91
- fallbackParser(httpMethod);
92
- }
93
- return;
94
- }
95
-
96
- for (const annotation of annotations) {
97
- // We expect the ApexDoc data representing this to be in YAML format.
98
- const inYaml = annotation?.bodyLines.reduce((prev, current) => prev + '\n' + current);
99
-
100
- if (!inYaml) {
101
- return;
102
- }
103
-
104
- this.addToOpenApiStrategy<T>(inYaml, urlValue, httpMethodKey, addToOpenApi);
105
- }
106
- }
107
-
108
- private addToOpenApiStrategy<T extends ApexDocSchemaAware>(
109
- inYaml: string,
110
- urlValue: string,
111
- httpMethodKey: HttpOperations,
112
- addToOpenApi: AddToOpenApi<T>,
113
- ): void {
114
- // Convert the YAML into a JSON object.
115
- const inJson = yaml.load(inYaml) as T;
116
- const requestBodyResponse = new RequestBodyBuilder().build(inJson);
117
-
118
- addToOpenApi(inJson, urlValue, httpMethodKey);
119
-
120
- this.addReference(requestBodyResponse);
121
- }
122
-
123
- private addRequestBodyToOpenApi(
124
- input: ApexDocHttpRequestBody,
125
- urlValue: string,
126
- httpMethodKey: HttpOperations,
127
- ): void {
128
- const requestBodyResponse = new RequestBodyBuilder().build(input);
129
- this.openApiModel.paths[urlValue][httpMethodKey]!.requestBody = requestBodyResponse.body;
130
- }
131
-
132
- private addParametersToOpenApi(input: ApexDocParameterObject, urlValue: string, httpMethodKey: HttpOperations): void {
133
- const parameterObjectResponse = new ParameterObjectBuilder().build(input);
134
-
135
- if (this.openApiModel.paths[urlValue][httpMethodKey]!.parameters === undefined) {
136
- // If no parameters have been defined yet, initialize the list.
137
- this.openApiModel.paths[urlValue][httpMethodKey]!.parameters = [];
138
- }
139
- this.openApiModel.paths[urlValue][httpMethodKey]!.parameters!.push(parameterObjectResponse.body);
140
- }
141
-
142
- private addHttpResponsesToOpenApi(input: ApexDocHttpResponse, urlValue: string, httpMethodKey: HttpOperations): void {
143
- const responseObjectResponse = new ResponsesBuilder().build(input);
144
-
145
- if (this.openApiModel.paths[urlValue][httpMethodKey]!.responses === undefined) {
146
- this.openApiModel.paths[urlValue][httpMethodKey]!.responses = {};
147
- }
148
-
149
- this.openApiModel.paths[urlValue][httpMethodKey]!.responses![input.statusCode] = responseObjectResponse.body;
150
- }
151
-
152
- private fallbackHttpRequestBodyParser(
153
- httpUrlEndpoint: string,
154
- httpMethodKey: 'get' | 'put' | 'post' | 'delete' | 'patch',
155
- ) {
156
- return (methodMirror: MethodMirror) => {
157
- // If the Apex method receives parameters, they will be interpreted by Salesforce as a JSON
158
- // object, with each key of the object being the parameter name.
159
- const parameters = methodMirror.parameters;
160
-
161
- if (!parameters.length) {
162
- return;
163
- }
164
-
165
- const propertiesObject: PropertiesObject = {};
166
- parameters.forEach((currentParameter) => {
167
- const propertyKey = currentParameter.name;
168
- const propertyReference = new ReferenceBuilder().getReferenceType(currentParameter.typeReference);
169
-
170
- propertiesObject[propertyKey] = propertyReference.schema;
171
-
172
- this.addReference({
173
- reference: {
174
- entrypointReferenceObject: propertyReference.schema as ReferenceObject,
175
- referenceComponents: propertyReference.referenceComponents,
176
- },
177
- });
178
- });
179
-
180
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.requestBody = {
181
- content: {
182
- 'application/json': {
183
- schema: {
184
- type: 'object',
185
- properties: propertiesObject,
186
- },
187
- },
188
- },
189
- };
190
- };
191
- }
192
-
193
- private getFallbackHttpResponseParser(
194
- httpUrlEndpoint: string,
195
- httpMethodKey: 'get' | 'put' | 'post' | 'delete' | 'patch',
196
- ) {
197
- return (methodMirror: MethodMirror) => {
198
- // Parses methods that return an object (as opposed to void).
199
- const returnType = methodMirror.typeReference;
200
-
201
- if (returnType.type.toLowerCase() === 'void') {
202
- return;
203
- }
204
-
205
- const reference = new ReferenceBuilder().getReferenceType(returnType);
206
-
207
- this.addReference({
208
- reference: {
209
- entrypointReferenceObject: reference.schema as ReferenceObject,
210
- referenceComponents: reference.referenceComponents,
211
- },
212
- });
213
-
214
- if (this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.responses === undefined) {
215
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.responses = {};
216
- }
217
-
218
- // Successful responses with a non-void return type always return a status code of 2000
219
- this.openApiModel.paths[httpUrlEndpoint][httpMethodKey]!.responses!['200'] = {
220
- description: methodMirror.docComment?.description ?? 'Status code 200',
221
- content: {
222
- 'application/json': { schema: reference.schema },
223
- },
224
- };
225
- };
226
- }
227
-
228
- private addReference(referenceHolder: { reference?: Reference }): void {
229
- if (referenceHolder.reference) {
230
- // If a reference is returned, we want to make sure to add it to the OpenApi object as well
231
- // Add to "component" section if it hasn't been already
232
- if (this.openApiModel.components === undefined) {
233
- this.openApiModel.components = {
234
- schemas: {},
235
- };
236
- }
237
-
238
- if (!referenceHolder.reference.referenceComponents.length) {
239
- return;
240
- }
241
-
242
- // Add all received references to the OpenApi components section.
243
- referenceHolder.reference.referenceComponents.forEach((current) => {
244
- // Check if the referenced object is already part of the OpenApi object
245
- this.openApiModel.components!.schemas![current.referencedClass] = current.schema;
246
- });
247
- }
248
- }
249
- }
@@ -1,13 +0,0 @@
1
- import { ParameterObject } from '../../../core/openapi/open-api-types';
2
- import { Reference } from './ReferenceBuilder';
3
- import { ApexDocParameterObject } from '../../../core/openapi/apex-doc-types';
4
- import { Builder } from './Builder';
5
-
6
- export class ParameterObjectBuilder extends Builder<ParameterObject, ApexDocParameterObject> {
7
- buildBody(apexDocObject: ApexDocParameterObject, reference?: Reference): ParameterObject {
8
- return {
9
- ...apexDocObject,
10
- schema: this.getOpenApiSchemaFromApexDocSchema(apexDocObject, reference),
11
- };
12
- }
13
- }