@cparra/apexdocs 3.0.0-rc.0 → 3.1.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 (226) hide show
  1. package/README.md +61 -576
  2. package/dist/cli/generate.js +73 -3094
  3. package/dist/defaults-BcE8DTat.js +13 -0
  4. package/dist/defaults-D07y_bq4.js +40 -0
  5. package/dist/defaults-gPzwP66p.js +14 -0
  6. package/dist/index.d.ts +35 -3
  7. package/dist/index.js +90 -2
  8. package/dist/logger-BEbUIfqN.js +3282 -0
  9. package/dist/logger-BGuf1PnL.js +3281 -0
  10. package/dist/logger-CWBRF2za.js +3284 -0
  11. package/dist/logger-CdBmDEN1.js +3283 -0
  12. package/dist/logger-Ce4QqPFR.js +3278 -0
  13. package/dist/logger-CyEVYaAC.js +3284 -0
  14. package/dist/logger-D7a83ycP.js +3277 -0
  15. package/dist/logger-DGaHeBKk.js +3279 -0
  16. package/dist/logger-Dqhl_lO_.js +3278 -0
  17. package/dist/logger-aySSWi0G.js +3280 -0
  18. package/dist/logger-qLCcAtiy.js +3284 -0
  19. package/package.json +5 -2
  20. package/.github/workflows/ci.yaml +0 -22
  21. package/.github/workflows/close_stale.yml +0 -22
  22. package/.prettierrc.js +0 -7
  23. package/__mocks__/chalk.js +0 -12
  24. package/__mocks__/log-update.js +0 -6
  25. package/eslint.config.mjs +0 -10
  26. package/examples/markdown/.forceignore +0 -12
  27. package/examples/markdown/config/project-scratch-def.json +0 -5
  28. package/examples/markdown/docs/index.md +0 -109
  29. package/examples/markdown/docs/miscellaneous/BaseClass.md +0 -16
  30. package/examples/markdown/docs/miscellaneous/MultiInheritanceClass.md +0 -72
  31. package/examples/markdown/docs/miscellaneous/ParentInterface.md +0 -15
  32. package/examples/markdown/docs/miscellaneous/ReferencedEnum.md +0 -8
  33. package/examples/markdown/docs/miscellaneous/SampleException.md +0 -24
  34. package/examples/markdown/docs/miscellaneous/SampleInterface.md +0 -116
  35. package/examples/markdown/docs/miscellaneous/Url.md +0 -311
  36. package/examples/markdown/docs/sample-enums/SampleEnum.md +0 -36
  37. package/examples/markdown/docs/samplegroup/SampleClass.md +0 -170
  38. package/examples/markdown/force-app/classes/BaseClass.cls +0 -3
  39. package/examples/markdown/force-app/classes/MultiInheritanceClass.cls +0 -1
  40. package/examples/markdown/force-app/classes/ParentInterface.cls +0 -3
  41. package/examples/markdown/force-app/classes/ReferencedEnum.cls +0 -3
  42. package/examples/markdown/force-app/classes/SampleClass.cls +0 -72
  43. package/examples/markdown/force-app/classes/SampleEnum.cls +0 -30
  44. package/examples/markdown/force-app/classes/SampleException.cls +0 -17
  45. package/examples/markdown/force-app/classes/SampleInterface.cls +0 -50
  46. package/examples/markdown/force-app/classes/Url.cls +0 -196
  47. package/examples/markdown/package-lock.json +0 -665
  48. package/examples/markdown/package.json +0 -20
  49. package/examples/markdown/sfdx-project.json +0 -12
  50. package/examples/markdown-jsconfig/.forceignore +0 -12
  51. package/examples/markdown-jsconfig/apexdocs.config.mjs +0 -21
  52. package/examples/markdown-jsconfig/config/project-scratch-def.json +0 -5
  53. package/examples/markdown-jsconfig/docs/index.md +0 -12
  54. package/examples/markdown-jsconfig/docs/miscellaneous/Url.md +0 -315
  55. package/examples/markdown-jsconfig/force-app/classes/Url.cls +0 -196
  56. package/examples/markdown-jsconfig/package-lock.json +0 -665
  57. package/examples/markdown-jsconfig/package.json +0 -15
  58. package/examples/markdown-jsconfig/sfdx-project.json +0 -12
  59. package/examples/open-api/config/project-scratch-def.json +0 -13
  60. package/examples/open-api/docs/openapi.json +0 -582
  61. package/examples/open-api/force-app/main/default/classes/ChildClass.cls +0 -42
  62. package/examples/open-api/force-app/main/default/classes/SampleClass.cls +0 -167
  63. package/examples/open-api/force-app/main/default/restapi/SampleRestResource.cls +0 -195
  64. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceToSkip.cls +0 -35
  65. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceWithInnerClass.cls +0 -24
  66. package/examples/open-api/force-app/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +0 -15
  67. package/examples/open-api/force-app/main/default/restapi/references/Reference1.cls +0 -9
  68. package/examples/open-api/force-app/main/default/restapi/references/Reference2.cls +0 -9
  69. package/examples/open-api/force-app/main/default/restapi/references/Reference3.cls +0 -3
  70. package/examples/open-api/force-app/main/default/restapi/references/Reference4.cls +0 -3
  71. package/examples/open-api/force-app/main/default/restapi/references/Reference5.cls +0 -3
  72. package/examples/open-api/force-app/main/default/restapi/references/Reference6.cls +0 -6
  73. package/examples/open-api/force-app/main/default/restapi/references/Reference7.cls +0 -3
  74. package/examples/open-api/package-lock.json +0 -724
  75. package/examples/open-api/package.json +0 -20
  76. package/examples/open-api/sfdx-project.json +0 -12
  77. package/examples/vitepress/.forceignore +0 -12
  78. package/examples/vitepress/apexdocs.config.ts +0 -111
  79. package/examples/vitepress/config/project-scratch-def.json +0 -13
  80. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js +0 -259
  81. package/examples/vitepress/docs/.vitepress/cache/deps/@theme_index.js.map +0 -7
  82. package/examples/vitepress/docs/.vitepress/cache/deps/_metadata.json +0 -40
  83. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js +0 -11474
  84. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-574YRH25.js.map +0 -7
  85. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js +0 -9172
  86. package/examples/vitepress/docs/.vitepress/cache/deps/chunk-E5DZZB2I.js.map +0 -7
  87. package/examples/vitepress/docs/.vitepress/cache/deps/package.json +0 -3
  88. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +0 -4339
  89. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +0 -7
  90. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +0 -567
  91. package/examples/vitepress/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +0 -7
  92. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js +0 -323
  93. package/examples/vitepress/docs/.vitepress/cache/deps/vue.js.map +0 -7
  94. package/examples/vitepress/docs/.vitepress/config.mts +0 -21
  95. package/examples/vitepress/docs/.vitepress/sidebar.json +0 -119
  96. package/examples/vitepress/docs/api-examples.md +0 -49
  97. package/examples/vitepress/docs/index-frontmatter.md +0 -16
  98. package/examples/vitepress/docs/index.md +0 -56
  99. package/examples/vitepress/docs/markdown-examples.md +0 -85
  100. package/examples/vitepress/docs/miscellaneous/BaseClass.md +0 -20
  101. package/examples/vitepress/docs/miscellaneous/MultiInheritanceClass.md +0 -76
  102. package/examples/vitepress/docs/miscellaneous/ParentInterface.md +0 -19
  103. package/examples/vitepress/docs/miscellaneous/ReferencedEnum.md +0 -15
  104. package/examples/vitepress/docs/miscellaneous/SampleException.md +0 -28
  105. package/examples/vitepress/docs/miscellaneous/SampleInterface.md +0 -116
  106. package/examples/vitepress/docs/miscellaneous/Url.md +0 -317
  107. package/examples/vitepress/docs/sample-enums/SampleEnum.md +0 -40
  108. package/examples/vitepress/docs/samplegroup/SampleClass.md +0 -174
  109. package/examples/vitepress/force-app/main/default/classes/BaseClass.cls +0 -3
  110. package/examples/vitepress/force-app/main/default/classes/MultiInheritanceClass.cls +0 -1
  111. package/examples/vitepress/force-app/main/default/classes/ParentInterface.cls +0 -3
  112. package/examples/vitepress/force-app/main/default/classes/ReferencedEnum.cls +0 -5
  113. package/examples/vitepress/force-app/main/default/classes/SampleClass.cls +0 -72
  114. package/examples/vitepress/force-app/main/default/classes/SampleEnum.cls +0 -30
  115. package/examples/vitepress/force-app/main/default/classes/SampleException.cls +0 -17
  116. package/examples/vitepress/force-app/main/default/classes/SampleInterface.cls +0 -46
  117. package/examples/vitepress/force-app/main/default/classes/Url.cls +0 -198
  118. package/examples/vitepress/package-lock.json +0 -2574
  119. package/examples/vitepress/package.json +0 -18
  120. package/examples/vitepress/sfdx-project.json +0 -12
  121. package/jest.config.js +0 -10
  122. package/jest.d.ts +0 -7
  123. package/src/application/Apexdocs.ts +0 -72
  124. package/src/application/__tests__/apex-file-reader.spec.ts +0 -87
  125. package/src/application/apex-file-reader.ts +0 -55
  126. package/src/application/file-system.ts +0 -69
  127. package/src/application/file-writer.ts +0 -43
  128. package/src/application/generators/markdown.ts +0 -45
  129. package/src/application/generators/openapi.ts +0 -71
  130. package/src/cli/args.ts +0 -46
  131. package/src/cli/commands/markdown.ts +0 -51
  132. package/src/cli/commands/openapi.ts +0 -36
  133. package/src/cli/generate.ts +0 -16
  134. package/src/core/__test__/manifest.spec.ts +0 -16
  135. package/src/core/manifest.ts +0 -90
  136. package/src/core/markdown/__test__/expect-extensions.ts +0 -32
  137. package/src/core/markdown/__test__/generating-class-docs.spec.ts +0 -605
  138. package/src/core/markdown/__test__/generating-docs.spec.ts +0 -111
  139. package/src/core/markdown/__test__/generating-enum-docs.spec.ts +0 -321
  140. package/src/core/markdown/__test__/generating-interface-docs.spec.ts +0 -397
  141. package/src/core/markdown/__test__/generating-reference-guide.spec.ts +0 -180
  142. package/src/core/markdown/__test__/inheritance-chain.test.ts +0 -54
  143. package/src/core/markdown/__test__/test-helpers.ts +0 -23
  144. package/src/core/markdown/adapters/__tests__/documentables.spec.ts +0 -109
  145. package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +0 -148
  146. package/src/core/markdown/adapters/__tests__/link-generator.spec.ts +0 -130
  147. package/src/core/markdown/adapters/__tests__/references.spec.ts +0 -136
  148. package/src/core/markdown/adapters/apex-types.ts +0 -238
  149. package/src/core/markdown/adapters/documentables.ts +0 -115
  150. package/src/core/markdown/adapters/fields-and-properties.ts +0 -45
  151. package/src/core/markdown/adapters/generate-link.ts +0 -82
  152. package/src/core/markdown/adapters/inline.ts +0 -143
  153. package/src/core/markdown/adapters/methods-and-constructors.ts +0 -133
  154. package/src/core/markdown/adapters/reference-guide.ts +0 -37
  155. package/src/core/markdown/adapters/renderable-bundle.ts +0 -61
  156. package/src/core/markdown/adapters/renderable-to-page-data.ts +0 -89
  157. package/src/core/markdown/adapters/type-utils.ts +0 -13
  158. package/src/core/markdown/adapters/types.d.ts +0 -180
  159. package/src/core/markdown/generate-docs.ts +0 -212
  160. package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +0 -306
  161. package/src/core/markdown/reflection/filter-scope.ts +0 -13
  162. package/src/core/markdown/reflection/inheritance-chain-expanion.ts +0 -22
  163. package/src/core/markdown/reflection/inheritance-chain.ts +0 -23
  164. package/src/core/markdown/reflection/inherited-member-expansion.ts +0 -105
  165. package/src/core/markdown/reflection/reflect-source.ts +0 -123
  166. package/src/core/markdown/reflection/sort-members.ts +0 -59
  167. package/src/core/markdown/templates/class-template.ts +0 -75
  168. package/src/core/markdown/templates/constructors-partial-template.ts +0 -32
  169. package/src/core/markdown/templates/documentable-partial-template.ts +0 -26
  170. package/src/core/markdown/templates/enum-template.ts +0 -12
  171. package/src/core/markdown/templates/fieldsPartialTemplate.ts +0 -23
  172. package/src/core/markdown/templates/grouped-members-partial-template.ts +0 -6
  173. package/src/core/markdown/templates/hookable.ts +0 -7
  174. package/src/core/markdown/templates/interface-template.ts +0 -16
  175. package/src/core/markdown/templates/methods-partial-template.ts +0 -43
  176. package/src/core/markdown/templates/reference-guide.ts +0 -14
  177. package/src/core/markdown/templates/template.ts +0 -114
  178. package/src/core/markdown/templates/type-doc-partial.ts +0 -27
  179. package/src/core/markdown/utils.ts +0 -3
  180. package/src/core/openApiSettings.ts +0 -41
  181. package/src/core/openapi/__tests__/manifest-factory.spec.ts +0 -16
  182. package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +0 -56
  183. package/src/core/openapi/__tests__/open-api.spec.ts +0 -22
  184. package/src/core/openapi/apex-doc-types.ts +0 -26
  185. package/src/core/openapi/apex-type-wrappers/ClassMirrorWrapper.ts +0 -12
  186. package/src/core/openapi/apex-type-wrappers/MethodMirrorWrapper.ts +0 -11
  187. package/src/core/openapi/apex-type-wrappers/__tests__/ClassMirrorWrapper.spec.ts +0 -15
  188. package/src/core/openapi/file-container.ts +0 -13
  189. package/src/core/openapi/manifest-factory.ts +0 -16
  190. package/src/core/openapi/open-api-docs-processor.ts +0 -93
  191. package/src/core/openapi/open-api-types.ts +0 -119
  192. package/src/core/openapi/open-api.ts +0 -45
  193. package/src/core/openapi/openapi-type-file.ts +0 -12
  194. package/src/core/openapi/parser.ts +0 -160
  195. package/src/core/openapi/parsers/Builder.ts +0 -40
  196. package/src/core/openapi/parsers/MethodParser.ts +0 -249
  197. package/src/core/openapi/parsers/ParameterObjectBuilder.ts +0 -13
  198. package/src/core/openapi/parsers/ReferenceBuilder.ts +0 -299
  199. package/src/core/openapi/parsers/RequestBodyBuilder.ts +0 -19
  200. package/src/core/openapi/parsers/ResponsesBuilder.ts +0 -21
  201. package/src/core/openapi/parsers/__tests__/MethodParser.spec.ts +0 -44
  202. package/src/core/openapi/parsers/__tests__/ParameterObjectBuilder.spec.ts +0 -68
  203. package/src/core/openapi/parsers/__tests__/ReferenceBuilder.spec.ts +0 -751
  204. package/src/core/openapi/parsers/__tests__/RequestBodyBuilder.spec.ts +0 -64
  205. package/src/core/openapi/parsers/__tests__/ResponsesBuilder.spec.ts +0 -55
  206. package/src/core/openapi/transpiler.ts +0 -17
  207. package/src/core/openapi/types-repository.ts +0 -54
  208. package/src/core/parse-apex-metadata.ts +0 -30
  209. package/src/core/shared/types.d.ts +0 -148
  210. package/src/core/shared/utils.ts +0 -5
  211. package/src/defaults.ts +0 -9
  212. package/src/index.ts +0 -49
  213. package/src/test-helpers/AnnotationBuilder.ts +0 -29
  214. package/src/test-helpers/ClassMirrorBuilder.ts +0 -69
  215. package/src/test-helpers/DocCommentAnnotationBuilder.ts +0 -24
  216. package/src/test-helpers/DocCommentBuilder.ts +0 -36
  217. package/src/test-helpers/FieldMirrorBuilder.ts +0 -59
  218. package/src/test-helpers/InterfaceMirrorBuilder.ts +0 -39
  219. package/src/test-helpers/MethodMirrorBuilder.ts +0 -77
  220. package/src/test-helpers/SettingsBuilder.ts +0 -17
  221. package/src/util/error-logger.ts +0 -92
  222. package/src/util/fp.ts +0 -3
  223. package/src/util/logger.ts +0 -44
  224. package/src/util/string-utils.ts +0 -7
  225. package/tsconfig.json +0 -25
  226. package/tslint.json +0 -6
@@ -1,56 +0,0 @@
1
- import { OpenApiDocsProcessor } from '../open-api-docs-processor';
2
- import { OpenApiSettings } from '../../openApiSettings';
3
- import { SettingsBuilder } from '../../../test-helpers/SettingsBuilder';
4
- import { DocCommentBuilder } from '../../../test-helpers/DocCommentBuilder';
5
- import { AnnotationBuilder } from '../../../test-helpers/AnnotationBuilder';
6
- import { ClassMirrorBuilder } from '../../../test-helpers/ClassMirrorBuilder';
7
-
8
- beforeEach(() => {
9
- OpenApiSettings.build(new SettingsBuilder().build());
10
- });
11
-
12
- it('should add a path based on the @UrlResource annotation on the class', function () {
13
- const annotationElementValue = {
14
- key: 'urlMapping',
15
- value: "'/Account/*'",
16
- };
17
- const classMirror = new ClassMirrorBuilder()
18
- .addAnnotation(new AnnotationBuilder().addElementValue(annotationElementValue).build())
19
- .build();
20
-
21
- const processor = new OpenApiDocsProcessor();
22
- processor.onProcess(classMirror);
23
-
24
- expect(processor.openApiModel.paths).toHaveProperty('Account/');
25
- });
26
-
27
- it('should respect slashes', function () {
28
- const annotationElementValue = {
29
- key: 'urlMapping',
30
- value: "'v1/Account/*'",
31
- };
32
- const classMirror = new ClassMirrorBuilder()
33
- .addAnnotation(new AnnotationBuilder().addElementValue(annotationElementValue).build())
34
- .build();
35
-
36
- const processor = new OpenApiDocsProcessor();
37
- processor.onProcess(classMirror);
38
-
39
- expect(processor.openApiModel.paths).toHaveProperty('v1/Account/');
40
- });
41
-
42
- it('should contain a path with a description when the class has an ApexDoc comment', function () {
43
- const annotationElementValue = {
44
- key: 'urlMapping',
45
- value: "'/Account/*'",
46
- };
47
- const classMirror = new ClassMirrorBuilder()
48
- .addAnnotation(new AnnotationBuilder().addElementValue(annotationElementValue).build())
49
- .withDocComment(new DocCommentBuilder().withDescription('My Description').build())
50
- .build();
51
-
52
- const processor = new OpenApiDocsProcessor();
53
- processor.onProcess(classMirror);
54
-
55
- expect(processor.openApiModel.paths['Account/'].description).toBe('My Description');
56
- });
@@ -1,22 +0,0 @@
1
- import { OpenApi } from '../open-api';
2
-
3
- it('should get created with a title and a version', function () {
4
- const openApi = new OpenApi('Test Spec', '1.0.0');
5
-
6
- expect(openApi.info.title).toBe('Test Spec');
7
- expect(openApi.info.version).toBe('1.0.0');
8
- });
9
-
10
- it('should contain a single server, which points to the correct server URL', function () {
11
- const openApi = new OpenApi('Test Spec', '1.0.0');
12
-
13
- expect(openApi.servers.length).toBe(1);
14
- expect(openApi.servers[0].url).toBe('/services/apexrest/');
15
- });
16
-
17
- it('should optionally allow for a namespace to be passed in as part of the server', function () {
18
- const openApi = new OpenApi('Test Spec', '1.0.0', 'Namespace');
19
-
20
- expect(openApi.servers.length).toBe(1);
21
- expect(openApi.servers[0].url).toBe('/services/apexrest/Namespace/');
22
- });
@@ -1,26 +0,0 @@
1
- // These are types that represent how the data is expected to be created in the ApexDoc (as YAML), which
2
- // in some cases might be different from the official OpenApi spec for simplicity when writing the ApexDoc.
3
-
4
- import { SchemaObjectArray, SchemaObjectObject } from './open-api-types';
5
-
6
- export type ApexDocHttpResponse = {
7
- statusCode: number;
8
- description?: string;
9
- schema: ApexDocSchemaObject;
10
- };
11
-
12
- export type ApexDocHttpRequestBody = {
13
- description?: string;
14
- schema: ApexDocSchemaObject;
15
- required?: boolean;
16
- };
17
-
18
- export type ApexDocParameterObject = {
19
- name: string;
20
- in: 'query' | 'header' | 'path' | 'cookie';
21
- description?: string;
22
- required?: boolean;
23
- schema: ApexDocSchemaObject;
24
- };
25
-
26
- export type ApexDocSchemaObject = SchemaObjectObject | SchemaObjectArray | string;
@@ -1,12 +0,0 @@
1
- import { ClassMirror, MethodMirror } from '@cparra/apex-reflection';
2
-
3
- export class ClassMirrorWrapper {
4
- constructor(public classMirror: ClassMirror) {}
5
-
6
- getMethodsByAnnotation(annotation: string): MethodMirror[] {
7
- return this.classMirror.methods.filter((method) => this.hasAnnotation(method, annotation));
8
- }
9
-
10
- private hasAnnotation = (method: MethodMirror, annotationName: string) =>
11
- method.annotations.some((annotation) => annotation.name.toLowerCase() === annotationName);
12
- }
@@ -1,11 +0,0 @@
1
- import { DocCommentAnnotation, MethodMirror } from '@cparra/apex-reflection';
2
-
3
- export class MethodMirrorWrapper {
4
- constructor(public methodMirror: MethodMirror) {}
5
-
6
- public hasDocCommentAnnotation = (annotationName: string) =>
7
- this.methodMirror.docComment?.annotations.some((annotation) => annotation.name.toLowerCase() === annotationName);
8
-
9
- public getDocCommentAnnotation = (annotationName: string): DocCommentAnnotation | undefined =>
10
- this.methodMirror.docComment?.annotations.find((annotation) => annotation.name.toLowerCase() === annotationName);
11
- }
@@ -1,15 +0,0 @@
1
- import { ClassMirrorWrapper } from '../ClassMirrorWrapper';
2
- import { ClassMirrorBuilder } from '../../../../test-helpers/ClassMirrorBuilder';
3
- import { MethodMirrorBuilder } from '../../../../test-helpers/MethodMirrorBuilder';
4
- import { AnnotationBuilder } from '../../../../test-helpers/AnnotationBuilder';
5
-
6
- it('should return methods by annotation when they exist', function () {
7
- const classMirror = new ClassMirrorBuilder()
8
- .addMethod(new MethodMirrorBuilder().addAnnotation(new AnnotationBuilder().withName('httpget').build()).build())
9
- .build();
10
-
11
- const classMirrorWrapper = new ClassMirrorWrapper(classMirror);
12
- const foundMethods = classMirrorWrapper.getMethodsByAnnotation('httpget');
13
-
14
- expect(foundMethods.length).toBe(1);
15
- });
@@ -1,13 +0,0 @@
1
- import { PageData } from '../shared/types';
2
-
3
- export class FileContainer {
4
- _files: PageData[] = [];
5
-
6
- files(): PageData[] {
7
- return this._files;
8
- }
9
-
10
- pushFile(file: PageData): void {
11
- this._files.push(file);
12
- }
13
- }
@@ -1,16 +0,0 @@
1
- import Manifest from '../manifest';
2
- import { TypeParser } from './parser';
3
- import { ReflectionResult } from '@cparra/apex-reflection';
4
- import { UnparsedSourceFile } from '../shared/types';
5
-
6
- /**
7
- * Builds a new Manifest object, sourcing its types from the received TypeParser.
8
- * @param typeParser In charge of returning the list of reflected types.
9
- * @param reflect Reflection function.
10
- */
11
- export function createManifest(
12
- typeParser: TypeParser,
13
- reflect: (apexBundle: UnparsedSourceFile) => ReflectionResult,
14
- ): Manifest {
15
- return new Manifest(typeParser.parse(reflect));
16
- }
@@ -1,93 +0,0 @@
1
- import { FileContainer } from './file-container';
2
- import { ClassMirror, Type } from '@cparra/apex-reflection';
3
- import { Logger } from '#utils/logger';
4
- import { OpenApi } from './open-api';
5
- import { OpenApiSettings } from '../openApiSettings';
6
- import { MethodParser } from './parsers/MethodParser';
7
- import { camel2title } from '#utils/string-utils';
8
- import { createOpenApiFile } from './openapi-type-file';
9
-
10
- export class OpenApiDocsProcessor {
11
- protected readonly _fileContainer: FileContainer;
12
- openApiModel: OpenApi;
13
-
14
- constructor() {
15
- this._fileContainer = new FileContainer();
16
- const title = OpenApiSettings.getInstance().getOpenApiTitle();
17
- if (!title) {
18
- throw Error('No OpenApi title was provided.');
19
- }
20
- this.openApiModel = new OpenApi(
21
- title,
22
- OpenApiSettings.getInstance().getVersion(),
23
- OpenApiSettings.getInstance().getNamespace(),
24
- );
25
- }
26
-
27
- fileBuilder(): FileContainer {
28
- return this._fileContainer;
29
- }
30
-
31
- onProcess(type: Type): void {
32
- Logger.logSingle(`Processing ${type.name}`, 'green');
33
-
34
- const endpointPath = this.getEndpointPath(type);
35
- if (!endpointPath) {
36
- return;
37
- }
38
-
39
- this.openApiModel.paths[endpointPath] = {};
40
- if (type.docComment?.description) {
41
- this.openApiModel.paths[endpointPath].description = type.docComment.description;
42
- }
43
-
44
- // We can safely cast to a ClassMirror, since only these support the @RestResource annotation
45
- const typeAsClass = type as ClassMirror;
46
-
47
- // Add tags for this Apex class to the OpenApi model
48
- const tagName = camel2title(endpointPath);
49
- this.openApiModel.tags.push({
50
- name: tagName,
51
- description: type.docComment?.description,
52
- });
53
-
54
- const parser = new MethodParser(this.openApiModel);
55
-
56
- // GET
57
- parser.parseMethod(typeAsClass, endpointPath, 'get', tagName);
58
-
59
- // PATCH
60
- parser.parseMethod(typeAsClass, endpointPath, 'patch', tagName);
61
-
62
- // POST
63
- parser.parseMethod(typeAsClass, endpointPath, 'post', tagName);
64
-
65
- // PUT
66
- parser.parseMethod(typeAsClass, endpointPath, 'put', tagName);
67
-
68
- // DELETE
69
- parser.parseMethod(typeAsClass, endpointPath, 'delete', tagName);
70
- }
71
-
72
- onAfterProcess: ((types: Type[]) => void) | undefined = () => {
73
- const page = createOpenApiFile(OpenApiSettings.getInstance().openApiFileName(), this.openApiModel);
74
- this._fileContainer.pushFile(page);
75
- };
76
-
77
- private getEndpointPath(type: Type): string | null {
78
- const restResourceAnnotation = type.annotations.find((element) => element.name.toLowerCase() === 'restresource');
79
- const urlMapping = restResourceAnnotation?.elementValues?.find(
80
- (element) => element.key.toLowerCase() === 'urlmapping',
81
- );
82
- if (!urlMapping) {
83
- Logger.error(`Type does not contain urlMapping annotation ${type.name}`);
84
- return null;
85
- }
86
-
87
- let endpointPath = urlMapping.value.replaceAll('"', '').replaceAll("'", '').replaceAll('/*', '/');
88
- if (endpointPath.startsWith('/')) {
89
- endpointPath = endpointPath.substring(1);
90
- }
91
- return endpointPath;
92
- }
93
- }
@@ -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,160 +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(public typeBundles: UnparsedSourceFile[]) {}
13
-
14
- parse(reflect: (apexBundle: UnparsedSourceFile) => ReflectionResult): Type[] {
15
- const types = this.typeBundles
16
- .map((currentBundle) => {
17
- Logger.log(`Parsing file: ${currentBundle.filePath}`);
18
- return reflect(currentBundle);
19
- })
20
- .filter((reflectionResult) => {
21
- return reflectionResult.typeMirror;
22
- })
23
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
24
- .map((reflectionResult) => reflectionResult.typeMirror!);
25
-
26
- return this.addFieldsFromParent(types);
27
- }
28
-
29
- addFieldsFromParent(types: Type[]): Type[] {
30
- const typesWithFields: Type[] = [];
31
- for (const currentType of types) {
32
- if (currentType.type_name !== 'class' && currentType.type_name !== 'interface') {
33
- typesWithFields.push(currentType);
34
- continue;
35
- }
36
-
37
- if (currentType.type_name === 'class') {
38
- let typeAsClass = currentType as ClassMirror;
39
- if (!typeAsClass.extended_class) {
40
- typesWithFields.push(currentType);
41
- continue;
42
- }
43
-
44
- typeAsClass = this.addMembersFromParent(typeAsClass, types);
45
- typesWithFields.push(typeAsClass);
46
- continue;
47
- }
48
-
49
- // At this stage, we can be sure we are dealing with an interface
50
- let typeAsInterface = currentType as InterfaceMirror;
51
- if (!typeAsInterface.extended_interfaces.length) {
52
- typesWithFields.push(currentType);
53
- continue;
54
- }
55
-
56
- typeAsInterface = this.addMethodsFromParent(typeAsInterface, types);
57
- typesWithFields.push(typeAsInterface);
58
- }
59
-
60
- return typesWithFields;
61
- }
62
-
63
- addMembersFromParent(currentClass: ClassMirror, allTypes: Type[]): ClassMirror {
64
- if (!currentClass.extended_class) {
65
- return currentClass;
66
- }
67
- const parent = allTypes.find((currentType: Type) => currentType.name === currentClass.extended_class);
68
- if (!parent || parent.type_name !== 'class') {
69
- return currentClass;
70
- }
71
-
72
- let parentAsClass = parent as ClassMirror;
73
- if (parentAsClass.extended_class) {
74
- parentAsClass = this.addMembersFromParent(parentAsClass, allTypes);
75
- }
76
-
77
- currentClass.fields = [...currentClass.fields, ...this.getInheritedFields(parentAsClass, currentClass)];
78
- currentClass.properties = [...currentClass.properties, ...this.getInheritedProperties(parentAsClass, currentClass)];
79
- currentClass.methods = [...currentClass.methods, ...this.getInheritedMethods(parentAsClass, currentClass)];
80
- return currentClass;
81
- }
82
-
83
- addMethodsFromParent(currentInterface: InterfaceMirror, allTypes: Type[]): InterfaceMirror {
84
- if (!currentInterface.extended_interfaces.length) {
85
- return currentInterface;
86
- }
87
-
88
- const parents = [];
89
- for (const currentInterfaceName of currentInterface.extended_interfaces) {
90
- const parent = allTypes.find((currentType: Type) => currentType.name === currentInterfaceName);
91
- if (parent) {
92
- parents.push(parent);
93
- }
94
- }
95
-
96
- for (const parent of parents) {
97
- let parentAsInterface = parent as InterfaceMirror;
98
- if (parentAsInterface.extended_interfaces.length) {
99
- parentAsInterface = this.addMethodsFromParent(parentAsInterface, allTypes);
100
- }
101
-
102
- currentInterface.methods = [
103
- ...currentInterface.methods,
104
- ...this.getInheritedMethods(parentAsInterface, currentInterface),
105
- ];
106
- }
107
-
108
- return currentInterface;
109
- }
110
-
111
- private getInheritedFields(parentAsClass: ClassMirror, currentClass: ClassMirror) {
112
- return (
113
- parentAsClass.fields
114
- // Filter out private fields
115
- .filter((currentField) => currentField.access_modifier.toLowerCase() !== 'private')
116
- // Filter out fields that also exist on the child
117
- .filter((currentField) => !this.memberExists(currentClass.fields, currentField.name))
118
- .map((currentField) => ({
119
- ...currentField,
120
- inherited: true,
121
- }))
122
- );
123
- }
124
-
125
- private getInheritedProperties(parentAsClass: ClassMirror, currentClass: ClassMirror) {
126
- return (
127
- parentAsClass.properties
128
- // Filter out private properties
129
- .filter((currentProperty) => currentProperty.access_modifier.toLowerCase() !== 'private')
130
- // Filter out properties that also exist on the child
131
- .filter((currentProperty) => !this.memberExists(currentClass.properties, currentProperty.name))
132
- .map((currentProperty) => ({
133
- ...currentProperty,
134
- inherited: true,
135
- }))
136
- );
137
- }
138
-
139
- private getInheritedMethods(
140
- parentAsClass: ClassMirror | InterfaceMirror,
141
- currentClass: ClassMirror | InterfaceMirror,
142
- ) {
143
- return (
144
- parentAsClass.methods
145
- // Filter out private methods
146
- .filter((currentMethod) => currentMethod.access_modifier.toLowerCase() !== 'private')
147
- // Filter out methods that also exist on the child
148
- .filter((currentMethod) => !this.memberExists(currentClass.methods, currentMethod.name))
149
- .map((currentMethod) => ({
150
- ...currentMethod,
151
- inherited: true,
152
- }))
153
- );
154
- }
155
-
156
- memberExists(members: NameAware[], fieldName: string): boolean {
157
- const fieldNames = members.map((currentMember) => currentMember.name);
158
- return fieldNames.includes(fieldName);
159
- }
160
- }
@@ -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
- }