@cparra/apexdocs 2.8.2 → 2.9.0-alpha.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/docs/openapi.json +474 -0
- package/examples/force-app/main/default/classes/ChildClass.cls +3 -1
- package/examples/force-app/main/default/classes/ParentClass.cls +4 -4
- package/examples/force-app/main/default/classes/SampleClass.cls +3 -0
- package/examples/force-app/main/default/restapi/SampleRestResource.cls +195 -0
- package/examples/force-app/main/default/restapi/SampleRestResourceWithInnerClass.cls +24 -0
- package/examples/force-app/main/default/restapi/references/Reference1.cls +9 -0
- package/examples/force-app/main/default/restapi/references/Reference2.cls +3 -0
- package/examples/force-app/main/default/restapi/references/Reference3.cls +3 -0
- package/examples/force-app/main/default/restapi/references/Reference4.cls +3 -0
- package/examples/force-app/main/default/restapi/references/Reference5.cls +3 -0
- package/examples/force-app/main/default/restapi/references/Reference6.cls +6 -0
- package/lib/application/Apexdocs.d.ts +1 -0
- package/lib/application/Apexdocs.js +33 -9
- package/lib/application/Apexdocs.js.map +1 -1
- package/lib/cli/generate.js +11 -3
- package/lib/cli/generate.js.map +1 -1
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/model/apex-type-wrappers/ClassMirrorWrapper.d.ts +7 -0
- package/lib/model/apex-type-wrappers/ClassMirrorWrapper.js +14 -0
- package/lib/model/apex-type-wrappers/ClassMirrorWrapper.js.map +1 -0
- package/lib/model/inheritance.d.ts +5 -5
- package/lib/model/manifest.d.ts +1 -1
- package/lib/model/markdown-file.d.ts +2 -2
- package/lib/model/markdown-file.js +2 -2
- package/lib/model/markdown-file.js.map +1 -1
- package/lib/model/markdown-generation-util/doc-comment-annotation-util.js.map +1 -1
- package/lib/model/markdown-generation-util/field-declaration-util.js +2 -2
- package/lib/model/markdown-generation-util/field-declaration-util.js.map +1 -1
- package/lib/model/markdown-generation-util/index.js +6 -2
- package/lib/model/markdown-generation-util/index.js.map +1 -1
- package/lib/model/markdown-generation-util/method-declaration-util.js +4 -4
- package/lib/model/markdown-generation-util/method-declaration-util.js.map +1 -1
- package/lib/model/markdown-generation-util/type-declaration-util.js +2 -2
- package/lib/model/markdown-generation-util/type-declaration-util.js.map +1 -1
- package/lib/model/markdown-home-file.js +1 -1
- package/lib/model/markdown-home-file.js.map +1 -1
- package/lib/model/markdown-type-file.js +5 -5
- package/lib/model/markdown-type-file.js.map +1 -1
- package/lib/model/openapi/apex-doc-types.d.ts +18 -0
- package/lib/model/openapi/apex-doc-types.js +5 -0
- package/lib/model/openapi/apex-doc-types.js.map +1 -0
- package/lib/model/openapi/open-api-types.d.ts +87 -0
- package/lib/model/openapi/open-api-types.js +3 -0
- package/lib/model/openapi/open-api-types.js.map +1 -0
- package/lib/model/openapi/open-api.d.ts +15 -0
- package/lib/model/openapi/open-api.js +33 -0
- package/lib/model/openapi/open-api.js.map +1 -0
- package/lib/model/openapi/openapi-type-file.d.ts +7 -0
- package/lib/model/openapi/openapi-type-file.js +16 -0
- package/lib/model/openapi/openapi-type-file.js.map +1 -0
- package/lib/model/{file.d.ts → outputFile.d.ts} +1 -1
- package/lib/model/{file.js → outputFile.js} +4 -4
- package/lib/model/outputFile.js.map +1 -0
- package/lib/model/types-repository.d.ts +11 -3
- package/lib/model/types-repository.js +37 -5
- package/lib/model/types-repository.js.map +1 -1
- package/lib/service/file-writer.d.ts +2 -2
- package/lib/service/file-writer.js.map +1 -1
- package/lib/service/metadata-processor.js.map +1 -1
- package/lib/service/parser.d.ts +1 -1
- package/lib/settings.d.ts +4 -5
- package/lib/settings.js +5 -23
- package/lib/settings.js.map +1 -1
- package/lib/test-helpers/AnnotationBuilder.d.ts +12 -0
- package/lib/test-helpers/AnnotationBuilder.js +31 -0
- package/lib/test-helpers/AnnotationBuilder.js.map +1 -0
- package/lib/test-helpers/ClassMirrorBuilder.d.ts +18 -0
- package/lib/test-helpers/ClassMirrorBuilder.js +54 -0
- package/lib/test-helpers/ClassMirrorBuilder.js.map +1 -0
- package/lib/test-helpers/DocCommentAnnotationBuilder.d.ts +6 -0
- package/lib/test-helpers/DocCommentAnnotationBuilder.js +21 -0
- package/lib/test-helpers/DocCommentAnnotationBuilder.js.map +1 -0
- package/lib/test-helpers/DocCommentBuilder.d.ts +12 -0
- package/lib/test-helpers/DocCommentBuilder.js +38 -0
- package/lib/test-helpers/DocCommentBuilder.js.map +1 -0
- package/lib/test-helpers/FieldMirrorBuilder.d.ts +16 -0
- package/lib/test-helpers/FieldMirrorBuilder.js +48 -0
- package/lib/test-helpers/FieldMirrorBuilder.js.map +1 -0
- package/lib/test-helpers/MethodMirrorBuilder.d.ts +10 -0
- package/lib/test-helpers/MethodMirrorBuilder.js +37 -0
- package/lib/test-helpers/MethodMirrorBuilder.js.map +1 -0
- package/lib/test-helpers/SettingsBuilder.d.ts +8 -0
- package/lib/test-helpers/SettingsBuilder.js +24 -0
- package/lib/test-helpers/SettingsBuilder.js.map +1 -0
- package/lib/transpiler/factory.d.ts +6 -0
- package/lib/transpiler/factory.js +32 -0
- package/lib/transpiler/factory.js.map +1 -0
- package/lib/transpiler/file-container.d.ts +4 -4
- package/lib/transpiler/file-container.js.map +1 -1
- package/lib/transpiler/generator-choices.d.ts +1 -0
- package/lib/transpiler/generator-choices.js +3 -0
- package/lib/transpiler/generator-choices.js.map +1 -0
- package/lib/transpiler/markdown/class-file-generatorHelper.js +4 -2
- package/lib/transpiler/markdown/class-file-generatorHelper.js.map +1 -1
- package/lib/transpiler/openapi/open-api-docs-processor.d.ts +12 -0
- package/lib/transpiler/openapi/open-api-docs-processor.js +62 -0
- package/lib/transpiler/openapi/open-api-docs-processor.js.map +1 -0
- package/lib/transpiler/openapi/parsers/Builder.d.ts +16 -0
- package/lib/transpiler/openapi/parsers/Builder.js +30 -0
- package/lib/transpiler/openapi/parsers/Builder.js.map +1 -0
- package/lib/transpiler/openapi/parsers/MethodParser.d.ts +17 -0
- package/lib/transpiler/openapi/parsers/MethodParser.js +106 -0
- package/lib/transpiler/openapi/parsers/MethodParser.js.map +1 -0
- package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.d.ts +7 -0
- package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.js +11 -0
- package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.js.map +1 -0
- package/lib/transpiler/openapi/parsers/ReferenceBuilder.d.ts +31 -0
- package/lib/transpiler/openapi/parsers/ReferenceBuilder.js +161 -0
- package/lib/transpiler/openapi/parsers/ReferenceBuilder.js.map +1 -0
- package/lib/transpiler/openapi/parsers/RequestBodyBuilder.d.ts +10 -0
- package/lib/transpiler/openapi/parsers/RequestBodyBuilder.js +20 -0
- package/lib/transpiler/openapi/parsers/RequestBodyBuilder.js.map +1 -0
- package/lib/transpiler/openapi/parsers/ResponsesBuilder.d.ts +7 -0
- package/lib/transpiler/openapi/parsers/ResponsesBuilder.js +18 -0
- package/lib/transpiler/openapi/parsers/ResponsesBuilder.js.map +1 -0
- package/lib/transpiler/processor-type-transpiler.d.ts +2 -2
- package/lib/transpiler/processor-type-transpiler.js +3 -0
- package/lib/transpiler/processor-type-transpiler.js.map +1 -1
- package/lib/transpiler/transpiler.js.map +1 -1
- package/lib/util/error-logger.js.map +1 -1
- package/package.json +8 -5
- package/src/application/Apexdocs.ts +37 -16
- package/src/cli/generate.ts +13 -4
- package/src/model/apex-type-wrappers/ClassMirrorWrapper.ts +12 -0
- package/src/model/apex-type-wrappers/__tests__/ClassMirrorWrapper.spec.ts +15 -0
- package/src/model/markdown-file.ts +2 -2
- package/src/model/markdown-generation-util/field-declaration-util.ts +5 -2
- package/src/model/markdown-generation-util/method-declaration-util.ts +5 -3
- package/src/model/markdown-generation-util/type-declaration-util.ts +1 -1
- package/src/model/openapi/__tests__/open-api.spec.ts +22 -0
- package/src/model/openapi/apex-doc-types.ts +25 -0
- package/src/model/openapi/open-api-types.ts +112 -0
- package/src/model/openapi/open-api.ts +39 -0
- package/src/model/openapi/openapi-type-file.ts +13 -0
- package/src/model/{file.ts → outputFile.ts} +1 -1
- package/src/model/types-repository.ts +48 -6
- package/src/service/file-writer.ts +2 -2
- package/src/settings.ts +8 -29
- package/src/test-helpers/AnnotationBuilder.ts +29 -0
- package/src/test-helpers/ClassMirrorBuilder.ts +56 -0
- package/src/test-helpers/DocCommentAnnotationBuilder.ts +18 -0
- package/src/test-helpers/DocCommentBuilder.ts +36 -0
- package/src/test-helpers/FieldMirrorBuilder.ts +52 -0
- package/src/test-helpers/MethodMirrorBuilder.ts +37 -0
- package/src/test-helpers/SettingsBuilder.ts +21 -0
- package/src/transpiler/factory.ts +33 -0
- package/src/transpiler/file-container.ts +4 -4
- package/src/transpiler/generator-choices.ts +1 -0
- package/src/transpiler/markdown/class-file-generatorHelper.ts +4 -2
- package/src/transpiler/openapi/__tests__/open-api-docs-processor.spec.ts +41 -0
- package/src/transpiler/openapi/open-api-docs-processor.ts +76 -0
- package/src/transpiler/openapi/parsers/Builder.ts +40 -0
- package/src/transpiler/openapi/parsers/MethodParser.ts +142 -0
- package/src/transpiler/openapi/parsers/ParameterObjectBuilder.ts +13 -0
- package/src/transpiler/openapi/parsers/ReferenceBuilder.ts +205 -0
- package/src/transpiler/openapi/parsers/RequestBodyBuilder.ts +19 -0
- package/src/transpiler/openapi/parsers/ResponsesBuilder.ts +17 -0
- package/src/transpiler/openapi/parsers/__tests__/MethodParser.spec.ts +44 -0
- package/src/transpiler/openapi/parsers/__tests__/ParameterObjectBuilder.spec.ts +68 -0
- package/src/transpiler/openapi/parsers/__tests__/ReferenceBuilder.spec.ts +622 -0
- package/src/transpiler/openapi/parsers/__tests__/RequestBodyBuilder.spec.ts +64 -0
- package/src/transpiler/openapi/parsers/__tests__/ResponsesBuilder.spec.ts +55 -0
- package/src/transpiler/processor-type-transpiler.ts +3 -1
- package/tsconfig.json +4 -1
- package/lib/model/file.js.map +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
description?: string;
|
|
30
|
+
requestBody?: RequestBody;
|
|
31
|
+
parameters?: ParameterObject[];
|
|
32
|
+
responses?: ResponsesObject;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// Parameters
|
|
36
|
+
export type ParameterObject = {
|
|
37
|
+
name: string;
|
|
38
|
+
in: 'query' | 'header' | 'path' | 'cookie';
|
|
39
|
+
description?: string;
|
|
40
|
+
required?: boolean;
|
|
41
|
+
schema?: SchemaObject;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// Request Body
|
|
45
|
+
export type RequestBody = {
|
|
46
|
+
description?: string;
|
|
47
|
+
content: RequestBodyContent;
|
|
48
|
+
required?: boolean;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type RequestBodyContent = {
|
|
52
|
+
[index: string]: MediaTypeObject; // Only key supported is "application/json" for now.
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type MediaTypeObject = {
|
|
56
|
+
schema?: SchemaObject;
|
|
57
|
+
example?: any; // TODO: Parse this on the output
|
|
58
|
+
examples?: { [index: string]: ExampleObject }; // TODO: Parse this on the output
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export type ExampleObject = {
|
|
62
|
+
summary?: string;
|
|
63
|
+
description?: string;
|
|
64
|
+
value?: any;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Responses
|
|
68
|
+
export type ResponsesObject = {
|
|
69
|
+
[index: string]: ResponseObject; // The key will be the status code number
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type ResponseObject = {
|
|
73
|
+
description: string;
|
|
74
|
+
content?: ContentObject;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type ContentObject = {
|
|
78
|
+
[index: string]: { schema: SchemaObject }; // key is usually 'application/json'
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Common
|
|
82
|
+
export type SchemaObject = SchemaObjectObject | SchemaObjectArray | ReferenceObject;
|
|
83
|
+
|
|
84
|
+
export type SchemaObjectObject = {
|
|
85
|
+
type: string; // This can be "object" (which would require properties), or a primitive
|
|
86
|
+
properties?: PropertiesObject;
|
|
87
|
+
format?: string;
|
|
88
|
+
description?: string;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export type PropertiesObject = {
|
|
92
|
+
[index: string]: SchemaObject;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export type SchemaObjectArray = {
|
|
96
|
+
type: 'array';
|
|
97
|
+
items: SchemaObject;
|
|
98
|
+
description?: string;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// Reference and components
|
|
102
|
+
|
|
103
|
+
export type ReferenceObject = {
|
|
104
|
+
$ref: string;
|
|
105
|
+
description?: string;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export type ComponentsObject = {
|
|
109
|
+
schemas: {
|
|
110
|
+
[index: string]: SchemaObject;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ComponentsObject, InfoObject, PathsObject, ServerObject } 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
|
+
paths: PathsObject;
|
|
14
|
+
servers: ServerObject[];
|
|
15
|
+
components?: ComponentsObject;
|
|
16
|
+
|
|
17
|
+
constructor(title: string, version: string, public namespace?: string) {
|
|
18
|
+
this.info = {
|
|
19
|
+
title: title,
|
|
20
|
+
version: version,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
this.servers = [
|
|
24
|
+
{
|
|
25
|
+
url: this.getServerUrl(),
|
|
26
|
+
},
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
this.paths = {};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private getServerUrl(): string {
|
|
33
|
+
if (!this.namespace) {
|
|
34
|
+
return SERVER_URL;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return `${SERVER_URL}${this.namespace}/`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { OutputFile } from '../outputFile';
|
|
2
|
+
import { OpenApi } from './open-api';
|
|
3
|
+
|
|
4
|
+
export class OpenapiTypeFile extends OutputFile {
|
|
5
|
+
constructor(public openApiModel: OpenApi) {
|
|
6
|
+
super('openapi', '');
|
|
7
|
+
this.addText(JSON.stringify(openApiModel, null, 2));
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
fileExtension(): string {
|
|
11
|
+
return '.json';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { Type } from '@cparra/apex-reflection';
|
|
1
|
+
import { ClassMirror, Type } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
export type TypeBundle = { type: Type; isChild: boolean; parentType?: Type };
|
|
2
4
|
|
|
3
5
|
export class TypesRepository {
|
|
4
6
|
private static instance: TypesRepository;
|
|
5
|
-
private
|
|
7
|
+
private scopedTypes: Type[] = [];
|
|
8
|
+
private allTypes: Type[] = [];
|
|
6
9
|
|
|
7
10
|
public static getInstance(): TypesRepository {
|
|
8
11
|
if (!TypesRepository.instance) {
|
|
@@ -11,11 +14,50 @@ export class TypesRepository {
|
|
|
11
14
|
return TypesRepository.instance;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
|
-
public
|
|
15
|
-
this.
|
|
17
|
+
public populateAll(types: Type[]) {
|
|
18
|
+
this.allTypes = types;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public getFromAllByName(typeName: string): TypeBundle | undefined {
|
|
22
|
+
if (typeName.includes('.')) {
|
|
23
|
+
// If it includes a dot we are assuming we are dealing with an inner class.
|
|
24
|
+
const [parentTypeName, childTypeName] = typeName.split('.');
|
|
25
|
+
const parentReference = this.allTypes.find(
|
|
26
|
+
(currentType: Type) => currentType.name.toLowerCase() === parentTypeName.toLowerCase(),
|
|
27
|
+
);
|
|
28
|
+
if (!parentReference || parentReference.type_name !== 'class') {
|
|
29
|
+
// If the parent is not found, no reason to keep searching, instead we return undefined.
|
|
30
|
+
// Similarly, if the parent is not a class, it means it cannot have children, so we return early.
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const parentReferenceAsClass = parentReference as ClassMirror;
|
|
35
|
+
const childTypes = [
|
|
36
|
+
...parentReferenceAsClass.classes,
|
|
37
|
+
...parentReferenceAsClass.interfaces,
|
|
38
|
+
...parentReferenceAsClass.enums,
|
|
39
|
+
];
|
|
40
|
+
const foundType = childTypes.find((currentType: Type) => currentType.name.toLowerCase() === childTypeName);
|
|
41
|
+
if (!foundType) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return { type: foundType, isChild: true, parentType: parentReference };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const foundType = this.allTypes.find(
|
|
48
|
+
(currentType: Type) => currentType.name.toLowerCase() === typeName.toLowerCase(),
|
|
49
|
+
);
|
|
50
|
+
if (!foundType) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
return { type: foundType, isChild: false };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public populateScoped(types: Type[]) {
|
|
57
|
+
this.scopedTypes = types;
|
|
16
58
|
}
|
|
17
59
|
|
|
18
|
-
public
|
|
19
|
-
return this.
|
|
60
|
+
public getFromScopedByName(typeName: string): Type | undefined {
|
|
61
|
+
return this.scopedTypes.find((currentType: Type) => currentType.name === typeName);
|
|
20
62
|
}
|
|
21
63
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as fs from 'fs';
|
|
2
2
|
import * as path from 'path';
|
|
3
|
-
import {
|
|
3
|
+
import { OutputFile } from '../model/outputFile';
|
|
4
4
|
import { Settings } from '../settings';
|
|
5
5
|
|
|
6
6
|
export class FileWriter {
|
|
7
|
-
static write(files:
|
|
7
|
+
static write(files: OutputFile[], onWriteCallback: (fileName: string) => void) {
|
|
8
8
|
const outputDir = Settings.getInstance().outputDir;
|
|
9
9
|
if (!fs.existsSync(outputDir)) {
|
|
10
10
|
fs.mkdirSync(outputDir);
|
package/src/settings.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { JekyllDocsProcessor } from './transpiler/markdown/jekyll/jekyll-docsProcessor';
|
|
3
|
-
import DocsifyDocsProcessor from './transpiler/markdown/docsify/docsify-docs-processor';
|
|
4
|
-
import { PlainMarkdownDocsProcessor } from './transpiler/markdown/plain-markdown/plain-docsProcessor';
|
|
5
|
-
|
|
6
|
-
export type GeneratorChoices = 'jekyll' | 'docsify' | 'plain-markdown';
|
|
1
|
+
import { GeneratorChoices } from './transpiler/generator-choices';
|
|
7
2
|
|
|
8
3
|
export interface SettingsConfig {
|
|
9
4
|
sourceDirectory: string;
|
|
@@ -14,6 +9,7 @@ export interface SettingsConfig {
|
|
|
14
9
|
indexOnly: boolean;
|
|
15
10
|
defaultGroupName: string;
|
|
16
11
|
sanitizeHtml: boolean;
|
|
12
|
+
openApiTitle?: string;
|
|
17
13
|
}
|
|
18
14
|
|
|
19
15
|
export class Settings {
|
|
@@ -48,25 +44,8 @@ export class Settings {
|
|
|
48
44
|
return this.config.outputDir;
|
|
49
45
|
}
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
get typeTranspiler(): ProcessorTypeTranspiler {
|
|
54
|
-
if (Settings.typeTranspilerCache) {
|
|
55
|
-
return Settings.typeTranspilerCache;
|
|
56
|
-
}
|
|
57
|
-
switch (this.config.targetGenerator) {
|
|
58
|
-
case 'jekyll':
|
|
59
|
-
Settings.typeTranspilerCache = new JekyllDocsProcessor();
|
|
60
|
-
return Settings.typeTranspilerCache;
|
|
61
|
-
case 'docsify':
|
|
62
|
-
Settings.typeTranspilerCache = new DocsifyDocsProcessor();
|
|
63
|
-
return Settings.typeTranspilerCache;
|
|
64
|
-
case 'plain-markdown':
|
|
65
|
-
Settings.typeTranspilerCache = new PlainMarkdownDocsProcessor();
|
|
66
|
-
return Settings.typeTranspilerCache;
|
|
67
|
-
default:
|
|
68
|
-
throw Error('Invalid target generator');
|
|
69
|
-
}
|
|
47
|
+
get targetGenerator(): GeneratorChoices {
|
|
48
|
+
return this.config.targetGenerator;
|
|
70
49
|
}
|
|
71
50
|
|
|
72
51
|
get indexOnly(): boolean {
|
|
@@ -77,11 +56,11 @@ export class Settings {
|
|
|
77
56
|
return this.config.sanitizeHtml;
|
|
78
57
|
}
|
|
79
58
|
|
|
80
|
-
get numberOfVisibleDescriptionLinesOnHomePage() {
|
|
81
|
-
return 5;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
59
|
public getDefaultGroupName(): string {
|
|
85
60
|
return this.config.defaultGroupName;
|
|
86
61
|
}
|
|
62
|
+
|
|
63
|
+
public getOpenApiTitle(): string | undefined {
|
|
64
|
+
return this.config.openApiTitle;
|
|
65
|
+
}
|
|
87
66
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Annotation, AnnotationElementValue } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builder class to create Annotation objects.
|
|
5
|
+
* For testing purposes only.
|
|
6
|
+
*/
|
|
7
|
+
export class AnnotationBuilder {
|
|
8
|
+
private name = 'restresource';
|
|
9
|
+
private elementValues: AnnotationElementValue[] = [];
|
|
10
|
+
|
|
11
|
+
withName(name: string): AnnotationBuilder {
|
|
12
|
+
this.name = name;
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
addElementValue(elementValue: AnnotationElementValue): AnnotationBuilder {
|
|
17
|
+
this.elementValues.push(elementValue);
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
build(): Annotation {
|
|
22
|
+
return {
|
|
23
|
+
rawDeclaration: '',
|
|
24
|
+
name: this.name,
|
|
25
|
+
type: this.name,
|
|
26
|
+
elementValues: this.elementValues,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Annotation, ClassMirror, DocComment, FieldMirror, MethodMirror } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builder class to create ClassMirror objects.
|
|
5
|
+
* For testing purposes only.
|
|
6
|
+
*/
|
|
7
|
+
export class ClassMirrorBuilder {
|
|
8
|
+
private name = 'SampleClass';
|
|
9
|
+
private annotations: Annotation[] = [];
|
|
10
|
+
private docComment?: DocComment;
|
|
11
|
+
private methods: MethodMirror[] = [];
|
|
12
|
+
private fields: FieldMirror[] = [];
|
|
13
|
+
|
|
14
|
+
withName(name: string): ClassMirrorBuilder {
|
|
15
|
+
this.name = name;
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
addAnnotation(annotation: Annotation): ClassMirrorBuilder {
|
|
20
|
+
this.annotations.push(annotation);
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
withDocComment(docComment: DocComment): ClassMirrorBuilder {
|
|
25
|
+
this.docComment = docComment;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
addMethod(method: MethodMirror): ClassMirrorBuilder {
|
|
30
|
+
this.methods.push(method);
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
addFiled(field: FieldMirror): ClassMirrorBuilder {
|
|
35
|
+
this.fields.push(field);
|
|
36
|
+
return this;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
build(): ClassMirror {
|
|
40
|
+
return {
|
|
41
|
+
annotations: this.annotations,
|
|
42
|
+
name: this.name,
|
|
43
|
+
type_name: 'class',
|
|
44
|
+
methods: this.methods,
|
|
45
|
+
implemented_interfaces: [],
|
|
46
|
+
properties: [],
|
|
47
|
+
fields: this.fields,
|
|
48
|
+
constructors: [],
|
|
49
|
+
enums: [],
|
|
50
|
+
interfaces: [],
|
|
51
|
+
classes: [],
|
|
52
|
+
access_modifier: 'public',
|
|
53
|
+
docComment: this.docComment,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DocCommentAnnotation } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
export class DocCommentAnnotationBuilder {
|
|
4
|
+
private name = '';
|
|
5
|
+
|
|
6
|
+
withName(name: string): DocCommentAnnotationBuilder {
|
|
7
|
+
this.name = name;
|
|
8
|
+
return this;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
build(): DocCommentAnnotation {
|
|
12
|
+
return {
|
|
13
|
+
name: this.name,
|
|
14
|
+
body: '',
|
|
15
|
+
bodyLines: [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { DocComment, DocCommentAnnotation } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builder class to create DocComment objects.
|
|
5
|
+
* For testing purposes only.
|
|
6
|
+
*/
|
|
7
|
+
export class DocCommentBuilder {
|
|
8
|
+
private description?: string;
|
|
9
|
+
private annotations: DocCommentAnnotation[] = [];
|
|
10
|
+
|
|
11
|
+
addAnnotation(annotation: DocCommentAnnotation): DocCommentBuilder {
|
|
12
|
+
this.annotations.push(annotation);
|
|
13
|
+
return this;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
withDescription(description: string): DocCommentBuilder {
|
|
17
|
+
this.description = description;
|
|
18
|
+
return this;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
build(): DocComment {
|
|
22
|
+
return {
|
|
23
|
+
paramAnnotations: [],
|
|
24
|
+
returnAnnotation: {
|
|
25
|
+
bodyLines: [],
|
|
26
|
+
},
|
|
27
|
+
exampleAnnotation: {
|
|
28
|
+
bodyLines: [],
|
|
29
|
+
},
|
|
30
|
+
throwsAnnotations: [],
|
|
31
|
+
annotations: this.annotations,
|
|
32
|
+
descriptionLines: [],
|
|
33
|
+
description: this.description ?? 'Sample Description',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { FieldMirror } from '@cparra/apex-reflection';
|
|
2
|
+
import { ReferencedType } from '@cparra/apex-reflection/index';
|
|
3
|
+
|
|
4
|
+
type MemberModifier = 'static' | 'webservice' | 'final' | 'override' | 'testmethod' | 'transient';
|
|
5
|
+
|
|
6
|
+
export class FieldMirrorBuilder {
|
|
7
|
+
private accessModifier = 'public';
|
|
8
|
+
private name = 'fieldName';
|
|
9
|
+
private memberModifiers: MemberModifier[] = [];
|
|
10
|
+
private type: ReferencedType = {
|
|
11
|
+
type: 'String',
|
|
12
|
+
rawDeclaration: 'String',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
withAccessModifier(accessModifier: string): FieldMirrorBuilder {
|
|
16
|
+
this.accessModifier = accessModifier;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
withName(name: string): FieldMirrorBuilder {
|
|
21
|
+
this.name = name;
|
|
22
|
+
return this;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
withType(type: string): FieldMirrorBuilder {
|
|
26
|
+
this.type = {
|
|
27
|
+
rawDeclaration: type,
|
|
28
|
+
type: type,
|
|
29
|
+
};
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
withReferencedType(type: ReferencedType): FieldMirrorBuilder {
|
|
34
|
+
this.type = type;
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
addMemberModifier(memberModifier: MemberModifier): FieldMirrorBuilder {
|
|
39
|
+
this.memberModifiers.push(memberModifier);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
build(): FieldMirror {
|
|
44
|
+
return {
|
|
45
|
+
access_modifier: this.accessModifier,
|
|
46
|
+
annotations: [],
|
|
47
|
+
name: this.name,
|
|
48
|
+
memberModifiers: this.memberModifiers,
|
|
49
|
+
typeReference: this.type,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Annotation, DocComment, MethodMirror } from '@cparra/apex-reflection';
|
|
2
|
+
|
|
3
|
+
export class MethodMirrorBuilder {
|
|
4
|
+
private name = 'sampleMethod';
|
|
5
|
+
private annotations: Annotation[] = [];
|
|
6
|
+
private docComment?: DocComment;
|
|
7
|
+
|
|
8
|
+
withName(name: string): MethodMirrorBuilder {
|
|
9
|
+
this.name = name;
|
|
10
|
+
return this;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
addAnnotation(annotation: Annotation): MethodMirrorBuilder {
|
|
14
|
+
this.annotations.push(annotation);
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
withDocComment(docComment: DocComment): MethodMirrorBuilder {
|
|
19
|
+
this.docComment = docComment;
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
build(): MethodMirror {
|
|
24
|
+
return {
|
|
25
|
+
access_modifier: 'public',
|
|
26
|
+
annotations: this.annotations,
|
|
27
|
+
name: this.name,
|
|
28
|
+
memberModifiers: [],
|
|
29
|
+
typeReference: {
|
|
30
|
+
type: 'void',
|
|
31
|
+
rawDeclaration: 'void',
|
|
32
|
+
},
|
|
33
|
+
parameters: [],
|
|
34
|
+
docComment: this.docComment,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SettingsConfig } from '../settings';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builder class to create SettingsConfig objects.
|
|
5
|
+
* For testing purposes only.
|
|
6
|
+
*/
|
|
7
|
+
export class SettingsBuilder {
|
|
8
|
+
build(): SettingsConfig {
|
|
9
|
+
return {
|
|
10
|
+
sourceDirectory: './',
|
|
11
|
+
recursive: true,
|
|
12
|
+
scope: [],
|
|
13
|
+
outputDir: './',
|
|
14
|
+
targetGenerator: 'openapi',
|
|
15
|
+
indexOnly: false,
|
|
16
|
+
defaultGroupName: 'Misc',
|
|
17
|
+
sanitizeHtml: true,
|
|
18
|
+
openApiTitle: 'Apex API',
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import ProcessorTypeTranspiler from './processor-type-transpiler';
|
|
2
|
+
import { GeneratorChoices } from './generator-choices';
|
|
3
|
+
import { JekyllDocsProcessor } from './markdown/jekyll/jekyll-docsProcessor';
|
|
4
|
+
import DocsifyDocsProcessor from './markdown/docsify/docsify-docs-processor';
|
|
5
|
+
import { PlainMarkdownDocsProcessor } from './markdown/plain-markdown/plain-docsProcessor';
|
|
6
|
+
import { OpenApiDocsProcessor } from './openapi/open-api-docs-processor';
|
|
7
|
+
|
|
8
|
+
export class TypeTranspilerFactory {
|
|
9
|
+
private static typeTranspilerCache?: ProcessorTypeTranspiler;
|
|
10
|
+
|
|
11
|
+
public static get(generator: GeneratorChoices): ProcessorTypeTranspiler {
|
|
12
|
+
if (this.typeTranspilerCache) {
|
|
13
|
+
return this.typeTranspilerCache;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
switch (generator) {
|
|
17
|
+
case 'jekyll':
|
|
18
|
+
this.typeTranspilerCache = new JekyllDocsProcessor();
|
|
19
|
+
return this.typeTranspilerCache;
|
|
20
|
+
case 'docsify':
|
|
21
|
+
this.typeTranspilerCache = new DocsifyDocsProcessor();
|
|
22
|
+
return this.typeTranspilerCache;
|
|
23
|
+
case 'plain-markdown':
|
|
24
|
+
this.typeTranspilerCache = new PlainMarkdownDocsProcessor();
|
|
25
|
+
return this.typeTranspilerCache;
|
|
26
|
+
case 'openapi':
|
|
27
|
+
this.typeTranspilerCache = new OpenApiDocsProcessor();
|
|
28
|
+
return this.typeTranspilerCache;
|
|
29
|
+
default:
|
|
30
|
+
throw Error('Invalid target generator');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OutputFile } from '../model/outputFile';
|
|
2
2
|
|
|
3
3
|
export class FileContainer {
|
|
4
|
-
_files:
|
|
4
|
+
_files: OutputFile[] = [];
|
|
5
5
|
|
|
6
|
-
files():
|
|
6
|
+
files(): OutputFile[] {
|
|
7
7
|
return this._files;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
pushFile(file:
|
|
10
|
+
pushFile(file: OutputFile): void {
|
|
11
11
|
this._files.push(file);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type GeneratorChoices = 'jekyll' | 'docsify' | 'plain-markdown' | 'openapi';
|
|
@@ -2,6 +2,7 @@ import { Type } from '@cparra/apex-reflection';
|
|
|
2
2
|
import { TypesRepository } from '../../model/types-repository';
|
|
3
3
|
import { Settings } from '../../settings';
|
|
4
4
|
import State from '../../service/state';
|
|
5
|
+
import { TypeTranspilerFactory } from '../factory';
|
|
5
6
|
|
|
6
7
|
export default class ClassFileGeneratorHelper {
|
|
7
8
|
public static getSanitizedGroup(classModel: Type) {
|
|
@@ -14,7 +15,7 @@ export default class ClassFileGeneratorHelper {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
public static getFileLinkByTypeName(typeName: string) {
|
|
17
|
-
const type = TypesRepository.getInstance().
|
|
18
|
+
const type = TypesRepository.getInstance().getFromScopedByName(typeName);
|
|
18
19
|
if (!type) {
|
|
19
20
|
// If the type is not found we return a Markdown hyperlink with whatever we received.
|
|
20
21
|
return `[${typeName}](${typeName})`;
|
|
@@ -25,7 +26,8 @@ export default class ClassFileGeneratorHelper {
|
|
|
25
26
|
|
|
26
27
|
private static getDirectoryRoot(classModel: Type) {
|
|
27
28
|
// root-relative links start from the root by using a leading '/'
|
|
28
|
-
|
|
29
|
+
const generator = Settings.getInstance().targetGenerator;
|
|
30
|
+
if (TypeTranspilerFactory.get(generator).getLinkingStrategy() === 'root-relative') {
|
|
29
31
|
return `/${this.getSanitizedGroup(classModel)}/`;
|
|
30
32
|
}
|
|
31
33
|
|