@cparra/apexdocs 3.0.0-alpha.9 → 3.0.0-beta.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 (51) hide show
  1. package/dist/cli/generate.js +294 -204
  2. package/examples/open-api/config/project-scratch-def.json +13 -0
  3. package/examples/open-api/docs/openapi.json +582 -0
  4. package/examples/{force-app → open-api/force-app}/main/default/classes/SampleClass.cls +1 -0
  5. package/examples/open-api/package-lock.json +724 -0
  6. package/examples/open-api/package.json +20 -0
  7. package/examples/open-api/sfdx-project.json +12 -0
  8. package/package.json +1 -1
  9. package/src/application/Apexdocs.ts +39 -7
  10. package/src/application/__tests__/apex-file-reader.spec.ts +0 -17
  11. package/src/application/file-writer.ts +37 -15
  12. package/src/application/generators/markdown.ts +10 -39
  13. package/src/application/generators/openapi.ts +22 -6
  14. package/src/cli/args.ts +4 -1
  15. package/src/cli/commands/openapi.ts +36 -0
  16. package/src/core/markdown/adapters/documentables.ts +0 -1
  17. package/src/core/markdown/generate-docs.ts +2 -5
  18. package/src/core/markdown/reflection/reflect-source.ts +51 -50
  19. package/src/core/openApiSettings.ts +41 -0
  20. package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +2 -2
  21. package/src/core/openapi/open-api-docs-processor.ts +8 -4
  22. package/src/core/openapi/open-api.ts +5 -1
  23. package/src/core/openapi/openapi-type-file.ts +1 -1
  24. package/src/core/openapi/parser.ts +1 -15
  25. package/src/core/openapi/transpiler.ts +0 -5
  26. package/src/core/parse-apex-metadata.ts +21 -5
  27. package/src/core/shared/types.d.ts +4 -1
  28. package/src/test-helpers/SettingsBuilder.ts +2 -6
  29. package/examples/force-app/main/default/classes/AnotherInterface.cls +0 -16
  30. package/examples/force-app/main/default/classes/EscapedAnnotations.cls +0 -5
  31. package/examples/force-app/main/default/classes/GrandparentClass.cls +0 -5
  32. package/examples/force-app/main/default/classes/GroupedClass.cls +0 -8
  33. package/examples/force-app/main/default/classes/InterfaceWithInheritance.cls +0 -1
  34. package/examples/force-app/main/default/classes/MemberGrouping.cls +0 -17
  35. package/examples/force-app/main/default/classes/ParentClass.cls +0 -16
  36. package/examples/force-app/main/default/classes/SampleClass.cls-meta.xml +0 -5
  37. package/examples/force-app/main/default/classes/SampleClassWithoutModifier.cls +0 -9
  38. package/examples/force-app/main/default/classes/SampleInterface.cls +0 -16
  39. package/src/core/settings.ts +0 -56
  40. /package/examples/{force-app → open-api/force-app}/main/default/classes/ChildClass.cls +0 -0
  41. /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResource.cls +0 -0
  42. /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceToSkip.cls +0 -0
  43. /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceWithInnerClass.cls +0 -0
  44. /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +0 -0
  45. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference1.cls +0 -0
  46. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference2.cls +0 -0
  47. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference3.cls +0 -0
  48. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference4.cls +0 -0
  49. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference5.cls +0 -0
  50. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference6.cls +0 -0
  51. /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference7.cls +0 -0
@@ -4,7 +4,7 @@ import { OpenApiPageData } from '../shared/types';
4
4
  export function createOpenApiFile(fileName: string, openApiModel: OpenApi): OpenApiPageData {
5
5
  const content = JSON.stringify({ ...openApiModel, namespace: undefined }, null, 2);
6
6
  return {
7
- outputDocPath: '',
7
+ outputDocPath: `${fileName}.json`,
8
8
  content,
9
9
  frontmatter: null,
10
10
  group: null,
@@ -1,5 +1,4 @@
1
1
  import { ClassMirror, InterfaceMirror, ReflectionResult, Type } from '@cparra/apex-reflection';
2
- import { parseApexMetadata } from '../parse-apex-metadata';
3
2
  import { Logger } from '#utils/logger';
4
3
  import { UnparsedSourceFile } from '../shared/types';
5
4
 
@@ -16,20 +15,7 @@ export class RawBodyParser implements TypeParser {
16
15
  const types = this.typeBundles
17
16
  .map((currentBundle) => {
18
17
  Logger.log(`Parsing file: ${currentBundle.filePath}`);
19
- const result = reflect(currentBundle);
20
- if (!!result.typeMirror && !!currentBundle.metadataContent) {
21
- // If successful and there is a metadata file
22
- const metadataParams = parseApexMetadata(currentBundle.metadataContent);
23
- metadataParams.forEach((value, key) => {
24
- const declaration = `${key}: ${value}`;
25
- result.typeMirror?.annotations.push({
26
- rawDeclaration: declaration,
27
- name: declaration,
28
- type: declaration,
29
- });
30
- });
31
- }
32
- return result;
18
+ return reflect(currentBundle);
33
19
  })
34
20
  .filter((reflectionResult) => {
35
21
  return reflectionResult.typeMirror;
@@ -1,5 +1,4 @@
1
1
  import { Type } from '@cparra/apex-reflection';
2
- import { Settings } from '../settings';
3
2
  import { OpenApiDocsProcessor } from './open-api-docs-processor';
4
3
 
5
4
  export default class Transpiler {
@@ -10,10 +9,6 @@ export default class Transpiler {
10
9
  return 0;
11
10
  });
12
11
 
13
- if (Settings.getInstance().indexOnly) {
14
- return;
15
- }
16
-
17
12
  sortedTypes.forEach((currentType) => {
18
13
  processor.onProcess(currentType);
19
14
  });
@@ -1,13 +1,29 @@
1
1
  import { XMLParser } from 'fast-xml-parser';
2
+ import * as E from 'fp-ts/Either';
3
+ import { pipe } from 'fp-ts/function';
4
+
5
+ type ApexMetadata = {
6
+ ApexClass: ApexClassMetadata;
7
+ };
8
+
9
+ type ApexClassMetadata = {
10
+ apiVersion: string;
11
+ status?: string;
12
+ };
2
13
 
3
14
  export function parseApexMetadata(input: string) {
4
- const map = new Map<string, string>();
5
- const xml = new XMLParser().parse(input);
15
+ return pipe(input, parse, E.map(toMap));
16
+ }
6
17
 
7
- map.set('apiVersion', xml.ApexClass.apiVersion ?? '');
18
+ function parse(input: string): E.Either<Error, ApexMetadata> {
19
+ return E.tryCatch(() => new XMLParser().parse(input), E.toError);
20
+ }
8
21
 
9
- if (xml.ApexClass.status) {
10
- map.set('status', xml.ApexClass.status);
22
+ function toMap(metadata: ApexMetadata): Map<string, string> {
23
+ const map = new Map<string, string>();
24
+ map.set('apiVersion', String(metadata.ApexClass.apiVersion));
25
+ if (metadata.ApexClass.status) {
26
+ map.set('status', String(metadata.ApexClass.status));
11
27
  }
12
28
 
13
29
  return map;
@@ -39,7 +39,10 @@ export type UserDefinedOpenApiConfig = {
39
39
  targetGenerator: 'openapi';
40
40
  sourceDir: string;
41
41
  targetDir: string;
42
- includeMetadata: boolean;
42
+ fileName: string;
43
+ namespace?: string;
44
+ title: string;
45
+ apiVersion: string;
43
46
  };
44
47
 
45
48
  export type UserDefinedConfig = UserDefinedMarkdownConfig | UserDefinedOpenApiConfig;
@@ -1,4 +1,4 @@
1
- import { SettingsConfig } from '../core/settings';
1
+ import { SettingsConfig } from '../core/openApiSettings';
2
2
 
3
3
  /**
4
4
  * Builder class to create SettingsConfig objects.
@@ -8,14 +8,10 @@ export class SettingsBuilder {
8
8
  build(): SettingsConfig {
9
9
  return {
10
10
  sourceDirectory: './',
11
- scope: [],
12
11
  outputDir: './',
13
- targetGenerator: 'openapi',
14
- indexOnly: false,
15
- defaultGroupName: 'Misc',
16
12
  openApiTitle: 'Apex API',
17
13
  openApiFileName: 'openapi',
18
- includeMetadata: false,
14
+ version: '1.0.0',
19
15
  };
20
16
  }
21
17
  }
@@ -1,16 +0,0 @@
1
- /**
2
- * @description Some desc
3
- * @group Classes
4
- * @mermaid
5
- * sequenceDiagram
6
- * participant dotcom
7
- * participant iframe
8
- * participant viewscreen
9
- * dotcom->>iframe: loads html w/ iframe url
10
- * iframe->>viewscreen: request template
11
- * viewscreen->>iframe: html & javascript
12
- * iframe->>dotcom: iframe ready
13
- * dotcom->>iframe: set mermaid data on iframe
14
- * iframe->>iframe: render mermaid
15
- */
16
- public interface AnotherInterface{}
@@ -1,5 +0,0 @@
1
- /**
2
- * @description This sentence has an `@embedded` annotation.
3
- */
4
- public with sharing class EscapedAnnotations {
5
- }
@@ -1,5 +0,0 @@
1
- public virtual class GrandparentClass {
2
- protected String protectedGrandParentField;
3
-
4
- protected String AProp { get; set; }
5
- }
@@ -1,8 +0,0 @@
1
- /**********************************************************
2
- Uses a block style apex doc
3
- @group Main
4
- @test-class {@link SampleClass}
5
- ***********************************************************/
6
- public class GroupedClass {
7
-
8
- }
@@ -1 +0,0 @@
1
- public interface InterfaceWithInheritance extends SampleInterface, AnotherInterface {}
@@ -1,17 +0,0 @@
1
- public class MemberGrouping {
2
- // @start-group Group old syntax
3
- public static final String inGroup1;
4
- public static final String anotherInGroup1;
5
- // @end-group
6
-
7
- /**
8
- * @start-group Group new syntax
9
- * @description Group's description
10
- */
11
-
12
- /** @description Description for constant in group 2 */
13
- public static final String inGroup2;
14
- /** @description Description for another constant in group 2 @future annotation */
15
- public static final String anotherInGroup2;
16
- /** @end-group */
17
- }
@@ -1,16 +0,0 @@
1
- public abstract class ParentClass extends GrandparentClass{
2
- private String privateStringFromParent;
3
- /**
4
- * @description This is a protected string, use carefully.
5
- */
6
- protected String protectedStringFromParent;
7
- public String publicStringFromParent;
8
-
9
- public virtual String overridableMethod() {
10
- return '';
11
- }
12
-
13
- public virtual String overridableMethodOverridden() {
14
- return '';
15
- }
16
- }
@@ -1,5 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3
- <apiVersion>54.0</apiVersion>
4
- <status>Active</status>
5
- </ApexClass>
@@ -1,9 +0,0 @@
1
- @IsTest
2
- class SampleClassWithoutModifier {
3
- /**
4
- * @description This is a test method
5
- */
6
- @IsTest
7
- private static void thisIsAClassWithoutAModifier() {
8
- }
9
- }
@@ -1,16 +0,0 @@
1
- /**
2
- * @description This is an interface description.
3
- * @group Sample Interfaces
4
- */
5
- global interface SampleInterface {
6
- /**
7
- * @description Executes the command.
8
- */
9
- void execute();
10
-
11
- /**
12
- * @description Returns a value based on the executed command.
13
- * @return The value
14
- */
15
- String getValue();
16
- }
@@ -1,56 +0,0 @@
1
- import { Generator } from './shared/types';
2
-
3
- export interface SettingsConfig {
4
- sourceDirectory: string;
5
- scope: string[];
6
- outputDir: string;
7
- targetGenerator: Generator;
8
- indexOnly: boolean;
9
- defaultGroupName: string;
10
- openApiTitle?: string;
11
- namespace?: string;
12
- openApiFileName: string;
13
- includeMetadata: boolean;
14
- sortMembersAlphabetically?: boolean;
15
- }
16
-
17
- export class Settings {
18
- private static instance: Settings;
19
-
20
- private constructor(public config: SettingsConfig) {}
21
-
22
- public static build(config: SettingsConfig) {
23
- Settings.instance = new Settings(config);
24
- }
25
-
26
- public static getInstance(): Settings {
27
- if (!Settings.instance) {
28
- throw new Error('Settings has not been initialized');
29
- }
30
- return Settings.instance;
31
- }
32
-
33
- get scope(): string[] {
34
- return this.config.scope;
35
- }
36
-
37
- get targetGenerator(): Generator {
38
- return this.config.targetGenerator;
39
- }
40
-
41
- get indexOnly(): boolean {
42
- return this.config.indexOnly;
43
- }
44
-
45
- public getOpenApiTitle(): string | undefined {
46
- return this.config.openApiTitle;
47
- }
48
-
49
- public getNamespace(): string | undefined {
50
- return this.config.namespace;
51
- }
52
-
53
- public openApiFileName(): string {
54
- return this.config.openApiFileName;
55
- }
56
- }