@cparra/apexdocs 3.0.0-alpha.8 → 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.
- package/dist/cli/generate.js +430 -288
- package/examples/open-api/config/project-scratch-def.json +13 -0
- package/examples/open-api/docs/openapi.json +582 -0
- package/examples/{force-app → open-api/force-app}/main/default/classes/SampleClass.cls +1 -0
- package/examples/open-api/package-lock.json +724 -0
- package/examples/open-api/package.json +20 -0
- package/examples/open-api/sfdx-project.json +12 -0
- package/package.json +2 -2
- package/src/application/Apexdocs.ts +39 -7
- package/src/application/__tests__/apex-file-reader.spec.ts +0 -17
- package/src/application/file-writer.ts +37 -15
- package/src/application/generators/markdown.ts +10 -39
- package/src/application/generators/openapi.ts +22 -6
- package/src/cli/args.ts +4 -1
- package/src/cli/commands/openapi.ts +36 -0
- package/src/core/markdown/adapters/documentables.ts +0 -1
- package/src/core/markdown/generate-docs.ts +8 -12
- package/src/core/markdown/reflection/reflect-source.ts +109 -31
- package/src/core/openApiSettings.ts +41 -0
- package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +2 -2
- package/src/core/openapi/open-api-docs-processor.ts +8 -4
- package/src/core/openapi/open-api.ts +5 -1
- package/src/core/openapi/openapi-type-file.ts +1 -1
- package/src/core/openapi/parser.ts +1 -15
- package/src/core/openapi/transpiler.ts +0 -5
- package/src/core/parse-apex-metadata.ts +21 -5
- package/src/core/shared/types.d.ts +4 -1
- package/src/test-helpers/SettingsBuilder.ts +2 -6
- package/dist/defaults-DUwru49Q.js +0 -12
- package/dist/defaults-SH0Rsi5E.js +0 -11
- package/dist/defaults-jLXD2y8-.js +0 -13
- package/examples/force-app/main/default/classes/AnotherInterface.cls +0 -16
- package/examples/force-app/main/default/classes/EscapedAnnotations.cls +0 -5
- package/examples/force-app/main/default/classes/GrandparentClass.cls +0 -5
- package/examples/force-app/main/default/classes/GroupedClass.cls +0 -8
- package/examples/force-app/main/default/classes/InterfaceWithInheritance.cls +0 -1
- package/examples/force-app/main/default/classes/MemberGrouping.cls +0 -17
- package/examples/force-app/main/default/classes/ParentClass.cls +0 -16
- package/examples/force-app/main/default/classes/SampleClass.cls-meta.xml +0 -5
- package/examples/force-app/main/default/classes/SampleClassWithoutModifier.cls +0 -9
- package/examples/force-app/main/default/classes/SampleInterface.cls +0 -16
- package/src/core/markdown/reflection/error-handling.ts +0 -37
- package/src/core/settings.ts +0 -56
- /package/examples/{force-app → open-api/force-app}/main/default/classes/ChildClass.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResource.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceToSkip.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceWithInnerClass.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference1.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference2.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference3.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference4.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference5.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference6.cls +0 -0
- /package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference7.cls +0 -0
|
@@ -2,7 +2,7 @@ import { FileContainer } from './file-container';
|
|
|
2
2
|
import { ClassMirror, Type } from '@cparra/apex-reflection';
|
|
3
3
|
import { Logger } from '#utils/logger';
|
|
4
4
|
import { OpenApi } from './open-api';
|
|
5
|
-
import {
|
|
5
|
+
import { OpenApiSettings } from '../openApiSettings';
|
|
6
6
|
import { MethodParser } from './parsers/MethodParser';
|
|
7
7
|
import { camel2title } from '#utils/string-utils';
|
|
8
8
|
import { createOpenApiFile } from './openapi-type-file';
|
|
@@ -13,11 +13,15 @@ export class OpenApiDocsProcessor {
|
|
|
13
13
|
|
|
14
14
|
constructor() {
|
|
15
15
|
this._fileContainer = new FileContainer();
|
|
16
|
-
const title =
|
|
16
|
+
const title = OpenApiSettings.getInstance().getOpenApiTitle();
|
|
17
17
|
if (!title) {
|
|
18
18
|
throw Error('No OpenApi title was provided.');
|
|
19
19
|
}
|
|
20
|
-
this.openApiModel = new OpenApi(
|
|
20
|
+
this.openApiModel = new OpenApi(
|
|
21
|
+
title,
|
|
22
|
+
OpenApiSettings.getInstance().getVersion(),
|
|
23
|
+
OpenApiSettings.getInstance().getNamespace(),
|
|
24
|
+
);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
fileBuilder(): FileContainer {
|
|
@@ -66,7 +70,7 @@ export class OpenApiDocsProcessor {
|
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
onAfterProcess: ((types: Type[]) => void) | undefined = () => {
|
|
69
|
-
const page = createOpenApiFile(
|
|
73
|
+
const page = createOpenApiFile(OpenApiSettings.getInstance().openApiFileName(), this.openApiModel);
|
|
70
74
|
this._fileContainer.pushFile(page);
|
|
71
75
|
};
|
|
72
76
|
|
|
@@ -15,7 +15,11 @@ export class OpenApi {
|
|
|
15
15
|
servers: ServerObject[];
|
|
16
16
|
components?: ComponentsObject;
|
|
17
17
|
|
|
18
|
-
constructor(
|
|
18
|
+
constructor(
|
|
19
|
+
title: string,
|
|
20
|
+
version: string,
|
|
21
|
+
private namespace?: string,
|
|
22
|
+
) {
|
|
19
23
|
this.info = {
|
|
20
24
|
title: title,
|
|
21
25
|
version: version,
|
|
@@ -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
|
-
|
|
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
|
-
|
|
5
|
-
|
|
15
|
+
return pipe(input, parse, E.map(toMap));
|
|
16
|
+
}
|
|
6
17
|
|
|
7
|
-
|
|
18
|
+
function parse(input: string): E.Either<Error, ApexMetadata> {
|
|
19
|
+
return E.tryCatch(() => new XMLParser().parse(input), E.toError);
|
|
20
|
+
}
|
|
8
21
|
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
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/
|
|
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
|
-
|
|
14
|
+
version: '1.0.0',
|
|
19
15
|
};
|
|
20
16
|
}
|
|
21
17
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const defaults = {
|
|
4
|
-
targetGenerator: "markdown",
|
|
5
|
-
targetDir: "./docs/",
|
|
6
|
-
scope: ["global"],
|
|
7
|
-
defaultGroupName: "Miscellaneous",
|
|
8
|
-
includeMetadata: false,
|
|
9
|
-
sortMembersAlphabetically: false,
|
|
10
|
-
documentationRootDir: ""
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
exports.defaults = defaults;
|
|
@@ -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 +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,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,37 +0,0 @@
|
|
|
1
|
-
import * as E from 'fp-ts/Either';
|
|
2
|
-
import { ParsedFile } from '../../shared/types';
|
|
3
|
-
import { pipe } from 'fp-ts/function';
|
|
4
|
-
|
|
5
|
-
export class ReflectionErrors {
|
|
6
|
-
readonly _tag = 'ReflectionErrors';
|
|
7
|
-
constructor(public errors: ReflectionError[]) {}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ReflectionError {
|
|
11
|
-
constructor(
|
|
12
|
-
public file: string,
|
|
13
|
-
public message: string,
|
|
14
|
-
) {}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function checkForReflectionErrors(reflectionResult: E.Either<ReflectionError, ParsedFile>[]) {
|
|
18
|
-
function reduceReflectionResultIntoSingleEither(results: E.Either<ReflectionError, ParsedFile>[]): {
|
|
19
|
-
errors: ReflectionError[];
|
|
20
|
-
parsedFiles: ParsedFile[];
|
|
21
|
-
} {
|
|
22
|
-
return results.reduce<{ errors: ReflectionError[]; parsedFiles: ParsedFile[] }>(
|
|
23
|
-
(acc, result) => {
|
|
24
|
-
E.isLeft(result) ? acc.errors.push(result.left) : acc.parsedFiles.push(result.right);
|
|
25
|
-
return acc;
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
errors: [],
|
|
29
|
-
parsedFiles: [],
|
|
30
|
-
},
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return pipe(reflectionResult, reduceReflectionResultIntoSingleEither, ({ errors, parsedFiles }) =>
|
|
35
|
-
errors.length ? E.left(new ReflectionErrors(errors)) : E.right(parsedFiles),
|
|
36
|
-
);
|
|
37
|
-
}
|
package/src/core/settings.ts
DELETED
|
@@ -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
|
-
}
|
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResource.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/SampleRestResourceToSkip.cls
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference1.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference2.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference3.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference4.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference5.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference6.cls
RENAMED
|
File without changes
|
/package/examples/{force-app → open-api/force-app}/main/default/restapi/references/Reference7.cls
RENAMED
|
File without changes
|