@cparra/apexdocs 3.0.0-beta.1 → 3.0.0-rc.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 +442 -325
- package/dist/cli/generate.js +1 -1
- package/dist/index.d.ts +15 -17
- 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/apexdocs.config.mjs +21 -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/vitepress/apexdocs.config.ts +7 -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/SampleClass.cls +1 -1
- package/package.json +2 -2
- package/src/cli/commands/markdown.ts +1 -3
- package/src/core/markdown/__test__/generating-class-docs.spec.ts +1 -129
- package/src/core/markdown/__test__/generating-docs.spec.ts +111 -0
- package/src/core/markdown/__test__/generating-enum-docs.spec.ts +0 -64
- package/src/core/markdown/__test__/generating-interface-docs.spec.ts +0 -64
- package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +306 -0
- package/src/core/shared/types.d.ts +14 -16
- package/src/index.ts +23 -10
package/README.md
CHANGED
|
@@ -1,197 +1,350 @@
|
|
|
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
|
|
57
|
+
|
|
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.
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
This repo contains several example implementations in the `examples` directory, showcasing how to integrate
|
|
62
|
+
with some of these tools.
|
|
63
|
+
|
|
64
|
+
* [Examples](./examples)
|
|
66
65
|
|
|
67
66
|
### In the wild
|
|
68
67
|
|
|
69
|
-
|
|
68
|
+
Here are some live projects using ApexDocs:
|
|
69
|
+
|
|
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/)
|
|
70
73
|
- [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
74
|
|
|
73
|
-
|
|
75
|
+
## ▶️ Available Commands
|
|
76
|
+
|
|
77
|
+
`markdown`
|
|
78
|
+
|
|
79
|
+
### Flags
|
|
80
|
+
|
|
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
|
+
| `--sortMembersAlphabetically` | N/A | Sorts 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 |
|
|
74
91
|
|
|
75
|
-
|
|
92
|
+
#### Linking Strategy
|
|
76
93
|
|
|
77
|
-
|
|
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.
|
|
78
98
|
|
|
79
|
-
|
|
99
|
+
These are the possible values for the `linkingStrategy` flag:
|
|
80
100
|
|
|
81
|
-
|
|
101
|
+
- `relative`
|
|
82
102
|
|
|
83
|
-
|
|
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)`
|
|
84
107
|
|
|
85
|
-
|
|
108
|
+
- `no-link`
|
|
109
|
+
|
|
110
|
+
Does not create a link at all. The class name will be displayed as plain text.
|
|
111
|
+
|
|
112
|
+
- `none`
|
|
113
|
+
|
|
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.
|
|
117
|
+
|
|
118
|
+
### Sample Usage
|
|
86
119
|
|
|
87
120
|
```bash
|
|
88
|
-
|
|
121
|
+
apexdocs markdown -s force-app -t docs -p global public namespaceaccessible -n MyNamespace
|
|
89
122
|
```
|
|
90
123
|
|
|
91
|
-
|
|
124
|
+
`openapi`
|
|
92
125
|
|
|
93
|
-
###
|
|
126
|
+
### Flags
|
|
127
|
+
|
|
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 |
|
|
136
|
+
|
|
137
|
+
### Sample Usage
|
|
94
138
|
|
|
95
139
|
```bash
|
|
96
|
-
apexdocs-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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:
|
|
140
|
+
apexdocs openapi -s force-app -t docs -n MyNamespace --title "My Custom OpenApi Title"
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## 🔬 Defining a configuration file
|
|
144
|
+
|
|
145
|
+
You can also use a configuration file to define the parameters that will be used when generating the documentation.
|
|
146
|
+
|
|
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.
|
|
149
|
+
|
|
150
|
+
### Overview
|
|
151
|
+
|
|
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):
|
|
128
154
|
|
|
129
155
|
- A `package.json` property, e.g. `{ "apexdocs": { "sourceDir": "src", "targetDir": "docs" } }`
|
|
130
156
|
- 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
|
|
157
|
+
- An `apexdocs.config.js` (or `.mjs`) file that exports an object
|
|
132
158
|
- A `apexdocs.config.ts` file that exports an object
|
|
133
159
|
|
|
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
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
160
|
+
**The configuration file should be placed in the root directory of your project.**
|
|
161
|
+
|
|
162
|
+
**Note that when using a configuration file, you can still override any of the parameters by passing them through the
|
|
163
|
+
CLI.**
|
|
164
|
+
|
|
165
|
+
### Configuration file
|
|
166
|
+
|
|
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.:
|
|
169
|
+
|
|
170
|
+
```javascript
|
|
171
|
+
export default {
|
|
172
|
+
sourceDir: 'force-app',
|
|
173
|
+
targetDir: 'docs',
|
|
174
|
+
scope: ['global', 'public'],
|
|
175
|
+
...
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
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.
|
|
181
|
+
|
|
182
|
+
### Config Intellisense
|
|
183
|
+
|
|
184
|
+
Using the `defineMarkdownConfig` helper will provide Typescript-powered intellisense
|
|
185
|
+
for the configuration file options. This should work with both Javascript and Typescript files.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
import { defineMarkdownConfig } from "@cparra/apexdocs";
|
|
189
|
+
|
|
190
|
+
export default defineMarkdownConfig({
|
|
191
|
+
sourceDir: 'force-app',
|
|
192
|
+
targetDir: 'docs',
|
|
193
|
+
scope: ['global', 'public'],
|
|
194
|
+
...
|
|
195
|
+
});
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Configuration Hooks
|
|
199
|
+
|
|
200
|
+
When defining a `.js` or `.ts` configuration file, your object export can also make use
|
|
201
|
+
of different hooks that will be called at different stages of the documentation generation process.
|
|
202
|
+
|
|
203
|
+
All hooks can be async functions, allowing you to make asynchronous operations, like calling an external API.
|
|
204
|
+
|
|
205
|
+
📒 Note: The extension hook functions are only available when generating Markdown files (not OpenApi).
|
|
206
|
+
|
|
207
|
+
#### **transformReferenceGuide**
|
|
208
|
+
|
|
209
|
+
Allows changing the Allows changing the frontmatter and content of the reference guide, or even if creating a reference
|
|
210
|
+
guide page should be skipped.
|
|
211
|
+
|
|
212
|
+
**Type**
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
type TransformReferenceGuide = (referenceGuide: ReferenceGuidePageData) => Partial<ReferenceGuidePageData> | Skip | Promise<Partial<ReferenceGuidePageData> | Skip>;
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Example: Updating the frontmatter
|
|
156
219
|
|
|
157
220
|
```typescript
|
|
158
|
-
import {TargetFile} from "@cparra/apexdocs/lib/settings";
|
|
159
221
|
export default {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
},
|
|
222
|
+
transformReferenceGuide: (referenceGuide) => {
|
|
223
|
+
return {
|
|
224
|
+
// The frontmatter can either be an object, of the frontmatter string itself
|
|
225
|
+
frontmatter: { example: 'example' }
|
|
226
|
+
};
|
|
227
|
+
}
|
|
167
228
|
};
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Example: skipping the reference guide
|
|
168
232
|
|
|
233
|
+
```typescript
|
|
234
|
+
// The skip function is imported from the package
|
|
235
|
+
import { defineMarkdownConfig, skip } from "@cparra/apexdocs";
|
|
236
|
+
|
|
237
|
+
export default defineMarkdownConfig({
|
|
238
|
+
transformReferenceGuide: (referenceGuide) => {
|
|
239
|
+
return skip();
|
|
240
|
+
}
|
|
241
|
+
});
|
|
169
242
|
```
|
|
170
243
|
|
|
171
|
-
|
|
244
|
+
#### **transformDocs**
|
|
245
|
+
|
|
246
|
+
The main purpose of this hook is to allow you to skip the generation of specific pages,
|
|
247
|
+
by returning a filtered array of `DocPageData` objects.
|
|
248
|
+
|
|
249
|
+
If you want to modify the contents or frontmatter of the docs, use the `transformDocPage` hook instead.
|
|
250
|
+
|
|
251
|
+
**Type**
|
|
252
|
+
|
|
253
|
+
```typescript
|
|
254
|
+
type TransformDocs = (docs: DocPageData[]) => DocPageData[] | Promise<DocPageData[]>
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Example
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
export default {
|
|
261
|
+
transformDocs: (docs) => {
|
|
262
|
+
return docs.filter(doc => doc.name !== 'MyClass');
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
#### **transformDocPage**
|
|
268
|
+
|
|
269
|
+
Allows changing the frontmatter and content of the doc page.
|
|
270
|
+
|
|
271
|
+
**Type**
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
type TransformDocPage = (
|
|
275
|
+
doc: DocPageData,
|
|
276
|
+
) => Partial<ConfigurableDocPageData> | Promise<Partial<ConfigurableDocPageData>>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Example
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
export default {
|
|
283
|
+
transformDocPage: (doc) => {
|
|
284
|
+
return {
|
|
285
|
+
frontmatter: { example: 'example' }
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
#### **transformReference**
|
|
292
|
+
|
|
293
|
+
Allows changing where the files are written to and how files are linked to each other.
|
|
294
|
+
|
|
295
|
+
**Type**
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
type TransformReference = (
|
|
299
|
+
reference: DocPageReference,
|
|
300
|
+
) => Partial<ConfigurableDocPageReference> | Promise<ConfigurableDocPageReference>;
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
Example
|
|
304
|
+
|
|
305
|
+
```typescript
|
|
306
|
+
export default {
|
|
307
|
+
// Notice how we are setting the linking strategy to none, so that nothing is done
|
|
308
|
+
// to the links by the tool when it tries to link to other classes
|
|
309
|
+
linkingStrategy: 'none',
|
|
310
|
+
transformReference: (reference) => {
|
|
311
|
+
return {
|
|
312
|
+
// Link to the class in Github instead to its doc page.
|
|
313
|
+
referencePath: `https://github.com/MyOrg/MyRepo/blob/main/src/classes/${reference.name}.cls`
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## ⤵︎ Importing to your project
|
|
172
320
|
|
|
173
321
|
If you are just interested in the Apex parsing capabilities, you can use the
|
|
174
322
|
standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
|
|
175
323
|
which is what gets used by this library behind the scenes to generate the documentation files.
|
|
176
324
|
|
|
177
|
-
|
|
325
|
+
### 👨💻 Typescript
|
|
326
|
+
|
|
327
|
+
If using Typescript, ApexDocs provides all necessary type definitions.
|
|
328
|
+
|
|
329
|
+
## 📖 Documentation Guide
|
|
178
330
|
|
|
179
331
|
ApexDocs picks up blocks of comments throughout your `.cls` files. The block must begin with `/**` and end with `*/`.
|
|
180
332
|
|
|
181
|
-
###
|
|
333
|
+
### Top-level files (classes, interfaces, and enums)
|
|
182
334
|
|
|
183
|
-
The following tags are supported at the
|
|
335
|
+
The following tags are supported at the file level:
|
|
184
336
|
|
|
185
337
|
**Note** Any custom generated tag is also supported. Custom tags can be added with at symbol (`@`) followed by the name
|
|
186
338
|
of the tag. For example `@custom-tag`
|
|
187
339
|
|
|
188
|
-
| Tag | Description
|
|
189
|
-
|
|
190
|
-
| `@description` | One or more lines describing the
|
|
191
|
-
| `@see` | The name of a related
|
|
192
|
-
| `@group` | The group to which the
|
|
193
|
-
| `@author` | The author of the
|
|
194
|
-
| `@date` | The date the
|
|
340
|
+
| Tag | Description |
|
|
341
|
+
|----------------|-----------------------------------------|
|
|
342
|
+
| `@description` | One or more lines describing the file. |
|
|
343
|
+
| `@see` | The name of a related file. |
|
|
344
|
+
| `@group` | The group to which the file belongs to. |
|
|
345
|
+
| `@author` | The author of the file. |
|
|
346
|
+
| `@date` | The date the file was created. |
|
|
347
|
+
| `@example` | Example of how the code can be used. |
|
|
195
348
|
|
|
196
349
|
**Example**
|
|
197
350
|
|
|
@@ -203,30 +356,7 @@ public with sharing class TestClass {
|
|
|
203
356
|
}
|
|
204
357
|
```
|
|
205
358
|
|
|
206
|
-
###
|
|
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
|
-
| `@see` | The name of a related class, enum, or interface. |
|
|
214
|
-
| `@group` | The group to which the enum belongs to. |
|
|
215
|
-
| `@author` | The author of the enum. |
|
|
216
|
-
| `@date` | The date the enum was created. |
|
|
217
|
-
|
|
218
|
-
**Example**
|
|
219
|
-
|
|
220
|
-
```apex
|
|
221
|
-
/**
|
|
222
|
-
* @description This is my enum description.
|
|
223
|
-
*/
|
|
224
|
-
public Enum ExampleEnum {
|
|
225
|
-
VALUE_1, VALUE_2
|
|
226
|
-
}
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
### Documenting Enum Values
|
|
359
|
+
### Enum Values
|
|
230
360
|
|
|
231
361
|
The following tags are supported on the enum value level:
|
|
232
362
|
|
|
@@ -245,9 +375,9 @@ public enum ExampleEnum {
|
|
|
245
375
|
}
|
|
246
376
|
```
|
|
247
377
|
|
|
248
|
-
###
|
|
378
|
+
### Properties and Fields
|
|
249
379
|
|
|
250
|
-
The following tags are supported on the property level:
|
|
380
|
+
The following tags are supported on the property and field level:
|
|
251
381
|
|
|
252
382
|
| Tag | Description |
|
|
253
383
|
|----------------|--------------------------------------------|
|
|
@@ -262,7 +392,7 @@ The following tags are supported on the property level:
|
|
|
262
392
|
public String ExampleProperty { get; set; }
|
|
263
393
|
```
|
|
264
394
|
|
|
265
|
-
###
|
|
395
|
+
### Methods and Constructors
|
|
266
396
|
|
|
267
397
|
Methods and constructors support the same tags.
|
|
268
398
|
|
|
@@ -281,18 +411,43 @@ The following tags are supported on the method level:
|
|
|
281
411
|
**Example**
|
|
282
412
|
|
|
283
413
|
```apex
|
|
284
|
-
/**
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
414
|
+
/**
|
|
415
|
+
* @description This is my method description.
|
|
416
|
+
* @param action The action to execute.
|
|
417
|
+
* @return The result of the operation.
|
|
418
|
+
* @example
|
|
419
|
+
* ```
|
|
420
|
+
* Object result = SampleClass.call('exampleAction');
|
|
421
|
+
* ```
|
|
422
|
+
public static Object call(String action) {
|
|
423
|
+
}
|
|
293
424
|
```
|
|
294
425
|
|
|
295
|
-
###
|
|
426
|
+
### Code Blocks
|
|
427
|
+
|
|
428
|
+
Code blocks can be added to *almost any tag by using the triple backtick syntax. This is useful when you want to display
|
|
429
|
+
code
|
|
430
|
+
snippets with sample usage or examples.
|
|
431
|
+
|
|
432
|
+
*The non-supported tags are the single line tags, like `@param`, `@return`, `@throws`, `@exception`, `@see`, etc*
|
|
433
|
+
|
|
434
|
+
After the triple backticks, you can optionally specify the language of the code block. This defaults to `apex`,
|
|
435
|
+
but it can be useful to override this when displaying code in other languages, such as `javascript` or `soql`.
|
|
436
|
+
|
|
437
|
+
Example
|
|
438
|
+
|
|
439
|
+
```apex
|
|
440
|
+
/**
|
|
441
|
+
* @description This is my method description.
|
|
442
|
+
* @sample-usage
|
|
443
|
+
* This is how you can use this method:
|
|
444
|
+
* ```
|
|
445
|
+
* Object result = SampleClass.call('exampleAction');
|
|
446
|
+
* ```
|
|
447
|
+
*/
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
### Custom Tags
|
|
296
451
|
|
|
297
452
|
You can use custom tags to document your code. Custom tags can be added with at symbol (`@`) followed by the name
|
|
298
453
|
of the tag. Apexdocs will automatically format tags which words are separated by a dash (`-`) by separating them with a
|
|
@@ -311,8 +466,8 @@ display code snippets within your documentation.
|
|
|
311
466
|
* System.debug('Hello World');
|
|
312
467
|
* ```
|
|
313
468
|
*/
|
|
314
|
-
|
|
315
|
-
|
|
469
|
+
public class MyClass {
|
|
470
|
+
}
|
|
316
471
|
```
|
|
317
472
|
|
|
318
473
|
Note that the language of the code block will be set to `apex` by default, but you can change it by adding the language
|
|
@@ -325,43 +480,11 @@ name after the triple backticks. For example, to display a JavaScript code block
|
|
|
325
480
|
* console.log('Hello World');
|
|
326
481
|
* ```
|
|
327
482
|
*/
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
```
|
|
331
|
-
|
|
332
|
-
### Grouping Declarations Within A Class
|
|
333
|
-
|
|
334
|
-
A class might have members that should be grouped together. For example, you can have a class for constants with
|
|
335
|
-
groups of constants that should be grouped together because they share a common behavior (e.g. different groups
|
|
336
|
-
of constants representing the possible values for different picklists.)
|
|
337
|
-
|
|
338
|
-
You can group things together within a class by using the following syntax:
|
|
339
|
-
|
|
340
|
-
```apex
|
|
341
|
-
// @start-group Group Name or Description
|
|
342
|
-
public static final String CONSTANT_FOO = 'Foo';
|
|
343
|
-
public static final String CONSTANT_BAR = 'Bar';
|
|
344
|
-
// @end-group
|
|
483
|
+
public class MyClass {
|
|
484
|
+
}
|
|
345
485
|
```
|
|
346
486
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
Some notes about grouping:
|
|
350
|
-
|
|
351
|
-
* This is only supported on classes, NOT enums and interfaces
|
|
352
|
-
* Supports
|
|
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.
|
|
363
|
-
|
|
364
|
-
### Inline linking
|
|
487
|
+
### Inline Linking
|
|
365
488
|
|
|
366
489
|
Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that
|
|
367
490
|
class file for easy navigation.
|
|
@@ -379,81 +502,63 @@ Apexdocs recognizes 2 different syntax when linking files:
|
|
|
379
502
|
* @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
|
|
380
503
|
* @return The result of the operation.
|
|
381
504
|
*/
|
|
382
|
-
public static Object doSomething(ExampleClass param1) {
|
|
505
|
+
public static Object doSomething(ExampleClass param1) {
|
|
506
|
+
}
|
|
383
507
|
```
|
|
384
508
|
|
|
385
|
-
|
|
509
|
+
#### Email linking
|
|
386
510
|
|
|
387
511
|
Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
|
|
388
512
|
|
|
389
|
-
###
|
|
513
|
+
### Markdown formatting
|
|
390
514
|
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
styling long text.
|
|
515
|
+
You can use Markdown syntax to format your documentation.
|
|
516
|
+
For example, to create bold text, you can use `**bold text**`, and to create a list you can use the `*` character.
|
|
394
517
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
Example
|
|
518
|
+
**Example**
|
|
398
519
|
|
|
399
520
|
```apex
|
|
400
521
|
/**
|
|
401
|
-
* @description
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
406
|
-
*
|
|
522
|
+
* @description This is a description with **bold text**.
|
|
523
|
+
* Which contains a list:
|
|
524
|
+
*
|
|
525
|
+
* **See Also**
|
|
526
|
+
* * [Title](https://example.com)
|
|
527
|
+
* * [Title 2](https://example.com)
|
|
407
528
|
*/
|
|
408
|
-
class MyClass {
|
|
409
|
-
}
|
|
410
529
|
```
|
|
411
530
|
|
|
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.
|
|
427
|
-
|
|
428
|
-
To fix this issue, when not sanitizing HTML, you should wrap any code that contain special characters that can be
|
|
429
|
-
treated as HTML within '\`'
|
|
430
|
-
or within `<code>` tags.
|
|
431
|
-
|
|
432
|
-
### Displaying diagrams
|
|
433
|
-
|
|
434
|
-
You can display diagrams in your documentation by leveraging Github's built-in [Mermaid](https://mermaid-js.github.io/mermaid/#/) support.
|
|
531
|
+
### Grouping Declarations Within A Class
|
|
435
532
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
533
|
+
A class might have members that should be grouped together. For example, you can have a class for constants with
|
|
534
|
+
groups of constants that should be grouped together because they share a common behavior (e.g. different groups
|
|
535
|
+
of constants representing the possible values for different picklists.)
|
|
439
536
|
|
|
440
|
-
|
|
537
|
+
You can group things together within a class by using the following syntax:
|
|
441
538
|
|
|
442
539
|
```apex
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
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
|
-
}
|
|
540
|
+
// @start-group Group Name or Description
|
|
541
|
+
public static final String CONSTANT_FOO = 'Foo';
|
|
542
|
+
public static final String CONSTANT_BAR = 'Bar';
|
|
543
|
+
// @end-group
|
|
454
544
|
```
|
|
455
545
|
|
|
456
|
-
|
|
546
|
+
Groups of members are displayed together under their own subsection after its name or description.
|
|
547
|
+
|
|
548
|
+
Some notes about grouping:
|
|
549
|
+
|
|
550
|
+
* This is only supported on classes, NOT enums and interfaces
|
|
551
|
+
* Supports
|
|
552
|
+
* Properties
|
|
553
|
+
* Fields (variables and constants)
|
|
554
|
+
* Constructors
|
|
555
|
+
* Methods
|
|
556
|
+
* BUT only members of the same type are grouped together. For example,
|
|
557
|
+
if you have a group that contains properties and methods the properties will be grouped together under Properties ->
|
|
558
|
+
Group Name, and the methods will be grouped together under Methods -> Group Name
|
|
559
|
+
* Does not support inner types (inner classes, interfaces, and enums)
|
|
560
|
+
* It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for
|
|
561
|
+
that file.
|
|
457
562
|
|
|
458
563
|
### Ignoring files and members
|
|
459
564
|
|
|
@@ -466,39 +571,44 @@ Example
|
|
|
466
571
|
/**
|
|
467
572
|
* @ignore
|
|
468
573
|
*/
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
574
|
+
public class MyClass {
|
|
575
|
+
public static void myMethod() {
|
|
576
|
+
}
|
|
577
|
+
}
|
|
472
578
|
```
|
|
473
579
|
|
|
474
|
-
## Generating OpenApi REST Definitions
|
|
580
|
+
## 📄 Generating OpenApi REST Definitions
|
|
475
581
|
|
|
476
582
|
ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
|
|
477
583
|
|
|
478
584
|
### Usage
|
|
479
585
|
|
|
480
|
-
To create an OpenApi specification file, run
|
|
481
|
-
When using this generator, you can also pass a custom title through the `--
|
|
482
|
-
in the output file's `info.title` property,
|
|
483
|
-
|
|
586
|
+
To create an OpenApi specification file, run `apexdocs openapi`
|
|
587
|
+
When using this generator, you can also pass a custom title through the `--title` parameter.
|
|
588
|
+
This title will be placed in the output file's `info.title` property,
|
|
589
|
+
as defined by the [OpenApi documentation for the Info Object](https://spec.openapis.org/oas/v3.1.0#info-object)
|
|
484
590
|
|
|
485
591
|
```shell
|
|
486
|
-
apexdocs
|
|
592
|
+
apexdocs openapi -s ./src -t docs --title "Custom OpenApi Title"
|
|
487
593
|
```
|
|
488
594
|
|
|
489
595
|
### How It Works
|
|
490
596
|
|
|
491
|
-
When generating an OpenApi document,
|
|
492
|
-
|
|
597
|
+
When generating an OpenApi document,
|
|
598
|
+
ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
|
|
493
599
|
|
|
494
|
-
Once it finishes running, a file named `openapi.json`
|
|
600
|
+
Once it finishes running, a file named `openapi.json` (unless a different name is specified) will be created
|
|
601
|
+
in the specified `--targetDir`.
|
|
495
602
|
|
|
496
603
|
### Configuring What Gets Created
|
|
497
604
|
|
|
498
605
|
ApexDocs will automatically parse your source code and generate the OpenApi definition based on the HTTP related Apex
|
|
499
|
-
annotations (RestResource
|
|
606
|
+
annotations (`RestResource`, `HttpDelete`, `HttpGet`, `HttpPatch`, `HttpPost`, `HttpGet`). The different HTTP
|
|
607
|
+
annotations will be used to generate a file that complies with
|
|
608
|
+
the [OpenApi Specification v3.1.0](https://spec.openapis.org/oas/v3.1.0)
|
|
500
609
|
|
|
501
|
-
Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs,
|
|
610
|
+
Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs,
|
|
611
|
+
relying on
|
|
502
612
|
some custom annotations that are specific to generating OpenApi definitions:
|
|
503
613
|
|
|
504
614
|
* `@http-request-body`
|
|
@@ -517,6 +627,7 @@ The `schema` can either be a reference to another class in your source code (see
|
|
|
517
627
|
or a fully defined custom schema (See the `Custom Schemas` section below).
|
|
518
628
|
|
|
519
629
|
Example
|
|
630
|
+
|
|
520
631
|
```apex
|
|
521
632
|
/**
|
|
522
633
|
* @description This is a sample HTTP Post method
|
|
@@ -524,10 +635,10 @@ Example
|
|
|
524
635
|
* description: This is an example of a request body
|
|
525
636
|
* required: true
|
|
526
637
|
* schema: ClassName
|
|
527
|
-
*/
|
|
638
|
+
*/
|
|
528
639
|
@HttpPost
|
|
529
640
|
global static void doPost() {
|
|
530
|
-
|
|
641
|
+
///...
|
|
531
642
|
}
|
|
532
643
|
```
|
|
533
644
|
|
|
@@ -543,6 +654,7 @@ whether it is `required` or not, a `description`, and a `schema`.
|
|
|
543
654
|
📝 Note that you can specify as many `@http-parameter` annotations as needed.
|
|
544
655
|
|
|
545
656
|
Example
|
|
657
|
+
|
|
546
658
|
```apex
|
|
547
659
|
/**
|
|
548
660
|
* @description This is a sample HTTP Post method
|
|
@@ -566,11 +678,12 @@ global static String doPost() {
|
|
|
566
678
|
```
|
|
567
679
|
|
|
568
680
|
📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
|
|
569
|
-
|
|
681
|
+
so spacing is important.
|
|
570
682
|
|
|
571
683
|
#### @http-response
|
|
572
684
|
|
|
573
|
-
Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response
|
|
685
|
+
Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response
|
|
686
|
+
code,
|
|
574
687
|
a `description`, and a `schema`.
|
|
575
688
|
|
|
576
689
|
If no `description` is provided then one will be automatically built using the `statusCode`.
|
|
@@ -599,50 +712,56 @@ global static String doPost() {
|
|
|
599
712
|
#### Class References
|
|
600
713
|
|
|
601
714
|
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
|
|
715
|
+
class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi
|
|
716
|
+
definition.
|
|
603
717
|
|
|
604
|
-
The tool will parse the class and create a reference that complies
|
|
718
|
+
The tool will parse the class and create a reference that complies
|
|
719
|
+
with [Apex's support for User-Defined Types](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_methods.htm#ApexRESTUserDefinedTypes)
|
|
605
720
|
|
|
606
721
|
##### Reference Overrides
|
|
607
722
|
|
|
608
|
-
When dealing with references, there might be cases when you want to manually tell the parser what type of object a
|
|
723
|
+
When dealing with references, there might be cases when you want to manually tell the parser what type of object a
|
|
724
|
+
property
|
|
609
725
|
or field is. For example, let's say we have a class that looks as follows
|
|
610
726
|
|
|
611
727
|
```apex
|
|
612
728
|
public class MyClass {
|
|
613
|
-
|
|
614
|
-
|
|
729
|
+
public Object myObject;
|
|
730
|
+
public Account myAccountRecord;
|
|
615
731
|
}
|
|
616
732
|
```
|
|
617
733
|
|
|
618
734
|
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
|
|
735
|
+
parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any
|
|
736
|
+
properties.
|
|
620
737
|
|
|
621
|
-
To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override
|
|
622
|
-
|
|
738
|
+
To accurately represent the shape of these objects, you can use the `@http-schema` annotation to essentially override
|
|
739
|
+
its
|
|
740
|
+
type during parsing. In this annotation you can specify the same thing you would in any `schema` property when dealing
|
|
741
|
+
with any
|
|
623
742
|
of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
|
|
624
743
|
|
|
625
744
|
```apex
|
|
626
745
|
public class MyClass {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
746
|
+
/**
|
|
747
|
+
* @description This is a generic reference to another class
|
|
748
|
+
* @http-schema MyOtherClassName
|
|
749
|
+
*/
|
|
750
|
+
public Object myObject;
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* @description This is a reference to an Account SObject
|
|
754
|
+
* @http-schema
|
|
755
|
+
* type: object
|
|
756
|
+
* properties:
|
|
757
|
+
* Id:
|
|
758
|
+
* type: string
|
|
759
|
+
* Name:
|
|
760
|
+
* type: string
|
|
761
|
+
* CustomField__c:
|
|
762
|
+
* type: number
|
|
763
|
+
*/
|
|
764
|
+
public Account myAccountRecord;
|
|
646
765
|
}
|
|
647
766
|
```
|
|
648
767
|
|
|
@@ -652,7 +771,8 @@ If dealing with a collection, you can also specify the name of the reference eit
|
|
|
652
771
|
|
|
653
772
|
📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
|
|
654
773
|
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
|
|
774
|
+
on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a
|
|
775
|
+
referenced
|
|
656
776
|
class as part of your codebase.
|
|
657
777
|
|
|
658
778
|
Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
|
|
@@ -667,12 +787,13 @@ to convert that to a valid specification. For this use case, define a Custom Sch
|
|
|
667
787
|
*/
|
|
668
788
|
@HttpPost
|
|
669
789
|
global static void doPost() {
|
|
670
|
-
|
|
790
|
+
///...
|
|
671
791
|
}
|
|
672
792
|
```
|
|
673
793
|
|
|
674
794
|
Inner class references are also supported, but note that you need to pass the full name of the reference,
|
|
675
|
-
by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP
|
|
795
|
+
by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP
|
|
796
|
+
method
|
|
676
797
|
referencing it.
|
|
677
798
|
|
|
678
799
|
```apex
|
|
@@ -684,18 +805,20 @@ referencing it.
|
|
|
684
805
|
*/
|
|
685
806
|
@HttpPost
|
|
686
807
|
global static void doPost() {
|
|
687
|
-
|
|
808
|
+
///...
|
|
688
809
|
}
|
|
689
810
|
```
|
|
690
811
|
|
|
691
812
|
#### Custom Schemas
|
|
692
813
|
|
|
693
814
|
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
|
|
815
|
+
can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an
|
|
816
|
+
`array`
|
|
695
817
|
|
|
696
818
|
**Primitives**
|
|
697
819
|
|
|
698
|
-
For primitives, you should specify the `type` and an optional `format`, as defined by
|
|
820
|
+
For primitives, you should specify the `type` and an optional `format`, as defined by
|
|
821
|
+
the [OpenApi Specification on Data Types](https://spec.openapis.org/oas/v3.1.0#data-types)
|
|
699
822
|
|
|
700
823
|
```apex
|
|
701
824
|
/**
|
|
@@ -752,28 +875,22 @@ not reach into your org to get existing SObject describes. Because of this, when
|
|
|
752
875
|
you should create a Custom Schema as defined above. This will also allow you to specify which specific
|
|
753
876
|
fields are being received or returned.
|
|
754
877
|
|
|
755
|
-
|
|
756
878
|
### Considerations
|
|
757
879
|
|
|
758
880
|
Please be aware of the following when using ApexDocs to create an OpenApi definition:
|
|
759
881
|
|
|
760
|
-
* Map references are resolved as `object` with no properties, as it is not possible to know which keys the map will
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
SObjects,
|
|
882
|
+
* Map references are resolved as `object` with no properties, as it is not possible to know which keys the map will
|
|
883
|
+
contain.
|
|
884
|
+
When using maps either create a class that better represents the shape of the object and use a Class Reference, or
|
|
885
|
+
define a Custom Schema in the `schema` section of the ApexDoc itself.
|
|
886
|
+
* Same thing when referencing SObjects, as SObject describe parsing is not supported by the ApexDocs tool. When
|
|
887
|
+
referencing
|
|
888
|
+
SObjects, consider defining a Custom Schema in the `schema` section of the ApexDoc.
|
|
765
889
|
* 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
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
## Typescript
|
|
772
|
-
|
|
773
|
-
ApexDocs provides all necessary type definitions.
|
|
774
|
-
|
|
775
|
-
---
|
|
890
|
+
code that lives outside your source code is not supported. Consider creating a Custom Schema for those situations.
|
|
891
|
+
* The return value and received parameters or your methods are currently not being considered when creating the OpenApi
|
|
892
|
+
definition file.
|
|
893
|
+
Instead, use the `@http-response` ApexDoc annotation to specify the return value, and `@http-parameter` to specify any
|
|
894
|
+
expected parameter.
|
|
776
895
|
|
|
777
|
-
## 1.X
|
|
778
896
|
|
|
779
|
-
Looking for documentation for version 1.X? Please refer to its [branch](https://github.com/cesarParra/apexdocs/tree/1.x)
|