@cparra/apexdocs 2.23.0 → 2.24.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.
- package/.eslintrc.js +12 -12
- package/.github/workflows/close_stale.yml +22 -22
- package/.prettierrc.js +7 -7
- package/LICENSE +21 -21
- package/README.md +718 -718
- package/apexdocs.config.ts +13 -13
- package/docs/README.md +1 -1
- package/docs/restapi.json +589 -589
- package/docs/types/Classes/nspc.ChildClass.md +97 -97
- package/docs/types/Main/nspc.SampleClass.md +189 -189
- package/examples/force-app/main/default/classes/AnotherInterface.cls +16 -16
- package/examples/force-app/main/default/classes/ChildClass.cls +42 -42
- package/examples/force-app/main/default/classes/EscapedAnnotations.cls +5 -5
- package/examples/force-app/main/default/classes/GrandparentClass.cls +4 -4
- package/examples/force-app/main/default/classes/GroupedClass.cls +8 -8
- package/examples/force-app/main/default/classes/MemberGrouping.cls +17 -17
- package/examples/force-app/main/default/classes/ParentClass.cls +16 -16
- package/examples/force-app/main/default/classes/SampleClass.cls +166 -166
- package/examples/force-app/main/default/classes/SampleClass.cls-meta.xml +5 -5
- package/examples/force-app/main/default/classes/SampleClassWithoutModifier.cls +9 -9
- package/examples/force-app/main/default/classes/SampleInterface.cls +16 -16
- package/examples/force-app/main/default/restapi/SampleRestResource.cls +195 -195
- package/examples/force-app/main/default/restapi/SampleRestResourceToSkip.cls +35 -35
- package/examples/force-app/main/default/restapi/SampleRestResourceWithInnerClass.cls +24 -24
- package/examples/force-app/main/default/restapi/SampleRestResourceWithoutApexDocs.cls +15 -15
- package/examples/force-app/main/default/restapi/references/Reference1.cls +9 -9
- package/examples/force-app/main/default/restapi/references/Reference2.cls +9 -9
- package/examples/force-app/main/default/restapi/references/Reference3.cls +3 -3
- package/examples/force-app/main/default/restapi/references/Reference4.cls +3 -3
- package/examples/force-app/main/default/restapi/references/Reference5.cls +3 -3
- package/examples/force-app/main/default/restapi/references/Reference6.cls +6 -6
- package/examples/force-app/main/default/restapi/references/Reference7.cls +3 -3
- package/examples/includes/header.md +3 -3
- package/jest.config.js +5 -5
- package/lib/application/Apexdocs.d.ts +13 -13
- package/lib/application/Apexdocs.js +76 -76
- package/lib/cli/generate.d.ts +2 -2
- package/lib/cli/generate.js +130 -130
- package/lib/index.d.ts +1 -1
- package/lib/index.js +17 -17
- package/lib/model/apex-bundle.d.ts +6 -6
- package/lib/model/apex-bundle.js +10 -10
- package/lib/model/apex-type-wrappers/ClassMirrorWrapper.d.ts +7 -7
- package/lib/model/apex-type-wrappers/ClassMirrorWrapper.js +13 -13
- package/lib/model/apex-type-wrappers/MethodMirrorWrapper.d.ts +7 -7
- package/lib/model/apex-type-wrappers/MethodMirrorWrapper.js +11 -11
- package/lib/model/inheritance.d.ts +8 -8
- package/lib/model/inheritance.js +2 -2
- package/lib/model/manifest-diff.d.ts +27 -27
- package/lib/model/manifest-diff.js +68 -68
- package/lib/model/manifest.d.ts +22 -22
- package/lib/model/manifest.js +46 -46
- package/lib/model/markdown-file.d.ts +16 -16
- package/lib/model/markdown-file.js +106 -106
- package/lib/model/markdown-generation-util/doc-comment-annotation-util.d.ts +8 -8
- package/lib/model/markdown-generation-util/doc-comment-annotation-util.js +43 -43
- package/lib/model/markdown-generation-util/field-declaration-util.d.ts +3 -3
- package/lib/model/markdown-generation-util/field-declaration-util.js +54 -54
- package/lib/model/markdown-generation-util/index.d.ts +3 -3
- package/lib/model/markdown-generation-util/index.js +19 -19
- package/lib/model/markdown-generation-util/method-declaration-util.d.ts +4 -4
- package/lib/model/markdown-generation-util/method-declaration-util.js +114 -114
- package/lib/model/markdown-generation-util/type-declaration-util.d.ts +3 -3
- package/lib/model/markdown-generation-util/type-declaration-util.js +81 -81
- package/lib/model/markdown-home-file.d.ts +11 -11
- package/lib/model/markdown-home-file.js +53 -53
- package/lib/model/markdown-type-file.d.ts +26 -26
- package/lib/model/markdown-type-file.js +133 -133
- package/lib/model/openapi/apex-doc-types.d.ts +19 -19
- package/lib/model/openapi/apex-doc-types.js +4 -4
- package/lib/model/openapi/open-api-types.d.ts +93 -93
- package/lib/model/openapi/open-api-types.js +2 -2
- package/lib/model/openapi/open-api.d.ts +16 -16
- package/lib/model/openapi/open-api.js +33 -33
- package/lib/model/openapi/openapi-type-file.d.ts +7 -7
- package/lib/model/openapi/openapi-type-file.js +16 -16
- package/lib/model/outputFile.d.ts +10 -10
- package/lib/model/outputFile.js +28 -28
- package/lib/model/types-repository.d.ts +16 -16
- package/lib/model/types-repository.js +53 -53
- package/lib/service/apex-file-reader.d.ts +14 -14
- package/lib/service/apex-file-reader.js +45 -45
- package/lib/service/file-system.d.ts +14 -14
- package/lib/service/file-system.js +24 -24
- package/lib/service/file-writer.d.ts +6 -6
- package/lib/service/file-writer.js +33 -33
- package/lib/service/manifest-factory.d.ts +10 -10
- package/lib/service/manifest-factory.js +13 -13
- package/lib/service/metadata-processor.d.ts +3 -3
- package/lib/service/metadata-processor.js +16 -16
- package/lib/service/parser.d.ts +21 -21
- package/lib/service/parser.js +134 -134
- package/lib/service/state.d.ts +9 -9
- package/lib/service/state.js +19 -19
- package/lib/service/walkers/class-walker.d.ts +4 -4
- package/lib/service/walkers/class-walker.js +32 -32
- package/lib/service/walkers/enum-walker.d.ts +4 -4
- package/lib/service/walkers/enum-walker.js +10 -10
- package/lib/service/walkers/interface-walker.d.ts +4 -4
- package/lib/service/walkers/interface-walker.js +14 -14
- package/lib/service/walkers/walker-factory.d.ts +5 -5
- package/lib/service/walkers/walker-factory.js +20 -20
- package/lib/service/walkers/walker.d.ts +19 -19
- package/lib/service/walkers/walker.js +16 -16
- package/lib/settings.d.ts +64 -64
- package/lib/settings.js +88 -88
- package/lib/test-helpers/AnnotationBuilder.d.ts +12 -12
- package/lib/test-helpers/AnnotationBuilder.js +30 -30
- package/lib/test-helpers/ClassMirrorBuilder.d.ts +18 -18
- package/lib/test-helpers/ClassMirrorBuilder.js +53 -53
- package/lib/test-helpers/DocCommentAnnotationBuilder.d.ts +8 -8
- package/lib/test-helpers/DocCommentAnnotationBuilder.js +25 -25
- package/lib/test-helpers/DocCommentBuilder.d.ts +12 -12
- package/lib/test-helpers/DocCommentBuilder.js +37 -37
- package/lib/test-helpers/FieldMirrorBuilder.d.ts +18 -18
- package/lib/test-helpers/FieldMirrorBuilder.js +53 -53
- package/lib/test-helpers/MethodMirrorBuilder.d.ts +10 -10
- package/lib/test-helpers/MethodMirrorBuilder.js +36 -36
- package/lib/test-helpers/SettingsBuilder.d.ts +8 -8
- package/lib/test-helpers/SettingsBuilder.js +26 -26
- package/lib/transpiler/factory.d.ts +6 -6
- package/lib/transpiler/factory.js +31 -31
- package/lib/transpiler/file-container.d.ts +6 -6
- package/lib/transpiler/file-container.js +15 -15
- package/lib/transpiler/generator-choices.d.ts +1 -1
- package/lib/transpiler/generator-choices.js +2 -2
- package/lib/transpiler/markdown/class-file-generatorHelper.d.ts +8 -8
- package/lib/transpiler/markdown/class-file-generatorHelper.js +55 -55
- package/lib/transpiler/markdown/docsify/docsify-docs-processor.d.ts +6 -6
- package/lib/transpiler/markdown/docsify/docsify-docs-processor.js +12 -12
- package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.d.ts +11 -11
- package/lib/transpiler/markdown/jekyll/jekyll-docsProcessor.js +50 -50
- package/lib/transpiler/markdown/markdown-transpiler-base.d.ts +11 -11
- package/lib/transpiler/markdown/markdown-transpiler-base.js +23 -23
- package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.d.ts +6 -6
- package/lib/transpiler/markdown/plain-markdown/plain-docsProcessor.js +13 -13
- package/lib/transpiler/openapi/open-api-docs-processor.d.ts +13 -13
- package/lib/transpiler/openapi/open-api-docs-processor.js +74 -74
- package/lib/transpiler/openapi/parsers/Builder.d.ts +16 -16
- package/lib/transpiler/openapi/parsers/Builder.js +29 -29
- package/lib/transpiler/openapi/parsers/MethodParser.d.ts +20 -20
- package/lib/transpiler/openapi/parsers/MethodParser.js +166 -166
- package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.d.ts +7 -7
- package/lib/transpiler/openapi/parsers/ParameterObjectBuilder.js +10 -10
- package/lib/transpiler/openapi/parsers/ReferenceBuilder.d.ts +39 -39
- package/lib/transpiler/openapi/parsers/ReferenceBuilder.js +225 -225
- package/lib/transpiler/openapi/parsers/RequestBodyBuilder.d.ts +10 -10
- package/lib/transpiler/openapi/parsers/RequestBodyBuilder.js +19 -19
- package/lib/transpiler/openapi/parsers/ResponsesBuilder.d.ts +7 -7
- package/lib/transpiler/openapi/parsers/ResponsesBuilder.js +21 -21
- package/lib/transpiler/processor-type-transpiler.d.ts +10 -10
- package/lib/transpiler/processor-type-transpiler.js +8 -8
- package/lib/transpiler/transpiler.d.ts +5 -5
- package/lib/transpiler/transpiler.js +26 -26
- package/lib/util/error-logger.d.ts +8 -8
- package/lib/util/error-logger.js +89 -89
- package/lib/util/logger.d.ts +21 -21
- package/lib/util/logger.js +57 -57
- package/lib/util/string-utils.d.ts +2 -2
- package/lib/util/string-utils.js +14 -14
- package/package.json +78 -78
- package/tsconfig.json +20 -20
- package/tslint.json +5 -5
package/README.md
CHANGED
|
@@ -1,718 +1,718 @@
|
|
|
1
|
-
# ApexDocs
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<b>ApexDocs is a Node.js library with CLI capabilities to docGenerator documentation for Salesforce Apex classes.</b>
|
|
5
|
-
</p>
|
|
6
|
-
|
|
7
|
-
[](https://github.com/cesarParra/apexdocs/blob/master/LICENSE)
|
|
8
|
-
|
|
9
|
-
## Description
|
|
10
|
-
|
|
11
|
-
ApexDocs was originally built as an alternative to
|
|
12
|
-
the [Java based ApexDoc tool](https://github.com/SalesforceFoundation/ApexDoc) originally created by Aslam Bari and
|
|
13
|
-
later maintained by Salesforce.org, as that tool is no longer being maintained.
|
|
14
|
-
|
|
15
|
-
ApexDocs is a Node.js library built on Typescript and hosted on [npm](https://www.npmjs.com/package/@cparra/apexdocs).
|
|
16
|
-
It offers CLI capabilities to automatically document your source code, based on the ApexDoc style of documentation.
|
|
17
|
-
Additionally, it can be imported and consumed directly by your JavaScript code.
|
|
18
|
-
|
|
19
|
-
There are some key differences between ApexDocs and the Java based ApexDoc tool:
|
|
20
|
-
|
|
21
|
-
- **Recursive file search through your module directory structure**. In an `sfdx` based project, all of your classes
|
|
22
|
-
will be documented by specifying the top-most directory where file search should begin.
|
|
23
|
-
- **Unopinionated documentation site generation**. Instead of creating HTML files, ApexDocs generates a Markdown (.md)
|
|
24
|
-
file per Apex class being documented. This means you can host your files in static web hosting services that parse
|
|
25
|
-
Markdown like Github Pages or Netlify, and use site generators like Jekyll or Gatsby. This gives you the freedom to
|
|
26
|
-
decide how to style your site to match your needs.
|
|
27
|
-
|
|
28
|
-
#### Features
|
|
29
|
-
|
|
30
|
-
* Custom Annotations
|
|
31
|
-
|
|
32
|
-
Any custom annotation defined in the Apexdoc is at the class level are supported, for example the following will be
|
|
33
|
-
output to the resulting markdown file:
|
|
34
|
-
|
|
35
|
-
```apex
|
|
36
|
-
/**
|
|
37
|
-
* @MyCustomAnnotation This is a custom annotation
|
|
38
|
-
*/
|
|
39
|
-
public class MyClass {
|
|
40
|
-
}
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
* Single Line ApexDoc Blocks
|
|
44
|
-
|
|
45
|
-
📒 Note: If you wish to have multiple `@` tags in a single line but don't want them to be treated as ApexDoc annotations, you can
|
|
46
|
-
escape them by adding wrapping the annotation in ticks, for example
|
|
47
|
-
|
|
48
|
-
```apex
|
|
49
|
-
/**
|
|
50
|
-
* @MyCustomAnnotation This is a custom annotation with an `@embedded` annotation
|
|
51
|
-
*/
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
* Support for grouping blocks of related code within a class
|
|
55
|
-
* Support for HTML tags
|
|
56
|
-
* OpenApi REST specification generation
|
|
57
|
-
* Support for ignoring files and members from being documented
|
|
58
|
-
* Namespace support
|
|
59
|
-
* Configuration file support
|
|
60
|
-
* And much, much more!
|
|
61
|
-
|
|
62
|
-
### Demo
|
|
63
|
-
|
|
64
|
-
ApexDocs currently supports generating markdown files for Jekyll and Docsify sites, as well as generating plain markdown
|
|
65
|
-
files.
|
|
66
|
-
|
|
67
|
-
### In the wild
|
|
68
|
-
|
|
69
|
-
- [Expression](https://cesarparra.github.io/expression/)
|
|
70
|
-
- [Nimble AMS Docs](https://nimbleuser.github.io/nams-api-docs/#/api-reference/)
|
|
71
|
-
- [Yet Another Salesforce Logger](https://cesarparra.github.io/yet-another-salesforce-logger/#/)
|
|
72
|
-
|
|
73
|
-
### [Docsify](https://docsify.js.org/)
|
|
74
|
-
|
|
75
|
-
Demo
|
|
76
|
-
|
|
77
|
-
- [Docsify](https://cesarparra.github.io/apexdocs/)
|
|
78
|
-
|
|
79
|
-
### [Jekyll](https://jekyllrb.com/)
|
|
80
|
-
|
|
81
|
-
Demo
|
|
82
|
-
|
|
83
|
-
- [Jekyll](https://cesarparra.github.io/apexdocs-docsify-example/)
|
|
84
|
-
|
|
85
|
-
## Installation
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
npm i -g @cparra/apexdocs
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
## Usage
|
|
92
|
-
|
|
93
|
-
### CLI
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
apexdocs-generate
|
|
97
|
-
-s src
|
|
98
|
-
-t docs
|
|
99
|
-
-p global
|
|
100
|
-
-g docsify
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
The CLI supports the following parameters:
|
|
104
|
-
|
|
105
|
-
| Parameter | Alias | Description | Default | Required |
|
|
106
|
-
|-----------------------------|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|
|
|
107
|
-
| --sourceDir | -s | The directory location which contains your apex .cls classes. | N/A | Yes |
|
|
108
|
-
| --targetDir | -t | The directory location where documentation will be generated to. | `docs` | No |
|
|
109
|
-
| --recursive | -r | Whether .cls classes will be searched for recursively in the directory provided. | `true` | No |
|
|
110
|
-
| --scope | -p | A list of scopes to document. Values should be separated by a space, e.g --scope public private. Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource. | `global` | No |
|
|
111
|
-
| --targetGenerator | -g | Define the static file generator for which the documents will be created. Currently supports: `jekyll`, `docsify`, `plain-markdown`, and `openapi`. | `jekyll` | No |
|
|
112
|
-
| --indexOnly | N/A | Defines whether only the index file should be generated. | `false` | No |
|
|
113
|
-
| --defaultGroupName | N/A | Defines the `@group` name to be used when a file does not specify it. | `Miscellaneous` | No |
|
|
114
|
-
| --sanitizeHtml | N/A | When on, any special character within your ApexDocs is converted into its HTML code representation. This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" because otherwise the content within < and > would be treated as HTML tags and not shown in the output. Content in @example blocks are never sanitized. |
|
|
115
|
-
| --openApiTitle | N/A | If using "openapi" as the target generator, this allows you to specify the OpenApi title value. |
|
|
116
|
-
| --title | N/A | Allows you to specify the home page main title. If using "openapi" this acts as an alias to the openApiTitle parameter | `Classes` | No |
|
|
117
|
-
| --namespace | N/A | The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url. | N/A | No |
|
|
118
|
-
| --openApiFileName | N/A | If using "openapi" as the target generator, this allows you to specify the name of the output file. | `openapi` | No |
|
|
119
|
-
| --sortMembersAlphabetically | N/A | Whether to sort the members of a class alphabetically. | `false` | No |
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
### Using a configuration file
|
|
124
|
-
|
|
125
|
-
You can also use a configuration file to define the parameters that will be used when generating the documentation. Apexdocs
|
|
126
|
-
uses [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) to load the configuration file, which means it supports
|
|
127
|
-
the following formats:
|
|
128
|
-
|
|
129
|
-
- A `package.json` property, e.g. `{ "apexdocs": { "sourceDir": "src", "targetDir": "docs" } }`
|
|
130
|
-
- A `.apexdocsrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`
|
|
131
|
-
- An `apexdocs.config.js` file that exports an object
|
|
132
|
-
- A `apexdocs.config.ts` file that exports an object
|
|
133
|
-
|
|
134
|
-
The configuration file should be placed in the root directory of your project.
|
|
135
|
-
|
|
136
|
-
**Note that when using a configuration file, you can still override any of the parameters by passing them through the CLI.**
|
|
137
|
-
|
|
138
|
-
When defining a `.js` or `.ts` configuration file, your object export can also contain the following functions that will
|
|
139
|
-
allow you to override some of the default behavior:
|
|
140
|
-
|
|
141
|
-
- `onBeforeFileWrite` - A function that will be called before a file is written to disk. It receives a `TargetFile` object
|
|
142
|
-
that contains the file's content, path, and name, etc. It should return a `TargetFile` object with the updated content.
|
|
143
|
-
The full object definition can be imported from `@cparra/apexdocs/lib/settings`
|
|
144
|
-
- `onAfterProcess` - A function that will be called after all files have been processed. It receives a `TargetFile[]` array
|
|
145
|
-
with all of the files that were processed and does not return anything.
|
|
146
|
-
- `frontMatterHeader` - A function that will be called before the front matter is written to the file (when using the Jekyll generator).
|
|
147
|
-
It receives a `TargetType` object
|
|
148
|
-
and should return a list of strings that will be written to the file as the front matter.
|
|
149
|
-
The full object definition can be imported from `@cparra/apexdocs/lib/settings`
|
|
150
|
-
and contains the following properties:
|
|
151
|
-
- `name` - The name of the type
|
|
152
|
-
- `typeName` - Can be 'class', 'interface', or 'enum'
|
|
153
|
-
- `accessModifier` - The access modifier of the type
|
|
154
|
-
- `group` - The group to which the type belongs (if any)
|
|
155
|
-
- `description` - The description of the type as defined in the ApexDoc
|
|
156
|
-
|
|
157
|
-
```typescript
|
|
158
|
-
import {TargetFile} from "@cparra/apexdocs/lib/settings";
|
|
159
|
-
export default {
|
|
160
|
-
onBeforeFileWrite: (file: TargetFile): TargetFile => {
|
|
161
|
-
console.log('onBefore writing', file);
|
|
162
|
-
return file;
|
|
163
|
-
},
|
|
164
|
-
onAfterProcess: (files: TargetFile[]) => {
|
|
165
|
-
console.log('onAfterProcess files', files);
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### Importing to your project
|
|
172
|
-
|
|
173
|
-
If you are just interested in the Apex parsing capabilities, you can use the
|
|
174
|
-
standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
|
|
175
|
-
which is what gets used by this library behind the scenes to generate the documentation files.
|
|
176
|
-
|
|
177
|
-
## Documentation Format
|
|
178
|
-
|
|
179
|
-
ApexDocs picks up blocks of comments throughout your `.cls` files. The block must begin with `/**` and end with `*/`.
|
|
180
|
-
|
|
181
|
-
### Documenting Classes
|
|
182
|
-
|
|
183
|
-
The following tags are supported on the class level:
|
|
184
|
-
|
|
185
|
-
**Note** Any custom generated tag is also supported. Custom tags can be added with at symbol (`@`) followed by the name
|
|
186
|
-
of the tag. For example `@custom-tag`
|
|
187
|
-
|
|
188
|
-
| Tag | Description |
|
|
189
|
-
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
190
|
-
| `@description` | One or more lines describing the class. |
|
|
191
|
-
| `@see` | The name of a related class. |
|
|
192
|
-
| `@group` | The group to which the class belongs to. |
|
|
193
|
-
| `@author` | The author of the class. Note that this only gets added if it is explicitly defined through the configuration class that it should. |
|
|
194
|
-
| `@date` | The date the class was created. Note that this only gets added if it is explicitly defined through the configuration class that it should. |
|
|
195
|
-
|
|
196
|
-
**Example**
|
|
197
|
-
|
|
198
|
-
```apex
|
|
199
|
-
/**
|
|
200
|
-
* @description This is my class description.
|
|
201
|
-
*/
|
|
202
|
-
public with sharing class TestClass {
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Documenting Enums
|
|
207
|
-
|
|
208
|
-
The following tags are supported on the enum level:
|
|
209
|
-
|
|
210
|
-
| Tag | Description |
|
|
211
|
-
|----------------|----------------------------------------|
|
|
212
|
-
| `@description` | One or more lines describing the enum. |
|
|
213
|
-
|
|
214
|
-
**Example**
|
|
215
|
-
|
|
216
|
-
```apex
|
|
217
|
-
/**
|
|
218
|
-
* @description This is my enum description.
|
|
219
|
-
*/
|
|
220
|
-
public Enum ExampleEnum {
|
|
221
|
-
VALUE_1, VALUE_2
|
|
222
|
-
}
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Documenting Properties
|
|
226
|
-
|
|
227
|
-
The following tags are supported on the property level:
|
|
228
|
-
|
|
229
|
-
| Tag | Description |
|
|
230
|
-
|----------------|--------------------------------------------|
|
|
231
|
-
| `@description` | One or more lines describing the property. |
|
|
232
|
-
|
|
233
|
-
**Example**
|
|
234
|
-
|
|
235
|
-
```apex
|
|
236
|
-
/**
|
|
237
|
-
* @description This is my property description.
|
|
238
|
-
*/
|
|
239
|
-
public String ExampleProperty { get; set; }
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
### Documenting Methods and Constructors
|
|
243
|
-
|
|
244
|
-
Methods and constructors support the same tags.
|
|
245
|
-
|
|
246
|
-
The following tags are supported on the method level:
|
|
247
|
-
|
|
248
|
-
| Tag | Description |
|
|
249
|
-
|------------------------------|---------------------------------------------------|
|
|
250
|
-
| `@description` | One or more lines describing the method. |
|
|
251
|
-
| `@param` _paramName_ | Description of a single parameter. |
|
|
252
|
-
| `@return` | Description of the return value of the method. |
|
|
253
|
-
| `@example` | Example of how the code can be used or called. |
|
|
254
|
-
| `@throws` _ExceptionName_ | Description of an exception thrown by the method. |
|
|
255
|
-
| `@exception` _ExceptionName_ | Same as `@throws`. V2 only |
|
|
256
|
-
|
|
257
|
-
**Example**
|
|
258
|
-
|
|
259
|
-
```apex
|
|
260
|
-
/**
|
|
261
|
-
* @description This is my method description.
|
|
262
|
-
* @param action The action to execute.
|
|
263
|
-
* @return The result of the operation.
|
|
264
|
-
* @example
|
|
265
|
-
* Object result = SampleClass.call('exampleAction');
|
|
266
|
-
*/
|
|
267
|
-
public static Object call(String action) {
|
|
268
|
-
}
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### Grouping Declarations Within A Class
|
|
272
|
-
|
|
273
|
-
A class might have members that should be grouped together. For example, you can have a class for constants with
|
|
274
|
-
groups of constants that should be grouped together because they share a common behavior (e.g. different groups
|
|
275
|
-
of constants representing the possible values for different picklists.)
|
|
276
|
-
|
|
277
|
-
You can group things together within a class by using the following syntax:
|
|
278
|
-
|
|
279
|
-
```apex
|
|
280
|
-
// @start-group Group Name or Description
|
|
281
|
-
public static final String CONSTANT_FOO = 'Foo';
|
|
282
|
-
public static final String CONSTANT_BAR = 'Bar';
|
|
283
|
-
// @end-group
|
|
284
|
-
```
|
|
285
|
-
|
|
286
|
-
Groups of members are displayed together under their own subsection after its name or description.
|
|
287
|
-
|
|
288
|
-
Some notes about grouping:
|
|
289
|
-
|
|
290
|
-
* This is only supported on classes, NOT enums and interfaces
|
|
291
|
-
* Supports
|
|
292
|
-
* Properties
|
|
293
|
-
* Fields (variables and constants)
|
|
294
|
-
* Constructors
|
|
295
|
-
* Methods
|
|
296
|
-
* BUT only members of the same type are grouped together. For example,
|
|
297
|
-
if you have a group that contains properties and methods the properties will be grouped together under Properties ->
|
|
298
|
-
Group Name, and the methods will be grouped together under Methods -> Group Name
|
|
299
|
-
* Does not support inner types (inner classes, interfaces, and enums)
|
|
300
|
-
* It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for
|
|
301
|
-
that file.
|
|
302
|
-
|
|
303
|
-
### Inline linking
|
|
304
|
-
|
|
305
|
-
Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that
|
|
306
|
-
class file for easy navigation.
|
|
307
|
-
|
|
308
|
-
Apexdocs recognizes 2 different syntax when linking files:
|
|
309
|
-
|
|
310
|
-
- Javadoc's `{@link FileName}` syntax
|
|
311
|
-
- A class name wrapped in between `<<` `>>`.
|
|
312
|
-
|
|
313
|
-
**Example**
|
|
314
|
-
|
|
315
|
-
```apex
|
|
316
|
-
/**
|
|
317
|
-
* @description This is my method description. This method receives an <<ExampleClass>>.
|
|
318
|
-
* @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
|
|
319
|
-
* @return The result of the operation.
|
|
320
|
-
*/
|
|
321
|
-
public static Object doSomething(ExampleClass param1) {}
|
|
322
|
-
```
|
|
323
|
-
|
|
324
|
-
---
|
|
325
|
-
|
|
326
|
-
Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
|
|
327
|
-
|
|
328
|
-
### HTML support
|
|
329
|
-
|
|
330
|
-
For the most part all HTML is sanitized when the `--sanitizeHtml` flag is passed a true value (which is the default).
|
|
331
|
-
But there are some tags are allowed to have for the possibility of better
|
|
332
|
-
styling long text.
|
|
333
|
-
|
|
334
|
-
- Allowed tags are: `br`, `p`, `ul`, `li`, and `code`
|
|
335
|
-
|
|
336
|
-
Example
|
|
337
|
-
|
|
338
|
-
```apex
|
|
339
|
-
/**
|
|
340
|
-
* @description <p>This is a paragraph</p>
|
|
341
|
-
* <p>And this is another paragraph</p>
|
|
342
|
-
* <ul>
|
|
343
|
-
* <li>This is a list item</li>
|
|
344
|
-
* <li>This is another list item</li>
|
|
345
|
-
* </ul>
|
|
346
|
-
*/
|
|
347
|
-
class MyClass {
|
|
348
|
-
}
|
|
349
|
-
```
|
|
350
|
-
|
|
351
|
-
⚠️When the `--sanitizeHtml` flag is ON, any special character between code blocks (i.e. \```, \`, or `<code>`) will also
|
|
352
|
-
be escaped.
|
|
353
|
-
So if you have references to Apex generic collections (Set, List, or Maps) they will not look right, as the < and >
|
|
354
|
-
symbols will be escaped.
|
|
355
|
-
To prevent this you can turn the flag off, but be aware of the special considerations when doing this described below.
|
|
356
|
-
|
|
357
|
-
---
|
|
358
|
-
|
|
359
|
-
For full control over the output you can also turn off the `--sanitizeHtml` flag, which will allow you
|
|
360
|
-
to have any desired HTML within your docs.
|
|
361
|
-
|
|
362
|
-
⚠️When the `--sanitizeHtml` flag is OFF, references to Apex generic collections (Set, List or Maps) can be problematic
|
|
363
|
-
as they will be treated as an HTML tag and not displayed. For example if you have something
|
|
364
|
-
like `@description Returns a List<String>`
|
|
365
|
-
the `<String>` portion will be treated as HTML and thus not appear on the page.
|
|
366
|
-
|
|
367
|
-
To fix this issue, when not sanitizing HTML, you should wrap any code that contain special characters that can be
|
|
368
|
-
treated as HTML within '\`'
|
|
369
|
-
or within `<code>` tags.
|
|
370
|
-
|
|
371
|
-
### Displaying diagrams
|
|
372
|
-
|
|
373
|
-
You can display diagrams in your documentation by leveraging Github's built-in [Mermaid](https://mermaid-js.github.io/mermaid/#/) support.
|
|
374
|
-
|
|
375
|
-
If you are using a markdown generator that supports Mermaid (e.g. [Github's markdown](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/),
|
|
376
|
-
you can add diagrams to your documentation by using the
|
|
377
|
-
`@mermaid` tag.
|
|
378
|
-
|
|
379
|
-
**Example**
|
|
380
|
-
|
|
381
|
-
```apex
|
|
382
|
-
/**
|
|
383
|
-
* @mermaid
|
|
384
|
-
* graph TD
|
|
385
|
-
* A[Christmas] -->|Get money| B(Go shopping)
|
|
386
|
-
* B --> C{Let me think}
|
|
387
|
-
* C -->|One| D[Laptop]
|
|
388
|
-
* C -->|Two| E[iPhone]
|
|
389
|
-
* C -->|Three| F[Car]
|
|
390
|
-
*/
|
|
391
|
-
public class MyClass {
|
|
392
|
-
}
|
|
393
|
-
```
|
|
394
|
-
|
|
395
|
-
[Here's an example of how that looks](/docs/types/Classes/nspc.AnotherInterface.md)
|
|
396
|
-
|
|
397
|
-
### Ignoring files and members
|
|
398
|
-
|
|
399
|
-
You can ignore files and members by using the `@ignore` tag on any ApexDoc block. If used at the class level, the entire
|
|
400
|
-
file will be ignored. If used at the member level, only that member will be ignored.
|
|
401
|
-
|
|
402
|
-
Example
|
|
403
|
-
|
|
404
|
-
```apex
|
|
405
|
-
/**
|
|
406
|
-
* @ignore
|
|
407
|
-
*/
|
|
408
|
-
public class MyClass {
|
|
409
|
-
public static void myMethod() {}
|
|
410
|
-
}
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
## Generating OpenApi REST Definitions
|
|
414
|
-
|
|
415
|
-
ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
|
|
416
|
-
|
|
417
|
-
### Usage
|
|
418
|
-
|
|
419
|
-
To create an OpenApi specification file, run the `apexdocs-generate` and pass `openapi` to the `--targetGenerator` parameter.
|
|
420
|
-
When using this generator, you can also pass a custom title through the `--openApiTitle` parameter. This title will be placed
|
|
421
|
-
in the output file's `info.title` property, as defined by the [OpenApi documentation for the Info Object](https://spec.openapis.org/oas/v3.1.0#info-object)
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
```shell
|
|
425
|
-
apexdocs-generate -s ./src -t docs -g openapi --openApiTitle "Custom OpenApi Title"
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
### How It Works
|
|
429
|
-
|
|
430
|
-
When generating an OpenApi document, since `@RestResource` classes need to be global in Apex, the `--scope` parameter will be ignored.
|
|
431
|
-
Instead, ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
|
|
432
|
-
|
|
433
|
-
Once it finishes running, a file named `openapi.json` will be created in the specified `--targetDir`.
|
|
434
|
-
|
|
435
|
-
### Configuring What Gets Created
|
|
436
|
-
|
|
437
|
-
ApexDocs will automatically parse your source code and generate the OpenApi definition based on the HTTP related Apex
|
|
438
|
-
annotations (RestResource, HttpDelete, HttpGet, HttpPatch, HttpPost, HttpGet). The different HTTP annotations will be used to generate a file that complies with the [OpenApi Specification v3.1.0](https://spec.openapis.org/oas/v3.1.0)
|
|
439
|
-
|
|
440
|
-
Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs, relying on
|
|
441
|
-
some custom annotations that are specific to generating OpenApi definitions:
|
|
442
|
-
|
|
443
|
-
* `@http-request-body`
|
|
444
|
-
* `@http-parameter`
|
|
445
|
-
* `@http-response`
|
|
446
|
-
|
|
447
|
-
#### @http-request-body
|
|
448
|
-
|
|
449
|
-
Allows you to specify the HTTP request's expected request body. It supports receiving a `description`,
|
|
450
|
-
whether it is `required` or not, and a `schema`, which defines the shape of the object that is expected.
|
|
451
|
-
|
|
452
|
-
📝 Note that only one `@http-request-body` should be defined per method. If you add more than one, only
|
|
453
|
-
a single one will be used when generating the OpenApi definition.
|
|
454
|
-
|
|
455
|
-
The `schema` can either be a reference to another class in your source code (see the `Class References` section below)
|
|
456
|
-
or a fully defined custom schema (See the `Custom Schemas` section below).
|
|
457
|
-
|
|
458
|
-
Example
|
|
459
|
-
```apex
|
|
460
|
-
/**
|
|
461
|
-
* @description This is a sample HTTP Post method
|
|
462
|
-
* @http-request-body
|
|
463
|
-
* description: This is an example of a request body
|
|
464
|
-
* required: true
|
|
465
|
-
* schema: ClassName
|
|
466
|
-
*/
|
|
467
|
-
@HttpPost
|
|
468
|
-
global static void doPost() {
|
|
469
|
-
///...
|
|
470
|
-
}
|
|
471
|
-
```
|
|
472
|
-
|
|
473
|
-
📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
|
|
474
|
-
so spacing is important.
|
|
475
|
-
|
|
476
|
-
#### @http-parameter
|
|
477
|
-
|
|
478
|
-
Allows you to specify any HTTP parameter expected by your method. It supports receiving a `name`,
|
|
479
|
-
an `in` as defined by the supported [Parameter Locations](https://spec.openapis.org/oas/v3.1.0#parameter-locations),
|
|
480
|
-
whether it is `required` or not, a `description`, and a `schema`.
|
|
481
|
-
|
|
482
|
-
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
483
|
-
|
|
484
|
-
Example
|
|
485
|
-
```apex
|
|
486
|
-
/**
|
|
487
|
-
* @description This is a sample HTTP Post method
|
|
488
|
-
* @return A String SObject.
|
|
489
|
-
* @http-parameter
|
|
490
|
-
* name: limit
|
|
491
|
-
* in: query
|
|
492
|
-
* required: true
|
|
493
|
-
* description: Limits the number of items on a page
|
|
494
|
-
* schema:
|
|
495
|
-
* type: integer
|
|
496
|
-
* @http-parameter
|
|
497
|
-
* name: complex
|
|
498
|
-
* in: cookie
|
|
499
|
-
* schema: MyClassName
|
|
500
|
-
*/
|
|
501
|
-
@HttpPost
|
|
502
|
-
global static String doPost() {
|
|
503
|
-
// ..
|
|
504
|
-
}
|
|
505
|
-
```
|
|
506
|
-
|
|
507
|
-
📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
|
|
508
|
-
so spacing is important.
|
|
509
|
-
|
|
510
|
-
#### @http-response
|
|
511
|
-
|
|
512
|
-
Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response code,
|
|
513
|
-
a `description`, and a `schema`.
|
|
514
|
-
|
|
515
|
-
If no `description` is provided then one will be automatically built using the `statusCode`.
|
|
516
|
-
|
|
517
|
-
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
518
|
-
|
|
519
|
-
```apex
|
|
520
|
-
/**
|
|
521
|
-
* @description This is a sample HTTP Post method
|
|
522
|
-
* @return A String SObject.
|
|
523
|
-
* @http-response
|
|
524
|
-
* statusCode: 200
|
|
525
|
-
* schema: SuccessfulResponseClassName
|
|
526
|
-
* @http-response
|
|
527
|
-
* statusCode: 500
|
|
528
|
-
* description: Status Code 500 - An internal server error occurred.
|
|
529
|
-
* schema:
|
|
530
|
-
* type: string
|
|
531
|
-
*/
|
|
532
|
-
@HttpPost
|
|
533
|
-
global static String doPost() {
|
|
534
|
-
// ...
|
|
535
|
-
}
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
#### Class References
|
|
539
|
-
|
|
540
|
-
Whenever specifying a `schema` parameter, you can pass as a string the name of any class in your source code. This
|
|
541
|
-
class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi definition.
|
|
542
|
-
|
|
543
|
-
The tool will parse the class and create a reference that complies with [Apex's support for User-Defined Types](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm#ApexRESTUserDefinedTypes)
|
|
544
|
-
|
|
545
|
-
##### Reference Overrides
|
|
546
|
-
|
|
547
|
-
When dealing with references, there might be cases when you want to manually tell the parser what type of object a property
|
|
548
|
-
or field is. For example, let's say we have a class that looks as follows
|
|
549
|
-
|
|
550
|
-
```apex
|
|
551
|
-
public class MyClass {
|
|
552
|
-
public Object myObject;
|
|
553
|
-
public Account myAccountRecord;
|
|
554
|
-
}
|
|
555
|
-
```
|
|
556
|
-
|
|
557
|
-
In this case `myObject` has a type of `Object`, and `myAccountRecord` is an SObject. Neither of these will be accurately
|
|
558
|
-
parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any properties.
|
|
559
|
-
|
|
560
|
-
To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override its
|
|
561
|
-
type during parsing. In this annotation you can specify the same thing you would in any `schema` property when dealing with any
|
|
562
|
-
of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
|
|
563
|
-
|
|
564
|
-
```apex
|
|
565
|
-
public class MyClass {
|
|
566
|
-
/**
|
|
567
|
-
* @description This is a generic reference to another class
|
|
568
|
-
* @http-schema MyOtherClassName
|
|
569
|
-
*/
|
|
570
|
-
public Object myObject;
|
|
571
|
-
|
|
572
|
-
/**
|
|
573
|
-
* @description This is a reference to an Account SObject
|
|
574
|
-
* @http-schema
|
|
575
|
-
* type: object
|
|
576
|
-
* properties:
|
|
577
|
-
* Id:
|
|
578
|
-
* type: string
|
|
579
|
-
* Name:
|
|
580
|
-
* type: string
|
|
581
|
-
* CustomField__c:
|
|
582
|
-
* type: number
|
|
583
|
-
*/
|
|
584
|
-
public Account myAccountRecord;
|
|
585
|
-
}
|
|
586
|
-
```
|
|
587
|
-
|
|
588
|
-
---
|
|
589
|
-
|
|
590
|
-
If dealing with a collection, you can also specify the name of the reference either using the `List` or `Set` syntax.
|
|
591
|
-
|
|
592
|
-
📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
|
|
593
|
-
deep are supported (e.g. List<List<String>> is not supported). This is only a limitation when referencing collections
|
|
594
|
-
on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a referenced
|
|
595
|
-
class as part of your codebase.
|
|
596
|
-
|
|
597
|
-
Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
|
|
598
|
-
to convert that to a valid specification. For this use case, define a Custom Schema as explained below.
|
|
599
|
-
|
|
600
|
-
```apex
|
|
601
|
-
/**
|
|
602
|
-
* @description This is a sample HTTP Post method
|
|
603
|
-
* @http-request-body
|
|
604
|
-
* description: This is an example of a request body
|
|
605
|
-
* schema: List<ClassName>
|
|
606
|
-
*/
|
|
607
|
-
@HttpPost
|
|
608
|
-
global static void doPost() {
|
|
609
|
-
///...
|
|
610
|
-
}
|
|
611
|
-
```
|
|
612
|
-
|
|
613
|
-
Inner class references are also supported, but note that you need to pass the full name of the reference,
|
|
614
|
-
by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP method
|
|
615
|
-
referencing it.
|
|
616
|
-
|
|
617
|
-
```apex
|
|
618
|
-
/**
|
|
619
|
-
* @description This is a sample HTTP Post method
|
|
620
|
-
* @http-request-body
|
|
621
|
-
* description: This is an example of a request body
|
|
622
|
-
* schema: ParentClass.InnerClass
|
|
623
|
-
*/
|
|
624
|
-
@HttpPost
|
|
625
|
-
global static void doPost() {
|
|
626
|
-
///...
|
|
627
|
-
}
|
|
628
|
-
```
|
|
629
|
-
|
|
630
|
-
#### Custom Schemas
|
|
631
|
-
|
|
632
|
-
For any `schema` parameter in any of the HTTP ApexDocs annotations, besides specifying the name of a class, you
|
|
633
|
-
can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an `array`
|
|
634
|
-
|
|
635
|
-
**Primitives**
|
|
636
|
-
|
|
637
|
-
For primitives, you should specify the `type` and an optional `format`, as defined by the [OpenApi Specification on Data Types](https://spec.openapis.org/oas/v3.1.0#data-types)
|
|
638
|
-
|
|
639
|
-
```apex
|
|
640
|
-
/**
|
|
641
|
-
* ...
|
|
642
|
-
* schema:
|
|
643
|
-
* type: string
|
|
644
|
-
* format: password
|
|
645
|
-
*/
|
|
646
|
-
```
|
|
647
|
-
|
|
648
|
-
**Objects**
|
|
649
|
-
|
|
650
|
-
To specify a custom object schema, use `object` as the `type`, and specify as many properties as follows:
|
|
651
|
-
|
|
652
|
-
```apex
|
|
653
|
-
/**
|
|
654
|
-
* schema:
|
|
655
|
-
* type: object
|
|
656
|
-
* properties:
|
|
657
|
-
* id:
|
|
658
|
-
* type: string
|
|
659
|
-
* description: The super Id.
|
|
660
|
-
* name:
|
|
661
|
-
* type: string
|
|
662
|
-
* phone:
|
|
663
|
-
* type: string
|
|
664
|
-
* format: byte
|
|
665
|
-
*/
|
|
666
|
-
```
|
|
667
|
-
|
|
668
|
-
Properties can be defined as primitives (as explained above), other objects, or arrays (explained below)
|
|
669
|
-
|
|
670
|
-
**Arrays**
|
|
671
|
-
|
|
672
|
-
To specify a custom array schema, use `array` as the `type`, and provide an `items` definition. In `items`
|
|
673
|
-
you can specify the definition of any other custom type (primitives, objects, or other arrays).
|
|
674
|
-
|
|
675
|
-
```apex
|
|
676
|
-
/**
|
|
677
|
-
* schema:
|
|
678
|
-
* type: array
|
|
679
|
-
* items:
|
|
680
|
-
* type: object
|
|
681
|
-
* properties:
|
|
682
|
-
* name:
|
|
683
|
-
* type: string
|
|
684
|
-
*/
|
|
685
|
-
```
|
|
686
|
-
|
|
687
|
-
#### SObject References
|
|
688
|
-
|
|
689
|
-
ApexDocs is not able to automatically parse SObject references, as it can with class references, as it does
|
|
690
|
-
not reach into your org to get existing SObject describes. Because of this, when dealing with SObject references
|
|
691
|
-
you should create a Custom Schema as defined above. This will also allow you to specify which specific
|
|
692
|
-
fields are being received or returned.
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
### Considerations
|
|
696
|
-
|
|
697
|
-
Please be aware of the following when using ApexDocs to create an OpenApi definition:
|
|
698
|
-
|
|
699
|
-
* Map references are resolved as `object` with no properties, as it is not possible to know which keys the map will contain.
|
|
700
|
-
When using maps either create a class that better represents the shape of the object and use a Class Reference, or
|
|
701
|
-
define a Custom Schema in the `schema` section of the ApexDoc itself.
|
|
702
|
-
* Same thing when referencing SObjects, as SObject describe parsing is not supported by the ApexDocs tool. When referencing
|
|
703
|
-
SObjects, consider defining a Custom Schema in the `schema` section of the ApexDoc.
|
|
704
|
-
* ApexDoc is only able to parse through your source code, so references to other packages (namespaced classes) or any
|
|
705
|
-
code that lives outside your source code is not supported. Consider creating a Custom Schema for those situations.
|
|
706
|
-
* The return value and received parameters or your methods are currently not being considered when creating the OpenApi definition file.
|
|
707
|
-
Instead, use the `@http-response` ApexDoc annotation to specify the return value, and `@http-parameter` to specify any
|
|
708
|
-
expected parameter.
|
|
709
|
-
|
|
710
|
-
## Typescript
|
|
711
|
-
|
|
712
|
-
ApexDocs provides all necessary type definitions.
|
|
713
|
-
|
|
714
|
-
---
|
|
715
|
-
|
|
716
|
-
## 1.X
|
|
717
|
-
|
|
718
|
-
Looking for documentation for version 1.X? Please refer to its [branch](https://github.com/cesarParra/apexdocs/tree/1.x)
|
|
1
|
+
# ApexDocs
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<b>ApexDocs is a Node.js library with CLI capabilities to docGenerator documentation for Salesforce Apex classes.</b>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
[](https://github.com/cesarParra/apexdocs/blob/master/LICENSE)
|
|
8
|
+
|
|
9
|
+
## Description
|
|
10
|
+
|
|
11
|
+
ApexDocs was originally built as an alternative to
|
|
12
|
+
the [Java based ApexDoc tool](https://github.com/SalesforceFoundation/ApexDoc) originally created by Aslam Bari and
|
|
13
|
+
later maintained by Salesforce.org, as that tool is no longer being maintained.
|
|
14
|
+
|
|
15
|
+
ApexDocs is a Node.js library built on Typescript and hosted on [npm](https://www.npmjs.com/package/@cparra/apexdocs).
|
|
16
|
+
It offers CLI capabilities to automatically document your source code, based on the ApexDoc style of documentation.
|
|
17
|
+
Additionally, it can be imported and consumed directly by your JavaScript code.
|
|
18
|
+
|
|
19
|
+
There are some key differences between ApexDocs and the Java based ApexDoc tool:
|
|
20
|
+
|
|
21
|
+
- **Recursive file search through your module directory structure**. In an `sfdx` based project, all of your classes
|
|
22
|
+
will be documented by specifying the top-most directory where file search should begin.
|
|
23
|
+
- **Unopinionated documentation site generation**. Instead of creating HTML files, ApexDocs generates a Markdown (.md)
|
|
24
|
+
file per Apex class being documented. This means you can host your files in static web hosting services that parse
|
|
25
|
+
Markdown like Github Pages or Netlify, and use site generators like Jekyll or Gatsby. This gives you the freedom to
|
|
26
|
+
decide how to style your site to match your needs.
|
|
27
|
+
|
|
28
|
+
#### Features
|
|
29
|
+
|
|
30
|
+
* Custom Annotations
|
|
31
|
+
|
|
32
|
+
Any custom annotation defined in the Apexdoc is at the class level are supported, for example the following will be
|
|
33
|
+
output to the resulting markdown file:
|
|
34
|
+
|
|
35
|
+
```apex
|
|
36
|
+
/**
|
|
37
|
+
* @MyCustomAnnotation This is a custom annotation
|
|
38
|
+
*/
|
|
39
|
+
public class MyClass {
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
* Single Line ApexDoc Blocks
|
|
44
|
+
|
|
45
|
+
📒 Note: If you wish to have multiple `@` tags in a single line but don't want them to be treated as ApexDoc annotations, you can
|
|
46
|
+
escape them by adding wrapping the annotation in ticks, for example
|
|
47
|
+
|
|
48
|
+
```apex
|
|
49
|
+
/**
|
|
50
|
+
* @MyCustomAnnotation This is a custom annotation with an `@embedded` annotation
|
|
51
|
+
*/
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
* Support for grouping blocks of related code within a class
|
|
55
|
+
* Support for HTML tags
|
|
56
|
+
* OpenApi REST specification generation
|
|
57
|
+
* Support for ignoring files and members from being documented
|
|
58
|
+
* Namespace support
|
|
59
|
+
* Configuration file support
|
|
60
|
+
* And much, much more!
|
|
61
|
+
|
|
62
|
+
### Demo
|
|
63
|
+
|
|
64
|
+
ApexDocs currently supports generating markdown files for Jekyll and Docsify sites, as well as generating plain markdown
|
|
65
|
+
files.
|
|
66
|
+
|
|
67
|
+
### In the wild
|
|
68
|
+
|
|
69
|
+
- [Expression](https://cesarparra.github.io/expression/)
|
|
70
|
+
- [Nimble AMS Docs](https://nimbleuser.github.io/nams-api-docs/#/api-reference/)
|
|
71
|
+
- [Yet Another Salesforce Logger](https://cesarparra.github.io/yet-another-salesforce-logger/#/)
|
|
72
|
+
|
|
73
|
+
### [Docsify](https://docsify.js.org/)
|
|
74
|
+
|
|
75
|
+
Demo
|
|
76
|
+
|
|
77
|
+
- [Docsify](https://cesarparra.github.io/apexdocs/)
|
|
78
|
+
|
|
79
|
+
### [Jekyll](https://jekyllrb.com/)
|
|
80
|
+
|
|
81
|
+
Demo
|
|
82
|
+
|
|
83
|
+
- [Jekyll](https://cesarparra.github.io/apexdocs-docsify-example/)
|
|
84
|
+
|
|
85
|
+
## Installation
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm i -g @cparra/apexdocs
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Usage
|
|
92
|
+
|
|
93
|
+
### CLI
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
apexdocs-generate
|
|
97
|
+
-s src
|
|
98
|
+
-t docs
|
|
99
|
+
-p global
|
|
100
|
+
-g docsify
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
The CLI supports the following parameters:
|
|
104
|
+
|
|
105
|
+
| Parameter | Alias | Description | Default | Required |
|
|
106
|
+
|-----------------------------|-------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|
|
|
107
|
+
| --sourceDir | -s | The directory location which contains your apex .cls classes. | N/A | Yes |
|
|
108
|
+
| --targetDir | -t | The directory location where documentation will be generated to. | `docs` | No |
|
|
109
|
+
| --recursive | -r | Whether .cls classes will be searched for recursively in the directory provided. | `true` | No |
|
|
110
|
+
| --scope | -p | A list of scopes to document. Values should be separated by a space, e.g --scope public private. Note that this setting is ignored if generating an OpenApi REST specification since that looks for classes annotated with @RestResource. | `global` | No |
|
|
111
|
+
| --targetGenerator | -g | Define the static file generator for which the documents will be created. Currently supports: `jekyll`, `docsify`, `plain-markdown`, and `openapi`. | `jekyll` | No |
|
|
112
|
+
| --indexOnly | N/A | Defines whether only the index file should be generated. | `false` | No |
|
|
113
|
+
| --defaultGroupName | N/A | Defines the `@group` name to be used when a file does not specify it. | `Miscellaneous` | No |
|
|
114
|
+
| --sanitizeHtml | N/A | When on, any special character within your ApexDocs is converted into its HTML code representation. This is specially useful when generic objects are described within the docs, e.g. "List< Foo>", "Map<Foo, Bar>" because otherwise the content within < and > would be treated as HTML tags and not shown in the output. Content in @example blocks are never sanitized. | true | No |
|
|
115
|
+
| --openApiTitle | N/A | If using "openapi" as the target generator, this allows you to specify the OpenApi title value. | `Apex REST Api` | No |
|
|
116
|
+
| --title | N/A | Allows you to specify the home page main title. If using "openapi" this acts as an alias to the openApiTitle parameter | `Classes` | No |
|
|
117
|
+
| --namespace | N/A | The package namespace, if any. If this value is provided the namespace will be added as a prefix to all of the parsed files. If generating an OpenApi definition, it will be added to the file's Server Url. | N/A | No |
|
|
118
|
+
| --openApiFileName | N/A | If using "openapi" as the target generator, this allows you to specify the name of the output file. | `openapi` | No |
|
|
119
|
+
| --sortMembersAlphabetically | N/A | Whether to sort the members of a class alphabetically. | `false` | No |
|
|
120
|
+
| --includeMetadata | N/A | Whether to include the file's meta.xml information: Whether it is active and and the API version | false | No |
|
|
121
|
+
| --documentationRootDir | N/A | The root directory where the documentation will be generated. This is useful when you want to generate the documentation in a subdirectory of your project. | N/A | No |
|
|
122
|
+
|
|
123
|
+
### Using a configuration file
|
|
124
|
+
|
|
125
|
+
You can also use a configuration file to define the parameters that will be used when generating the documentation. Apexdocs
|
|
126
|
+
uses [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) to load the configuration file, which means it supports
|
|
127
|
+
the following formats:
|
|
128
|
+
|
|
129
|
+
- A `package.json` property, e.g. `{ "apexdocs": { "sourceDir": "src", "targetDir": "docs" } }`
|
|
130
|
+
- A `.apexdocsrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`
|
|
131
|
+
- An `apexdocs.config.js` file that exports an object
|
|
132
|
+
- A `apexdocs.config.ts` file that exports an object
|
|
133
|
+
|
|
134
|
+
The configuration file should be placed in the root directory of your project.
|
|
135
|
+
|
|
136
|
+
**Note that when using a configuration file, you can still override any of the parameters by passing them through the CLI.**
|
|
137
|
+
|
|
138
|
+
When defining a `.js` or `.ts` configuration file, your object export can also contain the following functions that will
|
|
139
|
+
allow you to override some of the default behavior:
|
|
140
|
+
|
|
141
|
+
- `onBeforeFileWrite` - A function that will be called before a file is written to disk. It receives a `TargetFile` object
|
|
142
|
+
that contains the file's content, path, and name, etc. It should return a `TargetFile` object with the updated content.
|
|
143
|
+
The full object definition can be imported from `@cparra/apexdocs/lib/settings`
|
|
144
|
+
- `onAfterProcess` - A function that will be called after all files have been processed. It receives a `TargetFile[]` array
|
|
145
|
+
with all of the files that were processed and does not return anything.
|
|
146
|
+
- `frontMatterHeader` - A function that will be called before the front matter is written to the file (when using the Jekyll generator).
|
|
147
|
+
It receives a `TargetType` object
|
|
148
|
+
and should return a list of strings that will be written to the file as the front matter.
|
|
149
|
+
The full object definition can be imported from `@cparra/apexdocs/lib/settings`
|
|
150
|
+
and contains the following properties:
|
|
151
|
+
- `name` - The name of the type
|
|
152
|
+
- `typeName` - Can be 'class', 'interface', or 'enum'
|
|
153
|
+
- `accessModifier` - The access modifier of the type
|
|
154
|
+
- `group` - The group to which the type belongs (if any)
|
|
155
|
+
- `description` - The description of the type as defined in the ApexDoc
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
import {TargetFile} from "@cparra/apexdocs/lib/settings";
|
|
159
|
+
export default {
|
|
160
|
+
onBeforeFileWrite: (file: TargetFile): TargetFile => {
|
|
161
|
+
console.log('onBefore writing', file);
|
|
162
|
+
return file;
|
|
163
|
+
},
|
|
164
|
+
onAfterProcess: (files: TargetFile[]) => {
|
|
165
|
+
console.log('onAfterProcess files', files);
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Importing to your project
|
|
172
|
+
|
|
173
|
+
If you are just interested in the Apex parsing capabilities, you can use the
|
|
174
|
+
standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
|
|
175
|
+
which is what gets used by this library behind the scenes to generate the documentation files.
|
|
176
|
+
|
|
177
|
+
## Documentation Format
|
|
178
|
+
|
|
179
|
+
ApexDocs picks up blocks of comments throughout your `.cls` files. The block must begin with `/**` and end with `*/`.
|
|
180
|
+
|
|
181
|
+
### Documenting Classes
|
|
182
|
+
|
|
183
|
+
The following tags are supported on the class level:
|
|
184
|
+
|
|
185
|
+
**Note** Any custom generated tag is also supported. Custom tags can be added with at symbol (`@`) followed by the name
|
|
186
|
+
of the tag. For example `@custom-tag`
|
|
187
|
+
|
|
188
|
+
| Tag | Description |
|
|
189
|
+
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
190
|
+
| `@description` | One or more lines describing the class. |
|
|
191
|
+
| `@see` | The name of a related class. |
|
|
192
|
+
| `@group` | The group to which the class belongs to. |
|
|
193
|
+
| `@author` | The author of the class. Note that this only gets added if it is explicitly defined through the configuration class that it should. |
|
|
194
|
+
| `@date` | The date the class was created. Note that this only gets added if it is explicitly defined through the configuration class that it should. |
|
|
195
|
+
|
|
196
|
+
**Example**
|
|
197
|
+
|
|
198
|
+
```apex
|
|
199
|
+
/**
|
|
200
|
+
* @description This is my class description.
|
|
201
|
+
*/
|
|
202
|
+
public with sharing class TestClass {
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Documenting Enums
|
|
207
|
+
|
|
208
|
+
The following tags are supported on the enum level:
|
|
209
|
+
|
|
210
|
+
| Tag | Description |
|
|
211
|
+
|----------------|----------------------------------------|
|
|
212
|
+
| `@description` | One or more lines describing the enum. |
|
|
213
|
+
|
|
214
|
+
**Example**
|
|
215
|
+
|
|
216
|
+
```apex
|
|
217
|
+
/**
|
|
218
|
+
* @description This is my enum description.
|
|
219
|
+
*/
|
|
220
|
+
public Enum ExampleEnum {
|
|
221
|
+
VALUE_1, VALUE_2
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Documenting Properties
|
|
226
|
+
|
|
227
|
+
The following tags are supported on the property level:
|
|
228
|
+
|
|
229
|
+
| Tag | Description |
|
|
230
|
+
|----------------|--------------------------------------------|
|
|
231
|
+
| `@description` | One or more lines describing the property. |
|
|
232
|
+
|
|
233
|
+
**Example**
|
|
234
|
+
|
|
235
|
+
```apex
|
|
236
|
+
/**
|
|
237
|
+
* @description This is my property description.
|
|
238
|
+
*/
|
|
239
|
+
public String ExampleProperty { get; set; }
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Documenting Methods and Constructors
|
|
243
|
+
|
|
244
|
+
Methods and constructors support the same tags.
|
|
245
|
+
|
|
246
|
+
The following tags are supported on the method level:
|
|
247
|
+
|
|
248
|
+
| Tag | Description |
|
|
249
|
+
|------------------------------|---------------------------------------------------|
|
|
250
|
+
| `@description` | One or more lines describing the method. |
|
|
251
|
+
| `@param` _paramName_ | Description of a single parameter. |
|
|
252
|
+
| `@return` | Description of the return value of the method. |
|
|
253
|
+
| `@example` | Example of how the code can be used or called. |
|
|
254
|
+
| `@throws` _ExceptionName_ | Description of an exception thrown by the method. |
|
|
255
|
+
| `@exception` _ExceptionName_ | Same as `@throws`. V2 only |
|
|
256
|
+
|
|
257
|
+
**Example**
|
|
258
|
+
|
|
259
|
+
```apex
|
|
260
|
+
/**
|
|
261
|
+
* @description This is my method description.
|
|
262
|
+
* @param action The action to execute.
|
|
263
|
+
* @return The result of the operation.
|
|
264
|
+
* @example
|
|
265
|
+
* Object result = SampleClass.call('exampleAction');
|
|
266
|
+
*/
|
|
267
|
+
public static Object call(String action) {
|
|
268
|
+
}
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
### Grouping Declarations Within A Class
|
|
272
|
+
|
|
273
|
+
A class might have members that should be grouped together. For example, you can have a class for constants with
|
|
274
|
+
groups of constants that should be grouped together because they share a common behavior (e.g. different groups
|
|
275
|
+
of constants representing the possible values for different picklists.)
|
|
276
|
+
|
|
277
|
+
You can group things together within a class by using the following syntax:
|
|
278
|
+
|
|
279
|
+
```apex
|
|
280
|
+
// @start-group Group Name or Description
|
|
281
|
+
public static final String CONSTANT_FOO = 'Foo';
|
|
282
|
+
public static final String CONSTANT_BAR = 'Bar';
|
|
283
|
+
// @end-group
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Groups of members are displayed together under their own subsection after its name or description.
|
|
287
|
+
|
|
288
|
+
Some notes about grouping:
|
|
289
|
+
|
|
290
|
+
* This is only supported on classes, NOT enums and interfaces
|
|
291
|
+
* Supports
|
|
292
|
+
* Properties
|
|
293
|
+
* Fields (variables and constants)
|
|
294
|
+
* Constructors
|
|
295
|
+
* Methods
|
|
296
|
+
* BUT only members of the same type are grouped together. For example,
|
|
297
|
+
if you have a group that contains properties and methods the properties will be grouped together under Properties ->
|
|
298
|
+
Group Name, and the methods will be grouped together under Methods -> Group Name
|
|
299
|
+
* Does not support inner types (inner classes, interfaces, and enums)
|
|
300
|
+
* It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for
|
|
301
|
+
that file.
|
|
302
|
+
|
|
303
|
+
### Inline linking
|
|
304
|
+
|
|
305
|
+
Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that
|
|
306
|
+
class file for easy navigation.
|
|
307
|
+
|
|
308
|
+
Apexdocs recognizes 2 different syntax when linking files:
|
|
309
|
+
|
|
310
|
+
- Javadoc's `{@link FileName}` syntax
|
|
311
|
+
- A class name wrapped in between `<<` `>>`.
|
|
312
|
+
|
|
313
|
+
**Example**
|
|
314
|
+
|
|
315
|
+
```apex
|
|
316
|
+
/**
|
|
317
|
+
* @description This is my method description. This method receives an <<ExampleClass>>.
|
|
318
|
+
* @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
|
|
319
|
+
* @return The result of the operation.
|
|
320
|
+
*/
|
|
321
|
+
public static Object doSomething(ExampleClass param1) {}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
---
|
|
325
|
+
|
|
326
|
+
Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
|
|
327
|
+
|
|
328
|
+
### HTML support
|
|
329
|
+
|
|
330
|
+
For the most part all HTML is sanitized when the `--sanitizeHtml` flag is passed a true value (which is the default).
|
|
331
|
+
But there are some tags are allowed to have for the possibility of better
|
|
332
|
+
styling long text.
|
|
333
|
+
|
|
334
|
+
- Allowed tags are: `br`, `p`, `ul`, `li`, and `code`
|
|
335
|
+
|
|
336
|
+
Example
|
|
337
|
+
|
|
338
|
+
```apex
|
|
339
|
+
/**
|
|
340
|
+
* @description <p>This is a paragraph</p>
|
|
341
|
+
* <p>And this is another paragraph</p>
|
|
342
|
+
* <ul>
|
|
343
|
+
* <li>This is a list item</li>
|
|
344
|
+
* <li>This is another list item</li>
|
|
345
|
+
* </ul>
|
|
346
|
+
*/
|
|
347
|
+
class MyClass {
|
|
348
|
+
}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
⚠️When the `--sanitizeHtml` flag is ON, any special character between code blocks (i.e. \```, \`, or `<code>`) will also
|
|
352
|
+
be escaped.
|
|
353
|
+
So if you have references to Apex generic collections (Set, List, or Maps) they will not look right, as the < and >
|
|
354
|
+
symbols will be escaped.
|
|
355
|
+
To prevent this you can turn the flag off, but be aware of the special considerations when doing this described below.
|
|
356
|
+
|
|
357
|
+
---
|
|
358
|
+
|
|
359
|
+
For full control over the output you can also turn off the `--sanitizeHtml` flag, which will allow you
|
|
360
|
+
to have any desired HTML within your docs.
|
|
361
|
+
|
|
362
|
+
⚠️When the `--sanitizeHtml` flag is OFF, references to Apex generic collections (Set, List or Maps) can be problematic
|
|
363
|
+
as they will be treated as an HTML tag and not displayed. For example if you have something
|
|
364
|
+
like `@description Returns a List<String>`
|
|
365
|
+
the `<String>` portion will be treated as HTML and thus not appear on the page.
|
|
366
|
+
|
|
367
|
+
To fix this issue, when not sanitizing HTML, you should wrap any code that contain special characters that can be
|
|
368
|
+
treated as HTML within '\`'
|
|
369
|
+
or within `<code>` tags.
|
|
370
|
+
|
|
371
|
+
### Displaying diagrams
|
|
372
|
+
|
|
373
|
+
You can display diagrams in your documentation by leveraging Github's built-in [Mermaid](https://mermaid-js.github.io/mermaid/#/) support.
|
|
374
|
+
|
|
375
|
+
If you are using a markdown generator that supports Mermaid (e.g. [Github's markdown](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/),
|
|
376
|
+
you can add diagrams to your documentation by using the
|
|
377
|
+
`@mermaid` tag.
|
|
378
|
+
|
|
379
|
+
**Example**
|
|
380
|
+
|
|
381
|
+
```apex
|
|
382
|
+
/**
|
|
383
|
+
* @mermaid
|
|
384
|
+
* graph TD
|
|
385
|
+
* A[Christmas] -->|Get money| B(Go shopping)
|
|
386
|
+
* B --> C{Let me think}
|
|
387
|
+
* C -->|One| D[Laptop]
|
|
388
|
+
* C -->|Two| E[iPhone]
|
|
389
|
+
* C -->|Three| F[Car]
|
|
390
|
+
*/
|
|
391
|
+
public class MyClass {
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
[Here's an example of how that looks](/docs/types/Classes/nspc.AnotherInterface.md)
|
|
396
|
+
|
|
397
|
+
### Ignoring files and members
|
|
398
|
+
|
|
399
|
+
You can ignore files and members by using the `@ignore` tag on any ApexDoc block. If used at the class level, the entire
|
|
400
|
+
file will be ignored. If used at the member level, only that member will be ignored.
|
|
401
|
+
|
|
402
|
+
Example
|
|
403
|
+
|
|
404
|
+
```apex
|
|
405
|
+
/**
|
|
406
|
+
* @ignore
|
|
407
|
+
*/
|
|
408
|
+
public class MyClass {
|
|
409
|
+
public static void myMethod() {}
|
|
410
|
+
}
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
## Generating OpenApi REST Definitions
|
|
414
|
+
|
|
415
|
+
ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
|
|
416
|
+
|
|
417
|
+
### Usage
|
|
418
|
+
|
|
419
|
+
To create an OpenApi specification file, run the `apexdocs-generate` and pass `openapi` to the `--targetGenerator` parameter.
|
|
420
|
+
When using this generator, you can also pass a custom title through the `--openApiTitle` parameter. This title will be placed
|
|
421
|
+
in the output file's `info.title` property, as defined by the [OpenApi documentation for the Info Object](https://spec.openapis.org/oas/v3.1.0#info-object)
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
```shell
|
|
425
|
+
apexdocs-generate -s ./src -t docs -g openapi --openApiTitle "Custom OpenApi Title"
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### How It Works
|
|
429
|
+
|
|
430
|
+
When generating an OpenApi document, since `@RestResource` classes need to be global in Apex, the `--scope` parameter will be ignored.
|
|
431
|
+
Instead, ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
|
|
432
|
+
|
|
433
|
+
Once it finishes running, a file named `openapi.json` will be created in the specified `--targetDir`.
|
|
434
|
+
|
|
435
|
+
### Configuring What Gets Created
|
|
436
|
+
|
|
437
|
+
ApexDocs will automatically parse your source code and generate the OpenApi definition based on the HTTP related Apex
|
|
438
|
+
annotations (RestResource, HttpDelete, HttpGet, HttpPatch, HttpPost, HttpGet). The different HTTP annotations will be used to generate a file that complies with the [OpenApi Specification v3.1.0](https://spec.openapis.org/oas/v3.1.0)
|
|
439
|
+
|
|
440
|
+
Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs, relying on
|
|
441
|
+
some custom annotations that are specific to generating OpenApi definitions:
|
|
442
|
+
|
|
443
|
+
* `@http-request-body`
|
|
444
|
+
* `@http-parameter`
|
|
445
|
+
* `@http-response`
|
|
446
|
+
|
|
447
|
+
#### @http-request-body
|
|
448
|
+
|
|
449
|
+
Allows you to specify the HTTP request's expected request body. It supports receiving a `description`,
|
|
450
|
+
whether it is `required` or not, and a `schema`, which defines the shape of the object that is expected.
|
|
451
|
+
|
|
452
|
+
📝 Note that only one `@http-request-body` should be defined per method. If you add more than one, only
|
|
453
|
+
a single one will be used when generating the OpenApi definition.
|
|
454
|
+
|
|
455
|
+
The `schema` can either be a reference to another class in your source code (see the `Class References` section below)
|
|
456
|
+
or a fully defined custom schema (See the `Custom Schemas` section below).
|
|
457
|
+
|
|
458
|
+
Example
|
|
459
|
+
```apex
|
|
460
|
+
/**
|
|
461
|
+
* @description This is a sample HTTP Post method
|
|
462
|
+
* @http-request-body
|
|
463
|
+
* description: This is an example of a request body
|
|
464
|
+
* required: true
|
|
465
|
+
* schema: ClassName
|
|
466
|
+
*/
|
|
467
|
+
@HttpPost
|
|
468
|
+
global static void doPost() {
|
|
469
|
+
///...
|
|
470
|
+
}
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
|
|
474
|
+
so spacing is important.
|
|
475
|
+
|
|
476
|
+
#### @http-parameter
|
|
477
|
+
|
|
478
|
+
Allows you to specify any HTTP parameter expected by your method. It supports receiving a `name`,
|
|
479
|
+
an `in` as defined by the supported [Parameter Locations](https://spec.openapis.org/oas/v3.1.0#parameter-locations),
|
|
480
|
+
whether it is `required` or not, a `description`, and a `schema`.
|
|
481
|
+
|
|
482
|
+
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
483
|
+
|
|
484
|
+
Example
|
|
485
|
+
```apex
|
|
486
|
+
/**
|
|
487
|
+
* @description This is a sample HTTP Post method
|
|
488
|
+
* @return A String SObject.
|
|
489
|
+
* @http-parameter
|
|
490
|
+
* name: limit
|
|
491
|
+
* in: query
|
|
492
|
+
* required: true
|
|
493
|
+
* description: Limits the number of items on a page
|
|
494
|
+
* schema:
|
|
495
|
+
* type: integer
|
|
496
|
+
* @http-parameter
|
|
497
|
+
* name: complex
|
|
498
|
+
* in: cookie
|
|
499
|
+
* schema: MyClassName
|
|
500
|
+
*/
|
|
501
|
+
@HttpPost
|
|
502
|
+
global static String doPost() {
|
|
503
|
+
// ..
|
|
504
|
+
}
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
|
|
508
|
+
so spacing is important.
|
|
509
|
+
|
|
510
|
+
#### @http-response
|
|
511
|
+
|
|
512
|
+
Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response code,
|
|
513
|
+
a `description`, and a `schema`.
|
|
514
|
+
|
|
515
|
+
If no `description` is provided then one will be automatically built using the `statusCode`.
|
|
516
|
+
|
|
517
|
+
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
518
|
+
|
|
519
|
+
```apex
|
|
520
|
+
/**
|
|
521
|
+
* @description This is a sample HTTP Post method
|
|
522
|
+
* @return A String SObject.
|
|
523
|
+
* @http-response
|
|
524
|
+
* statusCode: 200
|
|
525
|
+
* schema: SuccessfulResponseClassName
|
|
526
|
+
* @http-response
|
|
527
|
+
* statusCode: 500
|
|
528
|
+
* description: Status Code 500 - An internal server error occurred.
|
|
529
|
+
* schema:
|
|
530
|
+
* type: string
|
|
531
|
+
*/
|
|
532
|
+
@HttpPost
|
|
533
|
+
global static String doPost() {
|
|
534
|
+
// ...
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
#### Class References
|
|
539
|
+
|
|
540
|
+
Whenever specifying a `schema` parameter, you can pass as a string the name of any class in your source code. This
|
|
541
|
+
class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi definition.
|
|
542
|
+
|
|
543
|
+
The tool will parse the class and create a reference that complies with [Apex's support for User-Defined Types](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm#ApexRESTUserDefinedTypes)
|
|
544
|
+
|
|
545
|
+
##### Reference Overrides
|
|
546
|
+
|
|
547
|
+
When dealing with references, there might be cases when you want to manually tell the parser what type of object a property
|
|
548
|
+
or field is. For example, let's say we have a class that looks as follows
|
|
549
|
+
|
|
550
|
+
```apex
|
|
551
|
+
public class MyClass {
|
|
552
|
+
public Object myObject;
|
|
553
|
+
public Account myAccountRecord;
|
|
554
|
+
}
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
In this case `myObject` has a type of `Object`, and `myAccountRecord` is an SObject. Neither of these will be accurately
|
|
558
|
+
parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any properties.
|
|
559
|
+
|
|
560
|
+
To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override its
|
|
561
|
+
type during parsing. In this annotation you can specify the same thing you would in any `schema` property when dealing with any
|
|
562
|
+
of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
|
|
563
|
+
|
|
564
|
+
```apex
|
|
565
|
+
public class MyClass {
|
|
566
|
+
/**
|
|
567
|
+
* @description This is a generic reference to another class
|
|
568
|
+
* @http-schema MyOtherClassName
|
|
569
|
+
*/
|
|
570
|
+
public Object myObject;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* @description This is a reference to an Account SObject
|
|
574
|
+
* @http-schema
|
|
575
|
+
* type: object
|
|
576
|
+
* properties:
|
|
577
|
+
* Id:
|
|
578
|
+
* type: string
|
|
579
|
+
* Name:
|
|
580
|
+
* type: string
|
|
581
|
+
* CustomField__c:
|
|
582
|
+
* type: number
|
|
583
|
+
*/
|
|
584
|
+
public Account myAccountRecord;
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
---
|
|
589
|
+
|
|
590
|
+
If dealing with a collection, you can also specify the name of the reference either using the `List` or `Set` syntax.
|
|
591
|
+
|
|
592
|
+
📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
|
|
593
|
+
deep are supported (e.g. List<List<String>> is not supported). This is only a limitation when referencing collections
|
|
594
|
+
on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a referenced
|
|
595
|
+
class as part of your codebase.
|
|
596
|
+
|
|
597
|
+
Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
|
|
598
|
+
to convert that to a valid specification. For this use case, define a Custom Schema as explained below.
|
|
599
|
+
|
|
600
|
+
```apex
|
|
601
|
+
/**
|
|
602
|
+
* @description This is a sample HTTP Post method
|
|
603
|
+
* @http-request-body
|
|
604
|
+
* description: This is an example of a request body
|
|
605
|
+
* schema: List<ClassName>
|
|
606
|
+
*/
|
|
607
|
+
@HttpPost
|
|
608
|
+
global static void doPost() {
|
|
609
|
+
///...
|
|
610
|
+
}
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
Inner class references are also supported, but note that you need to pass the full name of the reference,
|
|
614
|
+
by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP method
|
|
615
|
+
referencing it.
|
|
616
|
+
|
|
617
|
+
```apex
|
|
618
|
+
/**
|
|
619
|
+
* @description This is a sample HTTP Post method
|
|
620
|
+
* @http-request-body
|
|
621
|
+
* description: This is an example of a request body
|
|
622
|
+
* schema: ParentClass.InnerClass
|
|
623
|
+
*/
|
|
624
|
+
@HttpPost
|
|
625
|
+
global static void doPost() {
|
|
626
|
+
///...
|
|
627
|
+
}
|
|
628
|
+
```
|
|
629
|
+
|
|
630
|
+
#### Custom Schemas
|
|
631
|
+
|
|
632
|
+
For any `schema` parameter in any of the HTTP ApexDocs annotations, besides specifying the name of a class, you
|
|
633
|
+
can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an `array`
|
|
634
|
+
|
|
635
|
+
**Primitives**
|
|
636
|
+
|
|
637
|
+
For primitives, you should specify the `type` and an optional `format`, as defined by the [OpenApi Specification on Data Types](https://spec.openapis.org/oas/v3.1.0#data-types)
|
|
638
|
+
|
|
639
|
+
```apex
|
|
640
|
+
/**
|
|
641
|
+
* ...
|
|
642
|
+
* schema:
|
|
643
|
+
* type: string
|
|
644
|
+
* format: password
|
|
645
|
+
*/
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
**Objects**
|
|
649
|
+
|
|
650
|
+
To specify a custom object schema, use `object` as the `type`, and specify as many properties as follows:
|
|
651
|
+
|
|
652
|
+
```apex
|
|
653
|
+
/**
|
|
654
|
+
* schema:
|
|
655
|
+
* type: object
|
|
656
|
+
* properties:
|
|
657
|
+
* id:
|
|
658
|
+
* type: string
|
|
659
|
+
* description: The super Id.
|
|
660
|
+
* name:
|
|
661
|
+
* type: string
|
|
662
|
+
* phone:
|
|
663
|
+
* type: string
|
|
664
|
+
* format: byte
|
|
665
|
+
*/
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
Properties can be defined as primitives (as explained above), other objects, or arrays (explained below)
|
|
669
|
+
|
|
670
|
+
**Arrays**
|
|
671
|
+
|
|
672
|
+
To specify a custom array schema, use `array` as the `type`, and provide an `items` definition. In `items`
|
|
673
|
+
you can specify the definition of any other custom type (primitives, objects, or other arrays).
|
|
674
|
+
|
|
675
|
+
```apex
|
|
676
|
+
/**
|
|
677
|
+
* schema:
|
|
678
|
+
* type: array
|
|
679
|
+
* items:
|
|
680
|
+
* type: object
|
|
681
|
+
* properties:
|
|
682
|
+
* name:
|
|
683
|
+
* type: string
|
|
684
|
+
*/
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
#### SObject References
|
|
688
|
+
|
|
689
|
+
ApexDocs is not able to automatically parse SObject references, as it can with class references, as it does
|
|
690
|
+
not reach into your org to get existing SObject describes. Because of this, when dealing with SObject references
|
|
691
|
+
you should create a Custom Schema as defined above. This will also allow you to specify which specific
|
|
692
|
+
fields are being received or returned.
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
### Considerations
|
|
696
|
+
|
|
697
|
+
Please be aware of the following when using ApexDocs to create an OpenApi definition:
|
|
698
|
+
|
|
699
|
+
* Map references are resolved as `object` with no properties, as it is not possible to know which keys the map will contain.
|
|
700
|
+
When using maps either create a class that better represents the shape of the object and use a Class Reference, or
|
|
701
|
+
define a Custom Schema in the `schema` section of the ApexDoc itself.
|
|
702
|
+
* Same thing when referencing SObjects, as SObject describe parsing is not supported by the ApexDocs tool. When referencing
|
|
703
|
+
SObjects, consider defining a Custom Schema in the `schema` section of the ApexDoc.
|
|
704
|
+
* ApexDoc is only able to parse through your source code, so references to other packages (namespaced classes) or any
|
|
705
|
+
code that lives outside your source code is not supported. Consider creating a Custom Schema for those situations.
|
|
706
|
+
* The return value and received parameters or your methods are currently not being considered when creating the OpenApi definition file.
|
|
707
|
+
Instead, use the `@http-response` ApexDoc annotation to specify the return value, and `@http-parameter` to specify any
|
|
708
|
+
expected parameter.
|
|
709
|
+
|
|
710
|
+
## Typescript
|
|
711
|
+
|
|
712
|
+
ApexDocs provides all necessary type definitions.
|
|
713
|
+
|
|
714
|
+
---
|
|
715
|
+
|
|
716
|
+
## 1.X
|
|
717
|
+
|
|
718
|
+
Looking for documentation for version 1.X? Please refer to its [branch](https://github.com/cesarParra/apexdocs/tree/1.x)
|