|
| 1 | +# API Documentation |
| 2 | + |
| 3 | +This document explains how API documentation is generated and published for PolylineAlgorithm. |
| 4 | + |
| 5 | +## Toolchain |
| 6 | + |
| 7 | +Documentation is built with [DocFX](https://dotnet.github.io/docfx/), a static site generator for .NET API references and Markdown guides. |
| 8 | + |
| 9 | +## Repository Layout |
| 10 | + |
| 11 | +``` |
| 12 | +api-reference/ |
| 13 | +├── api-reference.json # DocFX build manifest (site generation) |
| 14 | +├── assembly-metadata.json # DocFX metadata manifest (API extraction only) |
| 15 | +├── toc.yml # Top-level table of contents |
| 16 | +├── index.md # Landing page |
| 17 | +├── favicon.ico |
| 18 | +├── media/ # Images and other static assets |
| 19 | +├── guide/ # Markdown guide articles |
| 20 | +│ ├── toc.yml |
| 21 | +│ ├── introduction.md |
| 22 | +│ ├── getting-started.md |
| 23 | +│ ├── configuration.md |
| 24 | +│ ├── advanced-scenarios.md |
| 25 | +│ ├── sample.md |
| 26 | +│ └── faq.md |
| 27 | +├── 0.0/ # Auto-generated API metadata for version 0.0 |
| 28 | +├── 1.0/ # Auto-generated API metadata for version 1.0 |
| 29 | +│ └── *.yml # DocFX apiPage YAML files (one per type) |
| 30 | +└── _docs/ # Build output (excluded from DocFX content, gitignored) |
| 31 | +``` |
| 32 | + |
| 33 | +## Two DocFX Manifests |
| 34 | + |
| 35 | +### `assembly-metadata.json` — API Extraction |
| 36 | + |
| 37 | +Used by the `documentation/docfx-metadata` composite action during CI builds to extract XML documentation comments from source code and produce DocFX-compatible YAML files. |
| 38 | + |
| 39 | +```json |
| 40 | +{ |
| 41 | + "metadata": [{ |
| 42 | + "src": [{ "src": "../src", "files": ["**/*.csproj"] }], |
| 43 | + "dest": "temp", |
| 44 | + "outputFormat": "apiPage" |
| 45 | + }] |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +- **Input:** All `.csproj` files under `src/` |
| 50 | +- **Output:** YAML files in `api-reference/temp/`, then copied to `api-reference/<version>/` |
| 51 | +- **When it runs:** Automatically after every successful `build` workflow run. The resulting YAML files are committed to the repository under `api-reference/<friendly-version>/` (e.g., `api-reference/1.2/`). |
| 52 | + |
| 53 | +### `api-reference.json` — Site Build |
| 54 | + |
| 55 | +Used by the `documentation/docfx-build` composite action to build the full documentation site. |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "build": { |
| 60 | + "content": [ |
| 61 | + { "files": ["index.md", "toc.yml", "guide/*.{md,yml}"], "exclude": ["_docs/**"] }, |
| 62 | + { "dest": "", "files": ["*.yml"], "group": "v1.0", "src": "1.0" }, |
| 63 | + { "dest": "", "files": ["*.yml"], "group": "v1.1", "src": "1.1" } |
| 64 | + ], |
| 65 | + "output": "_docs", |
| 66 | + "template": ["default", "modern"] |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +- **Input:** Markdown guide articles + versioned API YAML files |
| 72 | +- **Output:** Static HTML site in `api-reference/_docs/` |
| 73 | +- **When it runs:** During `release.yml` (automatic on every push to `preview/**` or `release/**`) and `publish-documentation.yml` (manual trigger). |
| 74 | + |
| 75 | +## Publishing Flow |
| 76 | + |
| 77 | +``` |
| 78 | +src/ changed |
| 79 | + │ |
| 80 | + ▼ |
| 81 | +[build.yml] → docfx metadata → commit YAML to api-reference/<version>/ |
| 82 | + │ |
| 83 | + ▼ |
| 84 | + [release.yml] or [publish-documentation.yml] |
| 85 | + │ |
| 86 | + ▼ |
| 87 | + docfx build → api-reference/_docs/ |
| 88 | + │ |
| 89 | + ▼ |
| 90 | + GitHub Pages → petesramek.github.io/polyline-algorithm-csharp |
| 91 | +``` |
| 92 | + |
| 93 | +## Adding a New Version to the Site |
| 94 | + |
| 95 | +When bumping the version to `X.Y`: |
| 96 | + |
| 97 | +1. The `build` workflow automatically generates metadata YAML files into `api-reference/X.Y/` after the first build on the new branch. |
| 98 | +2. Add a new entry to `api-reference.json` under `build.content`: |
| 99 | + ```json |
| 100 | + { "dest": "", "files": ["*.yml"], "group": "vX.Y", "src": "X.Y", "rootTocPath": "~/toc.html" } |
| 101 | + ``` |
| 102 | +3. Add a matching group definition: |
| 103 | + ```json |
| 104 | + "vX.Y": { "dest": "X.Y" } |
| 105 | + ``` |
| 106 | +4. Add the new version to `api-reference/toc.yml` so it appears in the navigation dropdown: |
| 107 | + ```yaml |
| 108 | + - name: vX.Y |
| 109 | + href: X.Y/PolylineAlgorithm.html |
| 110 | + ``` |
| 111 | +
|
| 112 | +## Writing API Documentation |
| 113 | +
|
| 114 | +All public types, interfaces, and members must have XML doc comments. DocFX picks these up automatically: |
| 115 | +
|
| 116 | +```csharp |
| 117 | +/// <summary> |
| 118 | +/// Encodes a sequence of coordinates into a polyline string. |
| 119 | +/// </summary> |
| 120 | +/// <param name="coordinates">The coordinates to encode.</param> |
| 121 | +/// <returns>An encoded polyline string.</returns> |
| 122 | +public string Encode(IEnumerable<(double Latitude, double Longitude)> coordinates) { ... } |
| 123 | +``` |
| 124 | + |
| 125 | +After merging a change, verify the rendered documentation at the [API Reference Site](https://petesramek.github.io/polyline-algorithm-csharp/). |
| 126 | + |
| 127 | +## Local Preview |
| 128 | + |
| 129 | +To preview the documentation locally: |
| 130 | + |
| 131 | +```bash |
| 132 | +dotnet tool update -g docfx |
| 133 | +docfx build ./api-reference/api-reference.json --serve |
| 134 | +``` |
| 135 | + |
| 136 | +Then open `http://localhost:8080` in your browser. |
0 commit comments