@cparra/apexdocs 3.0.0-rc.0 → 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.
Files changed (107) hide show
  1. package/README.md +50 -571
  2. package/dist/cli/generate.js +73 -3094
  3. package/dist/defaults-BcE8DTat.js +13 -0
  4. package/dist/defaults-D07y_bq4.js +40 -0
  5. package/dist/defaults-gPzwP66p.js +14 -0
  6. package/dist/index.d.ts +35 -3
  7. package/dist/index.js +90 -2
  8. package/dist/logger-BEbUIfqN.js +3282 -0
  9. package/dist/logger-BGuf1PnL.js +3281 -0
  10. package/dist/logger-CWBRF2za.js +3284 -0
  11. package/dist/logger-CdBmDEN1.js +3283 -0
  12. package/dist/logger-Ce4QqPFR.js +3278 -0
  13. package/dist/logger-CyEVYaAC.js +3284 -0
  14. package/dist/logger-D7a83ycP.js +3277 -0
  15. package/dist/logger-DGaHeBKk.js +3279 -0
  16. package/dist/logger-Dqhl_lO_.js +3278 -0
  17. package/dist/logger-aySSWi0G.js +3280 -0
  18. package/dist/logger-qLCcAtiy.js +3284 -0
  19. package/examples/README.md +5 -0
  20. package/examples/docsify/README.md +17 -0
  21. package/examples/docsify/apexdocs.config.ts +13 -0
  22. package/examples/docsify/classes/ASampleClass.cls +57 -0
  23. package/examples/docsify/classes/CodeControl.cls +19 -0
  24. package/examples/docsify/classes/SampleClass.cls +95 -0
  25. package/examples/docsify/classes/SampleInterface.cls +17 -0
  26. package/examples/docsify/classes/SomeDto.cls +122 -0
  27. package/examples/docsify/docs/.nojekyll +0 -0
  28. package/examples/docsify/docs/README.md +25 -0
  29. package/examples/docsify/docs/_config.yml +1 -0
  30. package/examples/docsify/docs/index.html +22 -0
  31. package/examples/docsify/docs/miscellaneous/ASampleClass.md +88 -0
  32. package/examples/docsify/docs/miscellaneous/CodeControl.md +107 -0
  33. package/examples/docsify/docs/miscellaneous/SomeDto.md +244 -0
  34. package/examples/docsify/docs/sample-classes/SampleClass.md +171 -0
  35. package/examples/docsify/docs/sample-interfaces/SampleInterface.md +36 -0
  36. package/examples/docsify/package-lock.json +2459 -0
  37. package/examples/docsify/package.json +14 -0
  38. package/examples/imported/.forceignore +12 -0
  39. package/examples/imported/README.md +6 -0
  40. package/examples/imported/config/project-scratch-def.json +5 -0
  41. package/examples/imported/docs/index.md +109 -0
  42. package/examples/imported/docs/miscellaneous/BaseClass.md +13 -0
  43. package/examples/imported/docs/miscellaneous/MultiInheritanceClass.md +69 -0
  44. package/examples/imported/docs/miscellaneous/ParentInterface.md +12 -0
  45. package/examples/imported/docs/miscellaneous/ReferencedEnum.md +5 -0
  46. package/examples/imported/docs/miscellaneous/SampleException.md +21 -0
  47. package/examples/imported/docs/miscellaneous/SampleInterface.md +113 -0
  48. package/examples/imported/docs/miscellaneous/Url.md +308 -0
  49. package/examples/imported/docs/sample-enums/SampleEnum.md +33 -0
  50. package/examples/imported/docs/samplegroup/SampleClass.md +167 -0
  51. package/examples/imported/force-app/classes/BaseClass.cls +3 -0
  52. package/examples/imported/force-app/classes/MultiInheritanceClass.cls +1 -0
  53. package/examples/imported/force-app/classes/ParentInterface.cls +3 -0
  54. package/examples/imported/force-app/classes/ReferencedEnum.cls +3 -0
  55. package/examples/imported/force-app/classes/SampleClass.cls +72 -0
  56. package/examples/imported/force-app/classes/SampleInterface.cls +50 -0
  57. package/examples/imported/force-app/classes/Url.cls +196 -0
  58. package/examples/imported/package-lock.json +665 -0
  59. package/examples/imported/package.json +6 -0
  60. package/examples/imported/scripts/process-docs.mjs +16 -0
  61. package/examples/imported/sfdx-project.json +12 -0
  62. package/examples/markdown/README.md +7 -0
  63. package/examples/markdown-jsconfig/README.md +9 -0
  64. package/examples/markdown-jsconfig/apexdocs.config.mjs +1 -0
  65. package/examples/markdown-jsconfig/docs/index.md +1 -1
  66. package/examples/open-api/README.md +5 -0
  67. package/examples/open-api/docs/openapi.json +2 -570
  68. package/examples/vitepress/README.md +25 -0
  69. package/examples/vitepress/apexdocs.config.ts +2 -0
  70. package/examples/vitepress/force-app/main/default/classes/{SampleClass.cls → feature-a/SampleClass.cls} +1 -0
  71. package/examples/vitepress/force-app/main/default/classes/feature-a/SampleEnum.cls +30 -0
  72. package/examples/vitepress/force-app/main/default/classes/feature-a/SampleException.cls +17 -0
  73. package/package.json +2 -2
  74. package/src/application/Apexdocs.ts +16 -19
  75. package/src/application/__tests__/apex-file-reader.spec.ts +108 -67
  76. package/src/application/apex-file-reader.ts +1 -0
  77. package/src/application/generators/openapi.ts +17 -13
  78. package/src/cli/args.ts +12 -3
  79. package/src/cli/commands/markdown.ts +14 -9
  80. package/src/cli/commands/openapi.ts +5 -5
  81. package/src/cli/generate.ts +20 -4
  82. package/src/core/markdown/__test__/generating-class-docs.spec.ts +14 -257
  83. package/src/core/markdown/__test__/generating-docs.spec.ts +271 -4
  84. package/src/core/markdown/__test__/generating-enum-docs.spec.ts +4 -264
  85. package/src/core/markdown/__test__/generating-interface-docs.spec.ts +4 -232
  86. package/src/core/markdown/__test__/generating-reference-guide.spec.ts +17 -1
  87. package/src/core/markdown/__test__/test-helpers.ts +3 -1
  88. package/src/core/markdown/adapters/__tests__/interface-adapter.spec.ts +3 -1
  89. package/src/core/markdown/adapters/renderable-to-page-data.ts +6 -4
  90. package/src/core/markdown/generate-docs.ts +13 -15
  91. package/src/core/markdown/reflection/__test__/filter-scope.spec.ts +2 -18
  92. package/src/core/markdown/reflection/__test__/helpers.ts +18 -0
  93. package/src/core/markdown/reflection/__test__/remove-excluded-tags.spec.ts +200 -0
  94. package/src/core/markdown/reflection/remove-excluded-tags.ts +168 -0
  95. package/src/core/markdown/reflection/{sort-members.ts → sort-types-and-members.ts} +7 -5
  96. package/src/core/markdown/templates/reference-guide.ts +2 -2
  97. package/src/core/openapi/__tests__/open-api-docs-processor.spec.ts +6 -3
  98. package/src/core/openapi/open-api-docs-processor.ts +3 -3
  99. package/src/core/openapi/parser.ts +5 -2
  100. package/src/core/shared/types.d.ts +4 -2
  101. package/src/defaults.ts +15 -3
  102. package/src/index.ts +65 -4
  103. package/src/util/error-logger.ts +36 -36
  104. package/src/util/logger.ts +18 -11
  105. /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleEnum.cls +0 -0
  106. /package/examples/{vitepress/force-app/main/default → imported/force-app}/classes/SampleException.cls +0 -0
  107. /package/examples/vitepress/force-app/main/default/classes/{SampleInterface.cls → feature-a/SampleInterface.cls} +0 -0
package/README.md CHANGED
@@ -78,16 +78,16 @@ Here are some live projects using ApexDocs:
78
78
 
79
79
  ### Flags
80
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 |
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 |
91
91
 
92
92
  #### Linking Strategy
93
93
 
@@ -181,7 +181,8 @@ CLI will be used, or the default value will be used.
181
181
 
182
182
  ### Config Intellisense
183
183
 
184
- Using the `defineMarkdownConfig` helper will provide Typescript-powered intellisense
184
+ Using the `defineMarkdownConfig` (or the `defineOpenApiConfig` for OpenApi documentation)
185
+ helper will provide Typescript-powered intellisense
185
186
  for the configuration file options. This should work with both Javascript and Typescript files.
186
187
 
187
188
  ```typescript
@@ -195,6 +196,23 @@ export default defineMarkdownConfig({
195
196
  });
196
197
  ```
197
198
 
199
+ ### Excluding Tags from Appearing in the Documentation
200
+
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.
203
+
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
+ });
214
+ ```
215
+
198
216
  ### Configuration Hooks
199
217
 
200
218
  When defining a `.js` or `.ts` configuration file, your object export can also make use
@@ -318,579 +336,40 @@ export default {
318
336
 
319
337
  ## ⤵︎ Importing to your project
320
338
 
339
+ ### Reflection
340
+
321
341
  If you are just interested in the Apex parsing capabilities, you can use the
322
342
  standalone [Apex Reflection Library](https://www.npmjs.com/package/@cparra/apex-reflection)
323
343
  which is what gets used by this library behind the scenes to generate the documentation files.
324
344
 
325
- ### 👨‍💻 Typescript
326
-
327
- If using Typescript, ApexDocs provides all necessary type definitions.
328
-
329
- ## 📖 Documentation Guide
330
-
331
- ApexDocs picks up blocks of comments throughout your `.cls` files. The block must begin with `/**` and end with `*/`.
332
-
333
- ### Top-level files (classes, interfaces, and enums)
334
-
335
- The following tags are supported at the file level:
336
-
337
- **Note** Any custom generated tag is also supported. Custom tags can be added with at symbol (`@`) followed by the name
338
- of the tag. For example `@custom-tag`
339
-
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. |
348
-
349
- **Example**
350
-
351
- ```apex
352
- /**
353
- * @description This is my class description.
354
- */
355
- public with sharing class TestClass {
356
- }
357
- ```
358
-
359
- ### Enum Values
360
-
361
- The following tags are supported on the enum value level:
362
-
363
- | Tag | Description |
364
- |----------------|-----------------------------------------|
365
- | `@description` | One or more lines describing the value. |
366
-
367
- **Example**
368
-
369
- ```apex
370
- public enum ExampleEnum {
371
- /** @description This is my enum value description. */
372
- VALUE_1,
373
- /** @description This is my other enum value description. */
374
- VALUE_2
375
- }
376
- ```
377
-
378
- ### Properties and Fields
379
-
380
- The following tags are supported on the property and field level:
381
-
382
- | Tag | Description |
383
- |----------------|--------------------------------------------|
384
- | `@description` | One or more lines describing the property. |
385
-
386
- **Example**
387
-
388
- ```apex
389
- /**
390
- * @description This is my property description.
391
- */
392
- public String ExampleProperty { get; set; }
393
- ```
394
-
395
- ### Methods and Constructors
396
-
397
- Methods and constructors support the same tags.
398
-
399
- The following tags are supported on the method level:
400
-
401
- | Tag | Description |
402
- |------------------------------|---------------------------------------------------|
403
- | `@description` | One or more lines describing the method. |
404
- | `@param` _paramName_ | Description of a single parameter. |
405
- | `@return` | Description of the return value of the method. |
406
- | `@example` | Example of how the code can be used or called. |
407
- | `@throws` _ExceptionName_ | Description of an exception thrown by the method. |
408
- | `@exception` _ExceptionName_ | Same as `@throws`. V2 only |
409
- | `@mermaid` | Diagrams in Mermaid format. |
410
-
411
- **Example**
412
-
413
- ```apex
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
- }
424
- ```
425
-
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
451
-
452
- You can use custom tags to document your code. Custom tags can be added with at symbol (`@`) followed by the name
453
- of the tag. Apexdocs will automatically format tags which words are separated by a dash (`-`) by separating them with a
454
- space and uppercasing them. For example, `@custom-tag` will be displayed as `Custom Tag`.
455
-
456
- Within a custom tag, you can also add code blocks by using the triple backtick syntax. This is useful when you want to
457
- display code snippets within your documentation.
458
-
459
- **Example**
460
-
461
- ```apex
462
- /**
463
- * @custom-tag This is a custom tag
464
- * @custom-tag-with-code
465
- * ```
466
- * System.debug('Hello World');
467
- * ```
468
- */
469
- public class MyClass {
470
- }
471
- ```
472
-
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
474
- name after the triple backticks. For example, to display a JavaScript code block you can use:
475
-
476
- ```apex
477
- /**
478
- * @custom-tag-with-code
479
- * ```javascript
480
- * console.log('Hello World');
481
- * ```
482
- */
483
- public class MyClass {
484
- }
485
- ```
486
-
487
- ### Inline Linking
488
-
489
- Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that
490
- class file for easy navigation.
491
-
492
- Apexdocs recognizes 2 different syntax when linking files:
493
-
494
- - Javadoc's `{@link FileName}` syntax
495
- - A class name wrapped in between `<<` `>>`.
496
-
497
- **Example**
498
-
499
- ```apex
500
- /**
501
- * @description This is my method description. This method receives an <<ExampleClass>>.
502
- * @param param1 An <<ExampleClass>> instance. Can also do {@link ExampleClass}
503
- * @return The result of the operation.
504
- */
505
- public static Object doSomething(ExampleClass param1) {
506
- }
507
- ```
508
-
509
- #### Email linking
345
+ ### Processing
510
346
 
511
- Email addresses can also be inlined linked by using the `{@email EMAIL_ADDRESS}` syntax.
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.
512
349
 
513
- ### Markdown formatting
514
-
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.
517
-
518
- **Example**
519
-
520
- ```apex
521
- /**
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)
528
- */
529
- ```
530
-
531
- ### Grouping Declarations Within A Class
532
-
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.)
536
-
537
- You can group things together within a class by using the following syntax:
350
+ ```typescript
351
+ import { process } from '@cparra/apexdocs';
538
352
 
539
- ```apex
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
353
+ process({
354
+ sourceDir: 'force-app',
355
+ targetDir: 'docs',
356
+ scope: ['global', 'public'],
357
+ ...
358
+ });
544
359
  ```
545
360
 
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.
562
-
563
- ### Ignoring files and members
361
+ ### 👨‍💻 Typescript
564
362
 
565
- You can ignore files and members by using the `@ignore` tag on any ApexDoc block. If used at the class level, the entire
566
- file will be ignored. If used at the member level, only that member will be ignored.
363
+ If using Typescript, ApexDocs provides all necessary type definitions.
567
364
 
568
- Example
365
+ ## 📖 Documentation Guide
569
366
 
570
- ```apex
571
- /**
572
- * @ignore
573
- */
574
- public class MyClass {
575
- public static void myMethod() {
576
- }
577
- }
578
- ```
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.
579
369
 
580
370
  ## 📄 Generating OpenApi REST Definitions
581
371
 
582
- ApexDocs supports generating OpenApi 3.1.0 REST definitions based on any `@RestResource` classes in your source code.
583
-
584
- ### Usage
585
-
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)
590
-
591
- ```shell
592
- apexdocs openapi -s ./src -t docs --title "Custom OpenApi Title"
593
- ```
594
-
595
- ### How It Works
596
-
597
- When generating an OpenApi document,
598
- ApexDocs will run through all classes annotated with `@RestResource` and add it to the output OpenApi file.
599
-
600
- Once it finishes running, a file named `openapi.json` (unless a different name is specified) will be created
601
- in the specified `--targetDir`.
602
-
603
- ### Configuring What Gets Created
604
-
605
- ApexDocs will automatically parse your source code and generate the OpenApi definition based on the HTTP related Apex
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)
609
-
610
- Besides these annotations, the ApexDocs tool will also use any information provided through your code's Apexdocs,
611
- relying on
612
- some custom annotations that are specific to generating OpenApi definitions:
613
-
614
- * `@http-request-body`
615
- * `@http-parameter`
616
- * `@http-response`
617
-
618
- #### @http-request-body
619
-
620
- Allows you to specify the HTTP request's expected request body. It supports receiving a `description`,
621
- whether it is `required` or not, and a `schema`, which defines the shape of the object that is expected.
622
-
623
- 📝 Note that only one `@http-request-body` should be defined per method. If you add more than one, only
624
- a single one will be used when generating the OpenApi definition.
625
-
626
- The `schema` can either be a reference to another class in your source code (see the `Class References` section below)
627
- or a fully defined custom schema (See the `Custom Schemas` section below).
628
-
629
- Example
630
-
631
- ```apex
632
- /**
633
- * @description This is a sample HTTP Post method
634
- * @http-request-body
635
- * description: This is an example of a request body
636
- * required: true
637
- * schema: ClassName
638
- */
639
- @HttpPost
640
- global static void doPost() {
641
- ///...
642
- }
643
- ```
644
-
645
- 📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
646
- so spacing is important.
647
-
648
- #### @http-parameter
649
-
650
- Allows you to specify any HTTP parameter expected by your method. It supports receiving a `name`,
651
- an `in` as defined by the supported [Parameter Locations](https://spec.openapis.org/oas/v3.1.0#parameter-locations),
652
- whether it is `required` or not, a `description`, and a `schema`.
653
-
654
- 📝 Note that you can specify as many `@http-parameter` annotations as needed.
655
-
656
- Example
657
-
658
- ```apex
659
- /**
660
- * @description This is a sample HTTP Post method
661
- * @return A String SObject.
662
- * @http-parameter
663
- * name: limit
664
- * in: query
665
- * required: true
666
- * description: Limits the number of items on a page
667
- * schema:
668
- * type: integer
669
- * @http-parameter
670
- * name: complex
671
- * in: cookie
672
- * schema: MyClassName
673
- */
674
- @HttpPost
675
- global static String doPost() {
676
- // ..
677
- }
678
- ```
679
-
680
- 📝 Note that each parameter of this annotation is expected to be on its own line. Parameters are treated as YAML,
681
- so spacing is important.
682
-
683
- #### @http-response
684
-
685
- Allows you to specify any HTTP response returned by your method. It supports receiving a `statusCode` with the response
686
- code,
687
- a `description`, and a `schema`.
688
-
689
- If no `description` is provided then one will be automatically built using the `statusCode`.
690
-
691
- 📝 Note that you can specify as many `@http-parameter` annotations as needed.
692
-
693
- ```apex
694
- /**
695
- * @description This is a sample HTTP Post method
696
- * @return A String SObject.
697
- * @http-response
698
- * statusCode: 200
699
- * schema: SuccessfulResponseClassName
700
- * @http-response
701
- * statusCode: 500
702
- * description: Status Code 500 - An internal server error occurred.
703
- * schema:
704
- * type: string
705
- */
706
- @HttpPost
707
- global static String doPost() {
708
- // ...
709
- }
710
- ```
711
-
712
- #### Class References
713
-
714
- Whenever specifying a `schema` parameter, you can pass as a string the name of any class in your source code. This
715
- class will be parsed by the ApexDocs tool and automatically converted to a reference in the resulting OpenApi
716
- definition.
717
-
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)
720
-
721
- ##### Reference Overrides
722
-
723
- When dealing with references, there might be cases when you want to manually tell the parser what type of object a
724
- property
725
- or field is. For example, let's say we have a class that looks as follows
726
-
727
- ```apex
728
- public class MyClass {
729
- public Object myObject;
730
- public Account myAccountRecord;
731
- }
732
- ```
733
-
734
- In this case `myObject` has a type of `Object`, and `myAccountRecord` is an SObject. Neither of these will be accurately
735
- parsed when building the OpenApi definition, instead they will be simple be referenced as `object` without any
736
- properties.
737
-
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
742
- of the main `@http-*` methods, meaning a reference to another class, or a Custom Schema (as defined below).
743
-
744
- ```apex
745
- public class MyClass {
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;
765
- }
766
- ```
767
-
768
- ---
769
-
770
- If dealing with a collection, you can also specify the name of the reference either using the `List` or `Set` syntax.
771
-
772
- 📝 When using List or Set syntax in the `schema` of the ApexDoc `@http-*` annotation, only collections one level
773
- deep are supported (e.g. List<List<String>> is not supported). This is only a limitation when referencing collections
774
- on the ApexDoc `schema` property directly, and is fully supported when multi-level collections are inside of a
775
- referenced
776
- class as part of your codebase.
777
-
778
- Maps are not supported, as it is not possible to know which keys the map will contain, and thus it is not possible
779
- to convert that to a valid specification. For this use case, define a Custom Schema as explained below.
780
-
781
- ```apex
782
- /**
783
- * @description This is a sample HTTP Post method
784
- * @http-request-body
785
- * description: This is an example of a request body
786
- * schema: List<ClassName>
787
- */
788
- @HttpPost
789
- global static void doPost() {
790
- ///...
791
- }
792
- ```
793
-
794
- Inner class references are also supported, but note that you need to pass the full name of the reference,
795
- by using the `ParentClassName.InnerClassName` syntax, even if the inner class resides on the same class as the HTTP
796
- method
797
- referencing it.
798
-
799
- ```apex
800
- /**
801
- * @description This is a sample HTTP Post method
802
- * @http-request-body
803
- * description: This is an example of a request body
804
- * schema: ParentClass.InnerClass
805
- */
806
- @HttpPost
807
- global static void doPost() {
808
- ///...
809
- }
810
- ```
811
-
812
- #### Custom Schemas
813
-
814
- For any `schema` parameter in any of the HTTP ApexDocs annotations, besides specifying the name of a class, you
815
- can also specify a custom schema definition. The schema definition can either be for a primitive type, an `object` or an
816
- `array`
817
-
818
- **Primitives**
819
-
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)
822
-
823
- ```apex
824
- /**
825
- * ...
826
- * schema:
827
- * type: string
828
- * format: password
829
- */
830
- ```
831
-
832
- **Objects**
833
-
834
- To specify a custom object schema, use `object` as the `type`, and specify as many properties as follows:
835
-
836
- ```apex
837
- /**
838
- * schema:
839
- * type: object
840
- * properties:
841
- * id:
842
- * type: string
843
- * description: The super Id.
844
- * name:
845
- * type: string
846
- * phone:
847
- * type: string
848
- * format: byte
849
- */
850
- ```
851
-
852
- Properties can be defined as primitives (as explained above), other objects, or arrays (explained below)
853
-
854
- **Arrays**
855
-
856
- To specify a custom array schema, use `array` as the `type`, and provide an `items` definition. In `items`
857
- you can specify the definition of any other custom type (primitives, objects, or other arrays).
858
-
859
- ```apex
860
- /**
861
- * schema:
862
- * type: array
863
- * items:
864
- * type: object
865
- * properties:
866
- * name:
867
- * type: string
868
- */
869
- ```
870
-
871
- #### SObject References
872
-
873
- ApexDocs is not able to automatically parse SObject references, as it can with class references, as it does
874
- not reach into your org to get existing SObject describes. Because of this, when dealing with SObject references
875
- you should create a Custom Schema as defined above. This will also allow you to specify which specific
876
- fields are being received or returned.
877
-
878
- ### Considerations
879
-
880
- Please be aware of the following when using ApexDocs to create an OpenApi definition:
881
-
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.
889
- * ApexDoc is only able to parse through your source code, so references to other packages (namespaced classes) or any
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.
895
-
372
+ ApexDocs can also generate OpenApi REST definitions for your Salesforce Apex classes annotated with `@RestResource`.
896
373
 
374
+ See the [wiki](https://github.com/cesarParra/apexdocs/wiki/%F0%9F%93%84-Generating-OpenApi-REST-Definitions)
375
+ for more information.