@cparra/apexdocs 3.0.0-beta.1 → 3.0.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/LICENSE +1 -1
- package/README.md +246 -650
- package/dist/cli/generate.js +74 -3095
- package/dist/defaults-BcE8DTat.js +13 -0
- package/dist/defaults-D07y_bq4.js +40 -0
- package/dist/defaults-gPzwP66p.js +14 -0
- package/dist/index.d.ts +49 -19
- package/dist/index.js +90 -2
- package/dist/logger-BEbUIfqN.js +3282 -0
- package/dist/logger-BGuf1PnL.js +3281 -0
- package/dist/logger-CWBRF2za.js +3284 -0
- package/dist/logger-CdBmDEN1.js +3283 -0
- package/dist/logger-Ce4QqPFR.js +3278 -0
- package/dist/logger-CyEVYaAC.js +3284 -0
- package/dist/logger-D7a83ycP.js +3277 -0
- package/dist/logger-DGaHeBKk.js +3279 -0
- package/dist/logger-Dqhl_lO_.js +3278 -0
- package/dist/logger-aySSWi0G.js +3280 -0
- package/dist/logger-qLCcAtiy.js +3284 -0
- package/examples/README.md +5 -0
- package/examples/docsify/README.md +17 -0
- package/examples/docsify/apexdocs.config.ts +13 -0
- package/examples/docsify/classes/ASampleClass.cls +57 -0
- package/examples/docsify/classes/CodeControl.cls +19 -0
- package/examples/docsify/classes/SampleClass.cls +95 -0
- package/examples/docsify/classes/SampleInterface.cls +17 -0
- package/examples/docsify/classes/SomeDto.cls +122 -0
- package/examples/docsify/docs/.nojekyll +0 -0
- package/examples/docsify/docs/README.md +25 -0
- package/examples/docsify/docs/_config.yml +1 -0
- package/examples/docsify/docs/index.html +22 -0
- package/examples/docsify/docs/miscellaneous/ASampleClass.md +88 -0
- package/examples/docsify/docs/miscellaneous/CodeControl.md +107 -0
- package/examples/docsify/docs/miscellaneous/SomeDto.md +244 -0
- package/examples/docsify/docs/sample-classes/SampleClass.md +171 -0
- package/examples/docsify/docs/sample-interfaces/SampleInterface.md +36 -0
- package/examples/docsify/package-lock.json +2459 -0
- package/examples/docsify/package.json +14 -0
- package/examples/imported/.forceignore +12 -0
- package/examples/imported/README.md +6 -0
- package/examples/imported/config/project-scratch-def.json +5 -0
- package/examples/imported/docs/index.md +109 -0
- package/examples/imported/docs/miscellaneous/BaseClass.md +13 -0
- package/examples/imported/docs/miscellaneous/MultiInheritanceClass.md +69 -0
- package/examples/imported/docs/miscellaneous/ParentInterface.md +12 -0
- package/examples/imported/docs/miscellaneous/ReferencedEnum.md +5 -0
- package/examples/imported/docs/miscellaneous/SampleException.md +21 -0
- package/examples/imported/docs/miscellaneous/SampleInterface.md +113 -0
- package/examples/imported/docs/miscellaneous/Url.md +308 -0
- package/examples/imported/docs/sample-enums/SampleEnum.md +33 -0
- package/examples/imported/docs/samplegroup/SampleClass.md +167 -0
- package/examples/imported/force-app/classes/BaseClass.cls +3 -0
- package/examples/imported/force-app/classes/MultiInheritanceClass.cls +1 -0
- package/examples/imported/force-app/classes/ParentInterface.cls +3 -0
- package/examples/imported/force-app/classes/ReferencedEnum.cls +3 -0
- package/examples/imported/force-app/classes/SampleInterface.cls +50 -0
- package/examples/imported/force-app/classes/Url.cls +196 -0
- package/examples/imported/package-lock.json +665 -0
- package/examples/imported/package.json +6 -0
- package/examples/imported/scripts/process-docs.mjs +16 -0
- package/examples/imported/sfdx-project.json +12 -0
- package/examples/markdown/README.md +7 -0
- package/examples/markdown/docs/miscellaneous/Url.md +10 -8
- package/examples/markdown/force-app/classes/Url.cls +3 -1
- package/examples/markdown-jsconfig/.forceignore +12 -0
- package/examples/markdown-jsconfig/README.md +9 -0
- package/examples/markdown-jsconfig/apexdocs.config.mjs +22 -0
- package/examples/markdown-jsconfig/config/project-scratch-def.json +5 -0
- package/examples/markdown-jsconfig/docs/index.md +12 -0
- package/examples/markdown-jsconfig/docs/miscellaneous/Url.md +315 -0
- package/examples/markdown-jsconfig/force-app/classes/Url.cls +196 -0
- package/examples/markdown-jsconfig/package-lock.json +665 -0
- package/examples/markdown-jsconfig/package.json +15 -0
- package/examples/markdown-jsconfig/sfdx-project.json +12 -0
- package/examples/open-api/README.md +5 -0
- package/examples/open-api/docs/openapi.json +2 -570
- package/examples/vitepress/README.md +25 -0
- package/examples/vitepress/apexdocs.config.ts +9 -2
- package/examples/vitepress/docs/index.md +11 -11
- package/examples/vitepress/docs/miscellaneous/BaseClass.md +1 -1
- package/examples/vitepress/docs/miscellaneous/MultiInheritanceClass.md +2 -2
- package/examples/vitepress/docs/miscellaneous/SampleException.md +1 -1
- package/examples/vitepress/docs/miscellaneous/SampleInterface.md +6 -6
- package/examples/vitepress/docs/miscellaneous/Url.md +3 -3
- package/examples/vitepress/docs/sample-enums/SampleEnum.md +3 -3
- package/examples/vitepress/docs/samplegroup/SampleClass.md +5 -5
- package/examples/vitepress/force-app/main/default/classes/feature-a/SampleClass.cls +73 -0
- package/examples/vitepress/force-app/main/default/classes/feature-a/SampleEnum.cls +30 -0
- package/examples/vitepress/force-app/main/default/classes/feature-a/SampleException.cls +17 -0
- package/package.json +3 -3
- package/src/application/Apexdocs.ts +16 -19
- package/src/application/__tests__/apex-file-reader.spec.ts +108 -67
- package/src/application/apex-file-reader.ts +1 -0
- package/src/application/generators/openapi.ts +17 -13
- package/src/cli/args.ts +12 -3
- package/src/cli/commands/markdown.ts +15 -12
- package/src/cli/commands/openapi.ts +5 -5
- package/src/cli/generate.ts +20 -4
- package/src/core/markdown/__test__/generating-class-docs.spec.ts +15 -386
- package/src/core/markdown/__test__/generating-docs.spec.ts +378 -0
- package/src/core/markdown/__test__/generating-enum-docs.spec.ts +4 -328
- package/src/core/markdown/__test__/generating-interface-docs.spec.ts +4 -296
- package/src/core/markdown/__test__/generating-reference-guide.spec.ts +17 -1
- package/src/core/markdown/__test__/test-helpers.ts +3 -1
- package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +3 -1
- package/src/core/markdown/adapters/renderable-to-page-data.ts +6 -4
- package/src/core/markdown/generate-docs.ts +13 -15
- package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +290 -0
- package/src/core/markdown/reflection/__test__/helpers.ts +18 -0
- package/src/core/markdown/reflection/__test__/remove-excluded-tags.spec.ts +200 -0
- package/src/core/markdown/reflection/remove-excluded-tags.ts +168 -0
- package/src/core/markdown/reflection/{sort-members.ts → sort-types-and-members.ts} +7 -5
- package/src/core/markdown/templates/reference-guide.ts +2 -2
- package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +6 -3
- package/src/core/openapi/open-api-docs-processor.ts +3 -3
- package/src/core/openapi/parser.ts +5 -2
- package/src/core/shared/types.d.ts +18 -18
- package/src/defaults.ts +15 -3
- package/src/index.ts +88 -14
- package/src/util/error-logger.ts +36 -36
- package/src/util/logger.ts +18 -11
- /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleClass.cls +0 -0
- /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleEnum.cls +0 -0
- /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleException.cls +0 -0
- /package/examples/vitepress/force-app/main/default/classes/{SampleInterface.cls → feature-a/SampleInterface.cls} +0 -0
package/README.md
CHANGED
|
@@ -1,779 +1,375 @@
|
|
|
1
1
|
# ApexDocs
|
|
2
2
|
|
|
3
|
-
<
|
|
4
|
-
<b>
|
|
5
|
-
</p>
|
|
3
|
+
<div align="center">
|
|
4
|
+
<b>CLI and Node library to generate documentation for Salesforce Apex classes.</b>
|
|
6
5
|
|
|
6
|
+
[](https://github.com/cesarParra/apexdocs/actions/workflows/ci.yaml)
|
|
7
7
|
[](https://github.com/cesarParra/apexdocs/blob/master/LICENSE)
|
|
8
|
+
[](https://www.npmjs.com/package/@cparra/apexdocs)
|
|
9
|
+
</div>
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
ApexDocs is a non-opinionated documentation generator for Salesforce Apex classes.
|
|
12
|
+
It can output documentation in Markdown
|
|
13
|
+
format,
|
|
14
|
+
which allows you to use the Static Site Generator of your choice to create a documentation site that fits your needs,
|
|
15
|
+
hosted in any static web hosting service.
|
|
10
16
|
|
|
11
|
-
|
|
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.
|
|
17
|
+
## 💿 Installation
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
There are some key differences between ApexDocs and the Java based ApexDoc tool:
|
|
19
|
+
```bash
|
|
20
|
+
npm i -g @cparra/apexdocs
|
|
21
|
+
```
|
|
20
22
|
|
|
21
|
-
|
|
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.
|
|
23
|
+
## ⚡ Quick Start
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
### CLI
|
|
29
26
|
|
|
30
|
-
|
|
27
|
+
#### Markdown
|
|
31
28
|
|
|
32
|
-
|
|
33
|
-
output to the resulting markdown file:
|
|
29
|
+
Run the following command to generate markdown files for your global Salesforce Apex classes:
|
|
34
30
|
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
* @MyCustomAnnotation This is a custom annotation
|
|
38
|
-
*/
|
|
39
|
-
public class MyClass {
|
|
40
|
-
}
|
|
31
|
+
```bash
|
|
32
|
+
apexdocs markdown -s force-app
|
|
41
33
|
```
|
|
42
34
|
|
|
43
|
-
|
|
35
|
+
#### OpenApi
|
|
44
36
|
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
Run the following command to generate an OpenApi REST specification for your Salesforce Apex classes
|
|
38
|
+
annotated with `@RestResource`:
|
|
47
39
|
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
* @MyCustomAnnotation This is a custom annotation with an `@embedded` annotation
|
|
51
|
-
*/
|
|
40
|
+
```bash
|
|
41
|
+
apexdocs openapi -s force-app
|
|
52
42
|
```
|
|
53
43
|
|
|
44
|
+
## 🚀 Features
|
|
45
|
+
|
|
46
|
+
* Generate documentation for Salesforce Apex classes as Markdown files
|
|
47
|
+
* Generate an OpenApi REST specification based on `@RestResource` classes
|
|
54
48
|
* Support for grouping blocks of related code within a class
|
|
55
|
-
* Support for HTML tags
|
|
56
|
-
* OpenApi REST specification generation
|
|
57
49
|
* Support for ignoring files and members from being documented
|
|
58
50
|
* Namespace support
|
|
59
51
|
* Configuration file support
|
|
52
|
+
* Single line ApexDoc Blocks
|
|
53
|
+
* Custom tag support
|
|
60
54
|
* And much, much more!
|
|
61
55
|
|
|
62
|
-
|
|
56
|
+
## 👀 Demo
|
|
63
57
|
|
|
64
|
-
ApexDocs
|
|
65
|
-
|
|
58
|
+
ApexDocs generates Markdown files, which can be integrated into any Static Site Generation engine,
|
|
59
|
+
(e.g. Jekyll, Vitepress, Hugo, Docosaurus, etc.) to create a documentation site that fits your needs.
|
|
66
60
|
|
|
67
|
-
|
|
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
|
|
61
|
+
This repo contains several example implementations in the `examples` directory, showcasing how to integrate
|
|
62
|
+
with some of these tools.
|
|
76
63
|
|
|
77
|
-
|
|
64
|
+
* [Examples](./examples)
|
|
78
65
|
|
|
79
|
-
###
|
|
80
|
-
|
|
81
|
-
Demo
|
|
82
|
-
|
|
83
|
-
- [Jekyll](https://cesarparra.github.io/apexdocs-docsify-example/)
|
|
66
|
+
### In the wild
|
|
84
67
|
|
|
85
|
-
|
|
68
|
+
Here are some live projects using ApexDocs:
|
|
86
69
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
70
|
+
- [Trailhead Apex Recipes](https://github.com/trailheadapps/apex-recipes)
|
|
71
|
+
- [Salesforce Commerce Apex Reference](https://developer.salesforce.com/docs/commerce/salesforce-commerce/references/comm-apex-reference/cart-reference.html)
|
|
72
|
+
- [Expression (API)](https://cesarparra.github.io/expression/)
|
|
73
|
+
- [Nimble AMS Docs](https://nimbleuser.github.io/nams-api-docs/#/api-reference/)
|
|
90
74
|
|
|
91
|
-
##
|
|
75
|
+
## ▶️ Available Commands
|
|
92
76
|
|
|
93
|
-
|
|
77
|
+
`markdown`
|
|
94
78
|
|
|
95
|
-
|
|
96
|
-
apexdocs-generate
|
|
97
|
-
-s src
|
|
98
|
-
-t docs
|
|
99
|
-
-p global
|
|
100
|
-
-g docsify
|
|
101
|
-
```
|
|
79
|
+
### Flags
|
|
102
80
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
|
106
|
-
|
|
107
|
-
|
|
|
108
|
-
|
|
|
109
|
-
|
|
|
110
|
-
|
|
|
111
|
-
|
|
|
112
|
-
|
|
|
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:
|
|
81
|
+
| Flag | Alias | Description | Default | Required |
|
|
82
|
+
|------------------------|-------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------|----------|
|
|
83
|
+
| `--sourceDir` | `-s` | The directory where the source files are located. | N/A | Yes |
|
|
84
|
+
| `--targetDir` | `-t` | The directory where the generated files will be placed. | `docs` | No |
|
|
85
|
+
| `--scope` | `-p` | A list of scopes to document. Values should be separated by a space, e.g --scope global public namespaceaccessible. | `global` | No |
|
|
86
|
+
| `--defaultGroupName` | N/A | The default group name to use when a group is not specified. | `Miscellaneous` | No |
|
|
87
|
+
| `--namespace` | N/A | The package namespace, if any. If provided, it will be added to the generated files. | N/A | No |
|
|
88
|
+
| `--sortAlphabetically` | N/A | Sorts files appearing in the Reference Guide alphabetically, as well as the members of a class, interface or enum alphabetically. If false, the members will be displayed in the same order as the code. | `false` | No |
|
|
89
|
+
| `--includeMetadata ` | N/A | Whether to include the file's meta.xml information: Whether it is active and and the API version | `false` | No |
|
|
90
|
+
| `--linkingStrategy` | N/A | The strategy to use when linking to other classes. Possible values are `relative`, `no-link`, and `none` | `relative` | No |
|
|
128
91
|
|
|
129
|
-
|
|
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
|
|
92
|
+
#### Linking Strategy
|
|
133
93
|
|
|
134
|
-
The
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
94
|
+
The linking strategy determines how ApexDocs will link to other classes in your documentation. For example,
|
|
95
|
+
if I have class `A` that links through class `B` (e.g. through an `{@link B}` tag, the `@see` tag,
|
|
96
|
+
takes it as a param, returns it from a method, etc.), the linking strategy will determine how the link to class `B` is
|
|
97
|
+
created.
|
|
156
98
|
|
|
157
|
-
|
|
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
|
-
```
|
|
99
|
+
These are the possible values for the `linkingStrategy` flag:
|
|
170
100
|
|
|
171
|
-
|
|
101
|
+
- `relative`
|
|
172
102
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
103
|
+
Create a relative link to the class file.
|
|
104
|
+
So if both classes are in the same directory, the link will be created as
|
|
105
|
+
`[B](B.md)`.
|
|
106
|
+
If the classes are in different directories, the link will be created as `[B](../path/to/B.md)`
|
|
176
107
|
|
|
177
|
-
|
|
108
|
+
- `no-link`
|
|
178
109
|
|
|
179
|
-
|
|
110
|
+
Does not create a link at all. The class name will be displayed as plain text.
|
|
180
111
|
|
|
181
|
-
|
|
112
|
+
- `none`
|
|
182
113
|
|
|
183
|
-
|
|
114
|
+
Does not apply any kind of logic. Instead, the links will be determined by the path to the file
|
|
115
|
+
from the root of the documentation site OR by whatever path you have returned in the `transformReference` hook
|
|
116
|
+
for the file.
|
|
184
117
|
|
|
185
|
-
|
|
186
|
-
of the tag. For example `@custom-tag`
|
|
118
|
+
### Sample Usage
|
|
187
119
|
|
|
188
|
-
|
|
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. |
|
|
194
|
-
| `@date` | The date the class was created. |
|
|
195
|
-
|
|
196
|
-
**Example**
|
|
197
|
-
|
|
198
|
-
```apex
|
|
199
|
-
/**
|
|
200
|
-
* @description This is my class description.
|
|
201
|
-
*/
|
|
202
|
-
public with sharing class TestClass {
|
|
203
|
-
}
|
|
120
|
+
```bash
|
|
121
|
+
apexdocs markdown -s force-app -t docs -p global public namespaceaccessible -n MyNamespace
|
|
204
122
|
```
|
|
205
123
|
|
|
206
|
-
|
|
124
|
+
`openapi`
|
|
207
125
|
|
|
208
|
-
|
|
126
|
+
### Flags
|
|
209
127
|
|
|
210
|
-
|
|
|
211
|
-
|
|
212
|
-
|
|
|
213
|
-
|
|
|
214
|
-
|
|
|
215
|
-
|
|
|
216
|
-
|
|
|
128
|
+
| Flag | Alias | Description | Default | Required |
|
|
129
|
+
|----------------|-------|-------------------------------------------------------------------------------|-----------------|----------|
|
|
130
|
+
| `--sourceDir` | `-s` | The directory where the source files are located. | N/A | Yes |
|
|
131
|
+
| `--targetDir` | `-t` | The directory where the generated files will be placed. | `docs` | No |
|
|
132
|
+
| `--fileName` | N/A | The name of the OpenApi file. | `openapi.json` | No |
|
|
133
|
+
| `--namespace` | N/A | The package namespace, if any. This will be added to the API file Server Url. | N/A | No |
|
|
134
|
+
| `--title` | N/A | The title of the OpenApi file. | `Apex REST API` | No |
|
|
135
|
+
| `--apiVersion` | N/A | The version of the API. | `1.0.0` | No |
|
|
217
136
|
|
|
218
|
-
|
|
137
|
+
### Sample Usage
|
|
219
138
|
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
* @description This is my enum description.
|
|
223
|
-
*/
|
|
224
|
-
public Enum ExampleEnum {
|
|
225
|
-
VALUE_1, VALUE_2
|
|
226
|
-
}
|
|
139
|
+
```bash
|
|
140
|
+
apexdocs openapi -s force-app -t docs -n MyNamespace --title "My Custom OpenApi Title"
|
|
227
141
|
```
|
|
228
142
|
|
|
229
|
-
|
|
143
|
+
## 🔬 Defining a configuration file
|
|
230
144
|
|
|
231
|
-
|
|
145
|
+
You can also use a configuration file to define the parameters that will be used when generating the documentation.
|
|
232
146
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
| `@description` | One or more lines describing the value. |
|
|
147
|
+
Configuration files are the main way to integrate the generated documentation with the Static Site Generator of your
|
|
148
|
+
choice and your build process, as well as configuring any custom behavior and the output of the generated files.
|
|
236
149
|
|
|
237
|
-
|
|
150
|
+
### Overview
|
|
238
151
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
/** @description This is my enum value description. */
|
|
242
|
-
VALUE_1,
|
|
243
|
-
/** @description This is my other enum value description. */
|
|
244
|
-
VALUE_2
|
|
245
|
-
}
|
|
246
|
-
```
|
|
152
|
+
Apexdocs uses [cosmiconfig](https://www.npmjs.com/package/cosmiconfig) to load the configuration file, which means it
|
|
153
|
+
supports the following formats (plus anything else supported by cosmiconfig):
|
|
247
154
|
|
|
248
|
-
|
|
155
|
+
- A `package.json` property, e.g. `{ "apexdocs": { "sourceDir": "src", "targetDir": "docs" } }`
|
|
156
|
+
- A `.apexdocsrc` file, written in YAML or JSON, with optional extensions: `.yaml/.yml/.json/.js`
|
|
157
|
+
- An `apexdocs.config.js` (or `.mjs`) file that exports an object
|
|
158
|
+
- A `apexdocs.config.ts` file that exports an object
|
|
249
159
|
|
|
250
|
-
The
|
|
160
|
+
**The configuration file should be placed in the root directory of your project.**
|
|
251
161
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
| `@description` | One or more lines describing the property. |
|
|
162
|
+
**Note that when using a configuration file, you can still override any of the parameters by passing them through the
|
|
163
|
+
CLI.**
|
|
255
164
|
|
|
256
|
-
|
|
165
|
+
### Configuration file
|
|
257
166
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
* @description This is my property description.
|
|
261
|
-
*/
|
|
262
|
-
public String ExampleProperty { get; set; }
|
|
263
|
-
```
|
|
167
|
+
When defining a configuration file, it is recommended to use ES modules syntax. The config file should `default`
|
|
168
|
+
export an object with the parameters you want to use.:
|
|
264
169
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
| Tag | Description |
|
|
272
|
-
|------------------------------|---------------------------------------------------|
|
|
273
|
-
| `@description` | One or more lines describing the method. |
|
|
274
|
-
| `@param` _paramName_ | Description of a single parameter. |
|
|
275
|
-
| `@return` | Description of the return value of the method. |
|
|
276
|
-
| `@example` | Example of how the code can be used or called. |
|
|
277
|
-
| `@throws` _ExceptionName_ | Description of an exception thrown by the method. |
|
|
278
|
-
| `@exception` _ExceptionName_ | Same as `@throws`. V2 only |
|
|
279
|
-
| `@mermaid` | Diagrams in Mermaid format. |
|
|
280
|
-
|
|
281
|
-
**Example**
|
|
282
|
-
|
|
283
|
-
```apex
|
|
284
|
-
/**
|
|
285
|
-
* @description This is my method description.
|
|
286
|
-
* @param action The action to execute.
|
|
287
|
-
* @return The result of the operation.
|
|
288
|
-
* @example
|
|
289
|
-
* Object result = SampleClass.call('exampleAction');
|
|
290
|
-
*/
|
|
291
|
-
public static Object call(String action) {
|
|
170
|
+
```javascript
|
|
171
|
+
export default {
|
|
172
|
+
sourceDir: 'force-app',
|
|
173
|
+
targetDir: 'docs',
|
|
174
|
+
scope: ['global', 'public'],
|
|
175
|
+
...
|
|
292
176
|
}
|
|
293
177
|
```
|
|
294
178
|
|
|
295
|
-
|
|
179
|
+
Every property in the configuration file is optional, and if not provided, either the value provided through the
|
|
180
|
+
CLI will be used, or the default value will be used.
|
|
296
181
|
|
|
297
|
-
|
|
298
|
-
of the tag. Apexdocs will automatically format tags which words are separated by a dash (`-`) by separating them with a
|
|
299
|
-
space and uppercasing them. For example, `@custom-tag` will be displayed as `Custom Tag`.
|
|
182
|
+
### Config Intellisense
|
|
300
183
|
|
|
301
|
-
|
|
302
|
-
|
|
184
|
+
Using the `defineMarkdownConfig` (or the `defineOpenApiConfig` for OpenApi documentation)
|
|
185
|
+
helper will provide Typescript-powered intellisense
|
|
186
|
+
for the configuration file options. This should work with both Javascript and Typescript files.
|
|
303
187
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
*/
|
|
314
|
-
public class MyClass {
|
|
315
|
-
}
|
|
316
|
-
```
|
|
317
|
-
|
|
318
|
-
Note that the language of the code block will be set to `apex` by default, but you can change it by adding the language
|
|
319
|
-
name after the triple backticks. For example, to display a JavaScript code block you can use:
|
|
320
|
-
|
|
321
|
-
```apex
|
|
322
|
-
/**
|
|
323
|
-
* @custom-tag-with-code
|
|
324
|
-
* ```javascript
|
|
325
|
-
* console.log('Hello World');
|
|
326
|
-
* ```
|
|
327
|
-
*/
|
|
328
|
-
public class MyClass {
|
|
329
|
-
}
|
|
188
|
+
```typescript
|
|
189
|
+
import { defineMarkdownConfig } from "@cparra/apexdocs";
|
|
190
|
+
|
|
191
|
+
export default defineMarkdownConfig({
|
|
192
|
+
sourceDir: 'force-app',
|
|
193
|
+
targetDir: 'docs',
|
|
194
|
+
scope: ['global', 'public'],
|
|
195
|
+
...
|
|
196
|
+
});
|
|
330
197
|
```
|
|
331
198
|
|
|
332
|
-
###
|
|
199
|
+
### Excluding Tags from Appearing in the Documentation
|
|
333
200
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
of constants representing the possible values for different picklists.)
|
|
201
|
+
You can exclude tags from appearing in the documentation by using the `excludeTags` property in the configuration file,
|
|
202
|
+
which allow you to pass a list of tags that you want to exclude from the documentation.
|
|
337
203
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
204
|
+
```typescript
|
|
205
|
+
import { defineMarkdownConfig } from "@cparra/apexdocs";
|
|
206
|
+
|
|
207
|
+
export default defineMarkdownConfig({
|
|
208
|
+
sourceDir: 'force-app',
|
|
209
|
+
targetDir: 'docs',
|
|
210
|
+
scope: ['global', 'public'],
|
|
211
|
+
excludeTags: ['internal', 'ignore'],
|
|
212
|
+
...
|
|
213
|
+
});
|
|
345
214
|
```
|
|
346
215
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
Some notes about grouping:
|
|
216
|
+
### Configuration Hooks
|
|
350
217
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
* Properties
|
|
354
|
-
* Fields (variables and constants)
|
|
355
|
-
* Constructors
|
|
356
|
-
* Methods
|
|
357
|
-
* BUT only members of the same type are grouped together. For example,
|
|
358
|
-
if you have a group that contains properties and methods the properties will be grouped together under Properties ->
|
|
359
|
-
Group Name, and the methods will be grouped together under Methods -> Group Name
|
|
360
|
-
* Does not support inner types (inner classes, interfaces, and enums)
|
|
361
|
-
* It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for
|
|
362
|
-
that file.
|
|
218
|
+
When defining a `.js` or `.ts` configuration file, your object export can also make use
|
|
219
|
+
of different hooks that will be called at different stages of the documentation generation process.
|
|
363
220
|
|
|
364
|
-
|
|
221
|
+
All hooks can be async functions, allowing you to make asynchronous operations, like calling an external API.
|
|
365
222
|
|
|
366
|
-
|
|
367
|
-
class file for easy navigation.
|
|
223
|
+
📒 Note: The extension hook functions are only available when generating Markdown files (not OpenApi).
|
|
368
224
|
|
|
369
|
-
|
|
225
|
+
#### **transformReferenceGuide**
|
|
370
226
|
|
|
371
|
-
|
|
372
|
-
|
|
227
|
+
Allows changing the Allows changing the frontmatter and content of the reference guide, or even if creating a reference
|
|
228
|
+
guide page should be skipped.
|
|
373
229
|
|
|
374
|
-
**
|
|
230
|
+
**Type**
|
|
375
231
|
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
* @description This is my method description. This method receives an <<ExampleClass>>.
|
|
379
|
-
* @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
|
|
380
|
-
* @return The result of the operation.
|
|
381
|
-
*/
|
|
382
|
-
public static Object doSomething(ExampleClass param1) {}
|
|
232
|
+
```typescript
|
|
233
|
+
type TransformReferenceGuide = (referenceGuide: ReferenceGuidePageData) => Partial<ReferenceGuidePageData> | Skip | Promise<Partial<ReferenceGuidePageData> | Skip>;
|
|
383
234
|
```
|
|
384
235
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
|
|
236
|
+
Example: Updating the frontmatter
|
|
388
237
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
```apex
|
|
400
|
-
/**
|
|
401
|
-
* @description <p>This is a paragraph</p>
|
|
402
|
-
* <p>And this is another paragraph</p>
|
|
403
|
-
* <ul>
|
|
404
|
-
* <li>This is a list item</li>
|
|
405
|
-
* <li>This is another list item</li>
|
|
406
|
-
* </ul>
|
|
407
|
-
*/
|
|
408
|
-
class MyClass {
|
|
409
|
-
}
|
|
238
|
+
```typescript
|
|
239
|
+
export default {
|
|
240
|
+
transformReferenceGuide: (referenceGuide) => {
|
|
241
|
+
return {
|
|
242
|
+
// The frontmatter can either be an object, of the frontmatter string itself
|
|
243
|
+
frontmatter: { example: 'example' }
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
};
|
|
410
247
|
```
|
|
411
248
|
|
|
412
|
-
|
|
413
|
-
be escaped.
|
|
414
|
-
So if you have references to Apex generic collections (Set, List, or Maps) they will not look right, as the < and >
|
|
415
|
-
symbols will be escaped.
|
|
416
|
-
To prevent this you can turn the flag off, but be aware of the special considerations when doing this described below.
|
|
417
|
-
|
|
418
|
-
---
|
|
419
|
-
|
|
420
|
-
For full control over the output you can also turn off the `--sanitizeHtml` flag, which will allow you
|
|
421
|
-
to have any desired HTML within your docs.
|
|
422
|
-
|
|
423
|
-
⚠️When the `--sanitizeHtml` flag is OFF, references to Apex generic collections (Set, List or Maps) can be problematic
|
|
424
|
-
as they will be treated as an HTML tag and not displayed. For example if you have something
|
|
425
|
-
like `@description Returns a List<String>`
|
|
426
|
-
the `<String>` portion will be treated as HTML and thus not appear on the page.
|
|
249
|
+
Example: skipping the reference guide
|
|
427
250
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
251
|
+
```typescript
|
|
252
|
+
// The skip function is imported from the package
|
|
253
|
+
import { defineMarkdownConfig, skip } from "@cparra/apexdocs";
|
|
254
|
+
|
|
255
|
+
export default defineMarkdownConfig({
|
|
256
|
+
transformReferenceGuide: (referenceGuide) => {
|
|
257
|
+
return skip();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
```
|
|
431
261
|
|
|
432
|
-
|
|
262
|
+
#### **transformDocs**
|
|
433
263
|
|
|
434
|
-
|
|
264
|
+
The main purpose of this hook is to allow you to skip the generation of specific pages,
|
|
265
|
+
by returning a filtered array of `DocPageData` objects.
|
|
435
266
|
|
|
436
|
-
If you
|
|
437
|
-
you can add diagrams to your documentation by using the
|
|
438
|
-
`@mermaid` tag.
|
|
267
|
+
If you want to modify the contents or frontmatter of the docs, use the `transformDocPage` hook instead.
|
|
439
268
|
|
|
440
|
-
**
|
|
269
|
+
**Type**
|
|
441
270
|
|
|
442
|
-
```
|
|
443
|
-
|
|
444
|
-
* @mermaid
|
|
445
|
-
* graph TD
|
|
446
|
-
* A[Christmas] -->|Get money| B(Go shopping)
|
|
447
|
-
* B --> C{Let me think}
|
|
448
|
-
* C -->|One| D[Laptop]
|
|
449
|
-
* C -->|Two| E[iPhone]
|
|
450
|
-
* C -->|Three| F[Car]
|
|
451
|
-
*/
|
|
452
|
-
public class MyClass {
|
|
453
|
-
}
|
|
271
|
+
```typescript
|
|
272
|
+
type TransformDocs = (docs: DocPageData[]) => DocPageData[] | Promise<DocPageData[]>
|
|
454
273
|
```
|
|
455
274
|
|
|
456
|
-
[Here's an example of how that looks](/docs/types/Classes/nspc.AnotherInterface.md)
|
|
457
|
-
|
|
458
|
-
### Ignoring files and members
|
|
459
|
-
|
|
460
|
-
You can ignore files and members by using the `@ignore` tag on any ApexDoc block. If used at the class level, the entire
|
|
461
|
-
file will be ignored. If used at the member level, only that member will be ignored.
|
|
462
|
-
|
|
463
275
|
Example
|
|
464
276
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
```
|
|
473
|
-
|
|
474
|
-
## Generating OpenApi REST Definitions
|
|
475
|
-
|
|
476
|
-
ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
|
|
477
|
-
|
|
478
|
-
### Usage
|
|
479
|
-
|
|
480
|
-
To create an OpenApi specification file, run the `apexdocs-generate` and pass `openapi` to the `--targetGenerator` parameter.
|
|
481
|
-
When using this generator, you can also pass a custom title through the `--openApiTitle` parameter. This title will be placed
|
|
482
|
-
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)
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
```shell
|
|
486
|
-
apexdocs-generate -s ./src -t docs -g openapi --openApiTitle "Custom OpenApi Title"
|
|
277
|
+
```typescript
|
|
278
|
+
export default {
|
|
279
|
+
transformDocs: (docs) => {
|
|
280
|
+
return docs.filter(doc => doc.name !== 'MyClass');
|
|
281
|
+
}
|
|
282
|
+
};
|
|
487
283
|
```
|
|
488
284
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
When generating an OpenApi document, since `@RestResource` classes need to be global in Apex, the `--scope` parameter will be ignored.
|
|
492
|
-
Instead, ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
|
|
493
|
-
|
|
494
|
-
Once it finishes running, a file named `openapi.json` will be created in the specified `--targetDir`.
|
|
285
|
+
#### **transformDocPage**
|
|
495
286
|
|
|
496
|
-
|
|
287
|
+
Allows changing the frontmatter and content of the doc page.
|
|
497
288
|
|
|
498
|
-
|
|
499
|
-
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)
|
|
289
|
+
**Type**
|
|
500
290
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
* `@http-parameter`
|
|
506
|
-
* `@http-response`
|
|
507
|
-
|
|
508
|
-
#### @http-request-body
|
|
509
|
-
|
|
510
|
-
Allows you to specify the HTTP request's expected request body. It supports receiving a `description`,
|
|
511
|
-
whether it is `required` or not, and a `schema`, which defines the shape of the object that is expected.
|
|
512
|
-
|
|
513
|
-
📝 Note that only one `@http-request-body` should be defined per method. If you add more than one, only
|
|
514
|
-
a single one will be used when generating the OpenApi definition.
|
|
515
|
-
|
|
516
|
-
The `schema` can either be a reference to another class in your source code (see the `Class References` section below)
|
|
517
|
-
or a fully defined custom schema (See the `Custom Schemas` section below).
|
|
518
|
-
|
|
519
|
-
Example
|
|
520
|
-
```apex
|
|
521
|
-
/**
|
|
522
|
-
* @description This is a sample HTTP Post method
|
|
523
|
-
* @http-request-body
|
|
524
|
-
* description: This is an example of a request body
|
|
525
|
-
* required: true
|
|
526
|
-
* schema: ClassName
|
|
527
|
-
*/
|
|
528
|
-
@HttpPost
|
|
529
|
-
global static void doPost() {
|
|
530
|
-
///...
|
|
531
|
-
}
|
|
291
|
+
```typescript
|
|
292
|
+
type TransformDocPage = (
|
|
293
|
+
doc: DocPageData,
|
|
294
|
+
) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>
|
|
532
295
|
```
|
|
533
296
|
|
|
534
|
-
📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
|
|
535
|
-
so spacing is important.
|
|
536
|
-
|
|
537
|
-
#### @http-parameter
|
|
538
|
-
|
|
539
|
-
Allows you to specify any HTTP parameter expected by your method. It supports receiving a `name`,
|
|
540
|
-
an `in` as defined by the supported [Parameter Locations](https://spec.openapis.org/oas/v3.1.0#parameter-locations),
|
|
541
|
-
whether it is `required` or not, a `description`, and a `schema`.
|
|
542
|
-
|
|
543
|
-
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
544
|
-
|
|
545
297
|
Example
|
|
546
|
-
```apex
|
|
547
|
-
/**
|
|
548
|
-
* @description This is a sample HTTP Post method
|
|
549
|
-
* @return A String SObject.
|
|
550
|
-
* @http-parameter
|
|
551
|
-
* name: limit
|
|
552
|
-
* in: query
|
|
553
|
-
* required: true
|
|
554
|
-
* description: Limits the number of items on a page
|
|
555
|
-
* schema:
|
|
556
|
-
* type: integer
|
|
557
|
-
* @http-parameter
|
|
558
|
-
* name: complex
|
|
559
|
-
* in: cookie
|
|
560
|
-
* schema: MyClassName
|
|
561
|
-
*/
|
|
562
|
-
@HttpPost
|
|
563
|
-
global static String doPost() {
|
|
564
|
-
// ..
|
|
565
|
-
}
|
|
566
|
-
```
|
|
567
298
|
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
If no `description` is provided then one will be automatically built using the `statusCode`.
|
|
577
|
-
|
|
578
|
-
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
579
|
-
|
|
580
|
-
```apex
|
|
581
|
-
/**
|
|
582
|
-
* @description This is a sample HTTP Post method
|
|
583
|
-
* @return A String SObject.
|
|
584
|
-
* @http-response
|
|
585
|
-
* statusCode: 200
|
|
586
|
-
* schema: SuccessfulResponseClassName
|
|
587
|
-
* @http-response
|
|
588
|
-
* statusCode: 500
|
|
589
|
-
* description: Status Code 500 - An internal server error occurred.
|
|
590
|
-
* schema:
|
|
591
|
-
* type: string
|
|
592
|
-
*/
|
|
593
|
-
@HttpPost
|
|
594
|
-
global static String doPost() {
|
|
595
|
-
// ...
|
|
596
|
-
}
|
|
299
|
+
```typescript
|
|
300
|
+
export default {
|
|
301
|
+
transformDocPage: (doc) => {
|
|
302
|
+
return {
|
|
303
|
+
frontmatter: { example: 'example' }
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
};
|
|
597
307
|
```
|
|
598
308
|
|
|
599
|
-
####
|
|
600
|
-
|
|
601
|
-
Whenever specifying a `schema` parameter, you can pass as a string the name of any class in your source code. This
|
|
602
|
-
class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi definition.
|
|
309
|
+
#### **transformReference**
|
|
603
310
|
|
|
604
|
-
|
|
311
|
+
Allows changing where the files are written to and how files are linked to each other.
|
|
605
312
|
|
|
606
|
-
|
|
313
|
+
**Type**
|
|
607
314
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
public class MyClass {
|
|
613
|
-
public Object myObject;
|
|
614
|
-
public Account myAccountRecord;
|
|
615
|
-
}
|
|
616
|
-
```
|
|
617
|
-
|
|
618
|
-
In this case `myObject` has a type of `Object`, and `myAccountRecord` is an SObject. Neither of these will be accurately
|
|
619
|
-
parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any properties.
|
|
620
|
-
|
|
621
|
-
To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override its
|
|
622
|
-
type during parsing. In this annotation you can specify the same thing you would in any `schema` property when dealing with any
|
|
623
|
-
of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
|
|
624
|
-
|
|
625
|
-
```apex
|
|
626
|
-
public class MyClass {
|
|
627
|
-
/**
|
|
628
|
-
* @description This is a generic reference to another class
|
|
629
|
-
* @http-schema MyOtherClassName
|
|
630
|
-
*/
|
|
631
|
-
public Object myObject;
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* @description This is a reference to an Account SObject
|
|
635
|
-
* @http-schema
|
|
636
|
-
* type: object
|
|
637
|
-
* properties:
|
|
638
|
-
* Id:
|
|
639
|
-
* type: string
|
|
640
|
-
* Name:
|
|
641
|
-
* type: string
|
|
642
|
-
* CustomField__c:
|
|
643
|
-
* type: number
|
|
644
|
-
*/
|
|
645
|
-
public Account myAccountRecord;
|
|
646
|
-
}
|
|
315
|
+
```typescript
|
|
316
|
+
type TransformReference = (
|
|
317
|
+
reference: DocPageReference,
|
|
318
|
+
) => Partial<ConfigurableDocPageReference> | Promise<ConfigurableDocPageReference>;
|
|
647
319
|
```
|
|
648
320
|
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
If dealing with a collection, you can also specify the name of the reference either using the `List` or `Set` syntax.
|
|
652
|
-
|
|
653
|
-
📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
|
|
654
|
-
deep are supported (e.g. List<List<String>> is not supported). This is only a limitation when referencing collections
|
|
655
|
-
on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a referenced
|
|
656
|
-
class as part of your codebase.
|
|
657
|
-
|
|
658
|
-
Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
|
|
659
|
-
to convert that to a valid specification. For this use case, define a Custom Schema as explained below.
|
|
660
|
-
|
|
661
|
-
```apex
|
|
662
|
-
/**
|
|
663
|
-
* @description This is a sample HTTP Post method
|
|
664
|
-
* @http-request-body
|
|
665
|
-
* description: This is an example of a request body
|
|
666
|
-
* schema: List<ClassName>
|
|
667
|
-
*/
|
|
668
|
-
@HttpPost
|
|
669
|
-
global static void doPost() {
|
|
670
|
-
///...
|
|
671
|
-
}
|
|
672
|
-
```
|
|
321
|
+
Example
|
|
673
322
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
global static void doPost() {
|
|
687
|
-
///...
|
|
688
|
-
}
|
|
323
|
+
```typescript
|
|
324
|
+
export default {
|
|
325
|
+
// Notice how we are setting the linking strategy to none, so that nothing is done
|
|
326
|
+
// to the links by the tool when it tries to link to other classes
|
|
327
|
+
linkingStrategy: 'none',
|
|
328
|
+
transformReference: (reference) => {
|
|
329
|
+
return {
|
|
330
|
+
// Link to the class in Github instead to its doc page.
|
|
331
|
+
referencePath: `https://github.com/MyOrg/MyRepo/blob/main/src/classes/${reference.name}.cls`
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
};
|
|
689
335
|
```
|
|
690
336
|
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
For any `schema` parameter in any of the HTTP ApexDocs annotations, besides specifying the name of a class, you
|
|
694
|
-
can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an `array`
|
|
695
|
-
|
|
696
|
-
**Primitives**
|
|
337
|
+
## ⤵︎ Importing to your project
|
|
697
338
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
```apex
|
|
701
|
-
/**
|
|
702
|
-
* ...
|
|
703
|
-
* schema:
|
|
704
|
-
* type: string
|
|
705
|
-
* format: password
|
|
706
|
-
*/
|
|
707
|
-
```
|
|
708
|
-
|
|
709
|
-
**Objects**
|
|
710
|
-
|
|
711
|
-
To specify a custom object schema, use `object` as the `type`, and specify as many properties as follows:
|
|
712
|
-
|
|
713
|
-
```apex
|
|
714
|
-
/**
|
|
715
|
-
* schema:
|
|
716
|
-
* type: object
|
|
717
|
-
* properties:
|
|
718
|
-
* id:
|
|
719
|
-
* type: string
|
|
720
|
-
* description: The super Id.
|
|
721
|
-
* name:
|
|
722
|
-
* type: string
|
|
723
|
-
* phone:
|
|
724
|
-
* type: string
|
|
725
|
-
* format: byte
|
|
726
|
-
*/
|
|
727
|
-
```
|
|
339
|
+
### Reflection
|
|
728
340
|
|
|
729
|
-
|
|
341
|
+
If you are just interested in the Apex parsing capabilities, you can use the
|
|
342
|
+
standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
|
|
343
|
+
which is what gets used by this library behind the scenes to generate the documentation files.
|
|
730
344
|
|
|
731
|
-
|
|
345
|
+
### Processing
|
|
732
346
|
|
|
733
|
-
|
|
734
|
-
|
|
347
|
+
If you would like to use the processing capabilities of ApexDocs directly from Javascript/Typescript
|
|
348
|
+
instead of using the CLI, you can import the `process` function from the library.
|
|
735
349
|
|
|
736
|
-
```
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
*/
|
|
350
|
+
```typescript
|
|
351
|
+
import { process } from '@cparra/apexdocs';
|
|
352
|
+
|
|
353
|
+
process({
|
|
354
|
+
sourceDir: 'force-app',
|
|
355
|
+
targetDir: 'docs',
|
|
356
|
+
scope: ['global', 'public'],
|
|
357
|
+
...
|
|
358
|
+
});
|
|
746
359
|
```
|
|
747
360
|
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
ApexDocs is not able to automatically parse SObject references, as it can with class references, as it does
|
|
751
|
-
not reach into your org to get existing SObject describes. Because of this, when dealing with SObject references
|
|
752
|
-
you should create a Custom Schema as defined above. This will also allow you to specify which specific
|
|
753
|
-
fields are being received or returned.
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
### Considerations
|
|
757
|
-
|
|
758
|
-
Please be aware of the following when using ApexDocs to create an OpenApi definition:
|
|
361
|
+
### 👨💻 Typescript
|
|
759
362
|
|
|
760
|
-
|
|
761
|
-
When using maps either create a class that better represents the shape of the object and use a Class Reference, or
|
|
762
|
-
define a Custom Schema in the `schema` section of the ApexDoc itself.
|
|
763
|
-
* Same thing when referencing SObjects, as SObject describe parsing is not supported by the ApexDocs tool. When referencing
|
|
764
|
-
SObjects, consider defining a Custom Schema in the `schema` section of the ApexDoc.
|
|
765
|
-
* ApexDoc is only able to parse through your source code, so references to other packages (namespaced classes) or any
|
|
766
|
-
code that lives outside your source code is not supported. Consider creating a Custom Schema for those situations.
|
|
767
|
-
* The return value and received parameters or your methods are currently not being considered when creating the OpenApi definition file.
|
|
768
|
-
Instead, use the `@http-response` ApexDoc annotation to specify the return value, and `@http-parameter` to specify any
|
|
769
|
-
expected parameter.
|
|
363
|
+
If using Typescript, ApexDocs provides all necessary type definitions.
|
|
770
364
|
|
|
771
|
-
##
|
|
365
|
+
## 📖 Documentation Guide
|
|
772
366
|
|
|
773
|
-
|
|
367
|
+
See the [wiki](https://github.com/cesarParra/apexdocs/wiki/%F0%9F%93%96-Documenting-Apex-code)
|
|
368
|
+
for an in-depth guide on how to document your Apex code to get the most out of ApexDocs.
|
|
774
369
|
|
|
775
|
-
|
|
370
|
+
## 📄 Generating OpenApi REST Definitions
|
|
776
371
|
|
|
777
|
-
|
|
372
|
+
ApexDocs can also generate OpenApi REST definitions for your Salesforce Apex classes annotated with `@RestResource`.
|
|
778
373
|
|
|
779
|
-
|
|
374
|
+
See the [wiki](https://github.com/cesarParra/apexdocs/wiki/%F0%9F%93%84-Generating-OpenApi-REST-Definitions)
|
|
375
|
+
for more information.
|