|
| 1 | +# Usage |
| 2 | + |
| 3 | +## SourceCode Annotation |
| 4 | + |
| 5 | +The program works by identifying markers in the source code, and extracing them and sorting them based on ancestral precedence - i.e. who is a parent/child/grandchild. |
| 6 | + |
| 7 | +### Markers and Annotation |
| 8 | + |
| 9 | +Markers have to be used in the exact form, beginning `//+gendoc annotationKey=annotationVal` and end `//-gendoc`. |
| 10 | + |
| 11 | +### Tips |
| 12 | + |
| 13 | +You can do multiline annotations by adding `\` before a line break e.g. |
| 14 | + |
| 15 | +```csharp |
| 16 | +public class Bar() { |
| 17 | + /* |
| 18 | + //+gendoc category=message \ |
| 19 | + type=example |
| 20 | + */ |
| 21 | + public class Foo() { |
| 22 | + |
| 23 | + } |
| 24 | + //-gendoc |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +## CLI |
| 29 | + |
| 30 | +Download the published binary from [here](TODO). |
| 31 | + |
| 32 | +> replace `darwin` in `.../gendoc-darwin/overview` for your platform = `linux|windows|darwin` |
| 33 | +
|
| 34 | +```sh |
| 35 | +chmod +x ./gendoc-$PLATFORM |
| 36 | +mv ./gendoc-$PLATFORM /usr/local/bin/gendoc |
| 37 | +``` |
| 38 | + |
| 39 | +After moving to a location which is on your $PATH, you should be able to run the following commands. |
| 40 | + |
| 41 | +The CLI comes with the following commands, for furher info and help use the `--help|-h` flag at any point. |
| 42 | + |
| 43 | +```bash |
| 44 | +gendoc -h |
| 45 | +gendoc --version |
| 46 | +``` |
| 47 | + |
| 48 | +### Commands |
| 49 | + |
| 50 | +The CLI has 2 main commands that are run either against a single repo that generates the interim output and the command that reads in the interim output and generates the AsyncAPI compliant document. |
| 51 | + |
| 52 | +- `--input`|`--output` options currently support 2 types of `"storage implementation"` |
| 53 | + - `local://` => pointing to a local filesystem |
| 54 | + - `azblob://` => pointing to an Azure storageaccount/blob in this format `azblob://STORAGE_ACCOUNT_NAME/CONTAINER_NAME`. The utility handles the virtual path and object creation. |
| 55 | + - additional `storageClients` can be added easily by providing a new implementation on the storageAdapter |
| 56 | + |
| 57 | +For ease of use, you can enable shell completion for your shell. |
| 58 | + |
| 59 | +`gendoc completion -h` to see the options, e.g. for powershell `gendoc completion powershell` |
| 60 | + |
| 61 | +>Not tested on Windows, users may need to suffix the binary with `.exe`. |
| 62 | +
|
| 63 | +#### SingleContext |
| 64 | + |
| 65 | +This command is run against a single directory which holds source code of any type and generates an interim output. |
| 66 | + |
| 67 | +It can be run in validate only mode by setting `--dry-run` flag, it will ensure that any annotations that have been added are set correctly and there is no syntax errors. |
| 68 | + |
| 69 | +```sh |
| 70 | +gendoc single-context --input local:///path/to/src/domain.sample --output local:///path/to/out/interim --is-service --verbose --dry-run |
| 71 | +``` |
| 72 | + |
| 73 | +If any errors occur they are returned to the terminal. In dry-run mode no files are emitted to the output location. |
| 74 | + |
| 75 | +```sh |
| 76 | +gendoc single-context --input local:///path/to/src/domain.sample --output local:///path/to/out/interim --is-service --business-ctx s2s --business-domain domain |
| 77 | +``` |
| 78 | + |
| 79 | +`--business-ctx` and `--business-domain` are purely for tagging/description/name generation purposes |
| 80 | + |
| 81 | +> Currently `--input` for single-context can only be a `local://` i.e. stored on the local filesystem |
| 82 | +
|
| 83 | +##### EnvVariable expansion |
| 84 | + |
| 85 | +The content can include environment variable like text to avoid repetition, however it will fail if the variable is not set. |
| 86 | + |
| 87 | +Example: |
| 88 | + |
| 89 | +```text |
| 90 | +//+gendoc category=message type=description id=foo |
| 91 | +this is some description with $foo |
| 92 | +//-gendoc |
| 93 | +``` |
| 94 | + |
| 95 | +Ensure that the environment variable is present otherwise it will fail with either an `unset` or `set but empty` error. |
| 96 | + |
| 97 | +See tests for [more examples](../src/go/async-api-gen-doc/internal/parser/parser_test.go) |
| 98 | + |
| 99 | +#### GlobalContext |
| 100 | + |
| 101 | +This command is run against a directory containing zero or more interim output files from generated from across many repos or (single-context sources). |
| 102 | + |
| 103 | +```sh |
| 104 | +gendoc global-context --input local:///path/to/src/domain.sample --output local:///path/to/out/interim |
| 105 | +``` |
| 106 | + |
| 107 | +### Local Example |
| 108 | + |
| 109 | +Point it to an input directory of any repo - e.g. `domain.Packing.DirectDespatchAggregation`. |
| 110 | + |
| 111 | +This will generate the interim code that the |
| 112 | + |
| 113 | +```sh |
| 114 | +gendoc single-context --input local://$FULL_PATH_TO/domain.Packing.DirectDespatchAggregation --is-service --bounded-ctx Packing --business-domain domain \ |
| 115 | +--repo "https://github.com/repo" \ |
| 116 | +--output local://$HOME/.gendoc/poc |
| 117 | +``` |
| 118 | + |
| 119 | +The output will be populated with a directory called `current` which will include the interim output(s) from the single-context runs. |
| 120 | + |
| 121 | +This is then used as in input for the global-context and it will output a full AsyncAPI document in the output directory in this case `local://$HOME/.gendoc/poc/processed` here. |
| 122 | + |
| 123 | +```sh |
| 124 | +gendoc global-context --input local://$HOME/.gendoc/poc/current --output local://$HOME/.gendoc/poc/processed |
| 125 | +``` |
| 126 | + |
| 127 | +The files are emitted with the `AsyncAPI.ID` as the name in the `asyncapi` directory, e.g.: `asyncapi/urn:domain:Packing:domain.Packing.DirectDespatchAggregation.yml`. |
0 commit comments