|
| 1 | +# API Documentation Guide |
| 2 | + |
| 3 | +This document explains how to generate and maintain API documentation for the Weaviate C# Client. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The Weaviate C# Client uses XMLDoc comments in the source code to generate API documentation in two formats: |
| 8 | +- **HTML** - Professional, searchable documentation website using DocFX |
| 9 | +- **Markdown** - Simple, portable markdown files |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +### Generate HTML Documentation |
| 14 | + |
| 15 | +```bash |
| 16 | +# macOS/Linux |
| 17 | +./scripts/generate-docs-html.sh |
| 18 | + |
| 19 | +# Windows |
| 20 | +.\scripts\generate-docs-html.ps1 |
| 21 | +``` |
| 22 | + |
| 23 | +Output: `_site/` directory |
| 24 | +View: `docfx serve _site` then open http://localhost:8080 |
| 25 | + |
| 26 | +### Generate Markdown Documentation |
| 27 | + |
| 28 | +```bash |
| 29 | +# macOS/Linux |
| 30 | +./scripts/generate-docs-markdown.sh |
| 31 | + |
| 32 | +# Direct Python call |
| 33 | +python3 scripts/generate-docs-markdown.py src/Weaviate.Client/bin/Release/net9.0/Weaviate.Client.xml docs/api-markdown |
| 34 | +``` |
| 35 | + |
| 36 | +Output: `docs/api-markdown/` directory |
| 37 | +View: `docs/api-markdown/index.md` |
| 38 | + |
| 39 | +## Documentation Status |
| 40 | + |
| 41 | +### Current Coverage |
| 42 | + |
| 43 | +As of this implementation: |
| 44 | +- **Total public types:** 384 |
| 45 | +- **Documented types:** ~36% (including recently added documentation) |
| 46 | +- **XML generation:** Enabled in project file |
| 47 | + |
| 48 | +### Recently Documented (High Priority) |
| 49 | + |
| 50 | +✅ **Model Classes:** |
| 51 | +- `Vector`, `VectorSingle<T>`, `VectorMulti<T>` - Vector data types |
| 52 | +- `Vectors` - Vector collection |
| 53 | +- `Filter`, `PropertyFilter`, `ReferenceFilter` - Filtering system |
| 54 | +- `Sort` - Sort specifications |
| 55 | +- `BatchInsertRequest`, `BatchInsertResponse` - Batch operations |
| 56 | + |
| 57 | +✅ **Infrastructure:** |
| 58 | +- XML documentation file generation enabled in `Weaviate.Client.csproj` |
| 59 | +- DocFX configuration (`docfx.json`) |
| 60 | +- Documentation generation scripts |
| 61 | + |
| 62 | +### To Be Documented |
| 63 | + |
| 64 | +The following high-priority areas still need XMLDoc comments: |
| 65 | + |
| 66 | +**Configuration Classes:** |
| 67 | +- `VectorConfig`, `VectorConfigList` |
| 68 | +- `InvertedIndexConfig` |
| 69 | +- `ShardingConfig` |
| 70 | +- `ReplicationConfig` |
| 71 | +- `MultiTenancyConfig` |
| 72 | +- `BM25Config`, `StopwordConfig` |
| 73 | + |
| 74 | +**Model Classes:** |
| 75 | +- `Property`, `Reference` - Collection schema |
| 76 | +- `Collection`, `CollectionConfig` - Collection configuration |
| 77 | +- `VectorIndex.*` - HNSW, Flat, Dynamic configurations |
| 78 | +- `Vectorizer.*` - All vectorizer variants |
| 79 | +- RBAC models in `Rbac.cs` |
| 80 | + |
| 81 | +**Serialization:** |
| 82 | +- `IPropertyConverter`, `PropertyConverterBase` |
| 83 | +- `PropertyBag`, `PropertyConverterRegistry` |
| 84 | +- Individual property converters |
| 85 | + |
| 86 | +## Project Configuration |
| 87 | + |
| 88 | +### XML Documentation Settings |
| 89 | + |
| 90 | +Location: `src/Weaviate.Client/Weaviate.Client.csproj` |
| 91 | + |
| 92 | +```xml |
| 93 | +<PropertyGroup> |
| 94 | + <!-- Enable XML documentation generation --> |
| 95 | + <GenerateDocumentationFile>true</GenerateDocumentationFile> |
| 96 | + <DocumentationFile>bin\$(Configuration)\$(TargetFramework)\Weaviate.Client.xml</DocumentationFile> |
| 97 | + <!-- Suppress warnings for missing XML comments (remove this line once all public APIs are documented) --> |
| 98 | + <NoWarn>$(NoWarn);CS1591</NoWarn> |
| 99 | +</PropertyGroup> |
| 100 | +``` |
| 101 | + |
| 102 | +**Note:** The `CS1591` warning suppression should be removed once all public APIs are documented. |
| 103 | + |
| 104 | +## Writing XMLDoc Comments |
| 105 | + |
| 106 | +### Basic Structure |
| 107 | + |
| 108 | +```csharp |
| 109 | +/// <summary> |
| 110 | +/// Brief description of the type or member. |
| 111 | +/// </summary> |
| 112 | +/// <remarks> |
| 113 | +/// Detailed explanation, usage notes, or important information. |
| 114 | +/// Can include multiple paragraphs. |
| 115 | +/// </remarks> |
| 116 | +/// <param name="paramName">Description of the parameter.</param> |
| 117 | +/// <returns>Description of the return value.</returns> |
| 118 | +/// <exception cref="ExceptionType">When this exception is thrown.</exception> |
| 119 | +/// <example> |
| 120 | +/// <code> |
| 121 | +/// var example = new MyClass(); |
| 122 | +/// example.DoSomething(); |
| 123 | +/// </code> |
| 124 | +/// </example> |
| 125 | +public class MyClass |
| 126 | +{ |
| 127 | + // Implementation |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +### Key Tags |
| 132 | + |
| 133 | +- `<summary>` - Brief description (required for all public APIs) |
| 134 | +- `<remarks>` - Additional details, usage notes |
| 135 | +- `<param>` - Parameter descriptions |
| 136 | +- `<typeparam>` - Generic type parameter descriptions |
| 137 | +- `<returns>` - Return value description |
| 138 | +- `<exception>` - Exceptions that may be thrown |
| 139 | +- `<example>` - Code examples |
| 140 | +- `<code>` - Code blocks within examples |
| 141 | +- `<see cref=""/>` - Cross-reference to other types/members |
| 142 | +- `<seealso cref=""/>` - Related types/members |
| 143 | + |
| 144 | +### Best Practices |
| 145 | + |
| 146 | +1. **Be Concise** - Summaries should be one or two sentences |
| 147 | +2. **Be Specific** - Describe what the member does, not how it works |
| 148 | +3. **Include Examples** - Especially for complex APIs |
| 149 | +4. **Cross-Reference** - Use `<see cref=""/>` to link related types |
| 150 | +5. **Document Parameters** - Explain purpose, valid values, constraints |
| 151 | +6. **Document Returns** - Describe what is returned and when |
| 152 | +7. **Note Exceptions** - Document all exceptions that can be thrown |
| 153 | + |
| 154 | +### Example from Vector.cs |
| 155 | + |
| 156 | +```csharp |
| 157 | +/// <summary> |
| 158 | +/// Represents a vector for use with Weaviate, supporting both single and multi-vector configurations. |
| 159 | +/// Vectors can contain numeric values of various types (double, float, int, etc.) and can be implicitly converted from native arrays. |
| 160 | +/// </summary> |
| 161 | +/// <remarks> |
| 162 | +/// This is the base class for all vector types in the Weaviate client library. |
| 163 | +/// Use <see cref="VectorSingle{T}"/> for single vectors or <see cref="VectorMulti{T}"/> for multi-vector representations. |
| 164 | +/// Supports implicit conversion from and to native C# arrays. |
| 165 | +/// </remarks> |
| 166 | +public abstract record Vector : IEnumerable, IHybridVectorInput |
| 167 | +{ |
| 168 | + /// <summary> |
| 169 | + /// Gets or initializes the name of this vector. Defaults to "default". |
| 170 | + /// Used to identify specific vectors in multi-vector configurations. |
| 171 | + /// </summary> |
| 172 | + public string Name { get; init; } = "default"; |
| 173 | +} |
| 174 | +``` |
| 175 | + |
| 176 | +## Documentation Generation Scripts |
| 177 | + |
| 178 | +### HTML Generation (DocFX) |
| 179 | + |
| 180 | +**Files:** |
| 181 | +- `scripts/generate-docs-html.sh` - Bash script for macOS/Linux |
| 182 | +- `scripts/generate-docs-html.ps1` - PowerShell script for Windows |
| 183 | +- `docfx.json` - DocFX configuration |
| 184 | +- `api/index.md` - API documentation landing page |
| 185 | + |
| 186 | +**Prerequisites:** |
| 187 | +```bash |
| 188 | +# Install DocFX |
| 189 | +dotnet tool install -g docfx |
| 190 | +``` |
| 191 | + |
| 192 | +**Process:** |
| 193 | +1. Builds the project in Release configuration |
| 194 | +2. Generates XML documentation file |
| 195 | +3. Runs `docfx metadata` to extract API information |
| 196 | +4. Runs `docfx build` to generate HTML site |
| 197 | + |
| 198 | +**Output:** `_site/` directory containing complete HTML documentation |
| 199 | + |
| 200 | +### Markdown Generation (Python) |
| 201 | + |
| 202 | +**Files:** |
| 203 | +- `scripts/generate-docs-markdown.py` - Python script (cross-platform) |
| 204 | +- `scripts/generate-docs-markdown.sh` - Bash wrapper script |
| 205 | + |
| 206 | +**Prerequisites:** |
| 207 | +- Python 3.x (usually pre-installed on macOS/Linux) |
| 208 | + |
| 209 | +**Process:** |
| 210 | +1. Builds the project in Release configuration |
| 211 | +2. Parses the generated XML documentation file |
| 212 | +3. Generates individual markdown files for each type |
| 213 | +4. Creates an index file organized by namespace |
| 214 | + |
| 215 | +**Output:** `docs/api-markdown/` directory with markdown files |
| 216 | + |
| 217 | +## Viewing Documentation |
| 218 | + |
| 219 | +### HTML Documentation |
| 220 | + |
| 221 | +**Local Preview:** |
| 222 | +```bash |
| 223 | +docfx serve _site |
| 224 | +# Open http://localhost:8080 |
| 225 | +``` |
| 226 | + |
| 227 | +**Features:** |
| 228 | +- Full-text search |
| 229 | +- Namespace/type navigation tree |
| 230 | +- Cross-references between types |
| 231 | +- Dark/light theme |
| 232 | +- Responsive design |
| 233 | + |
| 234 | +### Markdown Documentation |
| 235 | + |
| 236 | +**View Locally:** |
| 237 | +- Open `docs/api-markdown/index.md` in any markdown viewer |
| 238 | +- Use VSCode, Typora, or GitHub's markdown preview |
| 239 | +- Or use tools like `grip`: `grip docs/api-markdown/index.md` |
| 240 | + |
| 241 | +**Features:** |
| 242 | +- Simple, portable format |
| 243 | +- Easy to read and version control |
| 244 | +- Compatible with GitHub, GitLab, etc. |
| 245 | + |
| 246 | +## Publishing Documentation |
| 247 | + |
| 248 | +### GitHub Pages |
| 249 | + |
| 250 | +1. Generate HTML documentation: |
| 251 | + ```bash |
| 252 | + ./scripts/generate-docs-html.sh |
| 253 | + ``` |
| 254 | + |
| 255 | +2. Push to `gh-pages` branch: |
| 256 | + ```bash |
| 257 | + git add _site -f |
| 258 | + git subtree push --prefix _site origin gh-pages |
| 259 | + ``` |
| 260 | + |
| 261 | +3. Enable GitHub Pages in repository settings pointing to `gh-pages` branch |
| 262 | + |
| 263 | +### CI/CD Integration |
| 264 | + |
| 265 | +**GitHub Actions Example:** |
| 266 | + |
| 267 | +```yaml |
| 268 | +name: Generate Documentation |
| 269 | + |
| 270 | +on: |
| 271 | + push: |
| 272 | + branches: [main] |
| 273 | + pull_request: |
| 274 | + branches: [main] |
| 275 | + |
| 276 | +jobs: |
| 277 | + docs: |
| 278 | + runs-on: ubuntu-latest |
| 279 | + steps: |
| 280 | + - uses: actions/checkout@v3 |
| 281 | + |
| 282 | + - name: Setup .NET |
| 283 | + uses: actions/setup-dotnet@v3 |
| 284 | + with: |
| 285 | + dotnet-version: '9.0.x' |
| 286 | + |
| 287 | + - name: Install DocFX |
| 288 | + run: dotnet tool install -g docfx |
| 289 | + |
| 290 | + - name: Generate Documentation |
| 291 | + run: ./scripts/generate-docs-html.sh |
| 292 | + |
| 293 | + - name: Deploy to GitHub Pages |
| 294 | + if: github.ref == 'refs/heads/main' |
| 295 | + uses: peaceiris/actions-gh-pages@v3 |
| 296 | + with: |
| 297 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 298 | + publish_dir: ./_site |
| 299 | +``` |
| 300 | +
|
| 301 | +## Maintenance |
| 302 | +
|
| 303 | +### Adding Documentation to New Code |
| 304 | +
|
| 305 | +When adding new public APIs: |
| 306 | +
|
| 307 | +1. **Write XMLDoc comments** following the patterns in this guide |
| 308 | +2. **Build and check warnings** to ensure proper formatting: |
| 309 | + ```bash |
| 310 | + dotnet build --configuration Release |
| 311 | + ``` |
| 312 | +3. **Test documentation generation** to verify output: |
| 313 | + ```bash |
| 314 | + ./scripts/generate-docs-markdown.sh |
| 315 | + ``` |
| 316 | + |
| 317 | +### Updating Existing Documentation |
| 318 | + |
| 319 | +1. Edit XMLDoc comments in source files |
| 320 | +2. Rebuild the project |
| 321 | +3. Regenerate documentation |
| 322 | +4. Review changes in generated files |
| 323 | + |
| 324 | +### Removing CS1591 Warning Suppression |
| 325 | + |
| 326 | +Once all public APIs are documented: |
| 327 | + |
| 328 | +1. Remove `<NoWarn>$(NoWarn);CS1591</NoWarn>` from `Weaviate.Client.csproj` |
| 329 | +2. Build and fix any remaining warnings about missing documentation |
| 330 | +3. Enable this as a CI check to enforce documentation on new code |
| 331 | + |
| 332 | +## Troubleshooting |
| 333 | + |
| 334 | +### XML File Not Generated |
| 335 | + |
| 336 | +**Problem:** Documentation scripts report missing XML file |
| 337 | + |
| 338 | +**Solution:** |
| 339 | +1. Ensure `GenerateDocumentationFile` is `true` in project file |
| 340 | +2. Build in Release configuration: `dotnet build --configuration Release` |
| 341 | +3. Check for build errors |
| 342 | + |
| 343 | +### DocFX Not Found |
| 344 | + |
| 345 | +**Problem:** `docfx: command not found` |
| 346 | + |
| 347 | +**Solution:** |
| 348 | +```bash |
| 349 | +dotnet tool install -g docfx |
| 350 | +# Or update: dotnet tool update -g docfx |
| 351 | +``` |
| 352 | + |
| 353 | +### Python Not Found |
| 354 | + |
| 355 | +**Problem:** `python3: command not found` (Windows) |
| 356 | + |
| 357 | +**Solution:** |
| 358 | +- Download and install Python from [python.org](https://www.python.org/downloads/) |
| 359 | +- Ensure "Add Python to PATH" is checked during installation |
| 360 | + |
| 361 | +### Warnings About Missing Documentation |
| 362 | + |
| 363 | +**Problem:** CS1591 warnings during build |
| 364 | + |
| 365 | +**Status:** Expected - these indicate undocumented public APIs |
| 366 | + |
| 367 | +**Solution:** |
| 368 | +- Add XMLDoc comments to the reported types/members |
| 369 | +- Or keep `CS1591` suppressed in `NoWarn` (current configuration) |
| 370 | + |
| 371 | +## Resources |
| 372 | + |
| 373 | +### Documentation Tools |
| 374 | + |
| 375 | +- **DocFX:** https://dotnet.github.io/docfx/ |
| 376 | +- **XMLDoc Guide:** https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/ |
| 377 | +- **Markdown Guide:** https://www.markdownguide.org/ |
| 378 | + |
| 379 | +### Example Documentation |
| 380 | + |
| 381 | +See these files for well-documented examples: |
| 382 | +- `src/Weaviate.Client/Models/VectorData.cs` - Vector types |
| 383 | +- `src/Weaviate.Client/Models/Filter.cs` - Filter API |
| 384 | +- `src/Weaviate.Client/Models/Sort.cs` - Sort API |
| 385 | +- `src/Weaviate.Client/Models/Batch.cs` - Batch operations |
| 386 | + |
| 387 | +## Contributing |
| 388 | + |
| 389 | +When contributing documentation: |
| 390 | + |
| 391 | +1. Follow the patterns established in existing documentation |
| 392 | +2. Include examples for complex APIs |
| 393 | +3. Cross-reference related types using `<see cref=""/>` |
| 394 | +4. Test documentation generation before submitting PR |
| 395 | +5. Ensure all new public APIs have XMLDoc comments |
| 396 | + |
| 397 | +--- |
| 398 | + |
| 399 | +For questions or issues related to documentation, please file an issue on the GitHub repository. |
0 commit comments