This guide explains how to update the AdGuard DNS API OpenAPI specification and regenerate the C# API client.
The AdGuard API Client is auto-generated from an OpenAPI (formerly Swagger) specification using OpenAPI Generator. This ensures the client stays in sync with the AdGuard DNS API.
- API Version: 1.11
- Generator Version: 7.16.0
- Target Framework: .NET 10
- JSON Library: Newtonsoft.Json
The OpenAPI specification is stored at:
src/adguard-api-dotnet/api/openapi.json (primary)
src/adguard-api-dotnet/api/openapi.yaml (optional, for readability)
The AdGuard DNS API OpenAPI specification is publicly available at:
https://api.adguard-dns.io/swagger/openapi.json
You can download it directly:
# Download the latest spec
curl -O https://api.adguard-dns.io/swagger/openapi.json
# Or save it to the correct location
curl -o src/adguard-api-dotnet/api/openapi.json \
https://api.adguard-dns.io/swagger/openapi.jsonIf the public URL is not accessible:
-
Visit AdGuard DNS Documentation
- https://adguard-dns.io/kb/private-dns/api/overview/
- Check for links to the API specification
-
Check Your Account Dashboard
- If you have an AdGuard DNS account, check for developer/API documentation
-
AdGuard GitHub Repositories
- Search https://github.com/AdguardTeam for API-related repositories
The latest AdGuard DNS API OpenAPI specification is publicly available at:
https://api.adguard-dns.io/swagger/openapi.json
Use the complete update workflow script:
# Linux/macOS
cd src/adguard-api-dotnet
./update-api-client.sh
# Windows (PowerShell)
cd src/adguard-api-dotnet
.\Update-ApiClient.ps1This script will:
- Download the latest OpenAPI spec
- Validate it
- Regenerate the API client
- Build and test the solution
Once you have obtained the latest OpenAPI specification:
-
Download the spec:
curl -o src/adguard-api-dotnet/api/openapi.json \ https://api.adguard-dns.io/swagger/openapi.json -
Backup the current spec:
cp src/adguard-api-dotnet/api/openapi.json \ src/adguard-api-dotnet/api/openapi.json.backup
-
Convert JSON to YAML (optional, for readability):
# Install yq if needed: pip install yq yq eval -P src/adguard-api-dotnet/api/openapi.json > \ src/adguard-api-dotnet/api/openapi.yaml
-
Verify the specification:
# Install OpenAPI tools if needed npm install -g @stoplight/spectral-cli # Validate the spec spectral lint src/adguard-api-dotnet/api/openapi.json
-
Review changes:
git diff src/adguard-api-dotnet/api/openapi.json
Install OpenAPI Generator CLI:
# Using npm (recommended)
npm install -g @openapitools/openapi-generator-cli
# Or using Docker (no installation required)
# See Docker method belowcd src/adguard-api-dotnet
./regenerate-client.shcd src/adguard-api-dotnet
.\Regenerate-Client.ps1The script will:
- Validate the OpenAPI specification exists
- Create a backup of existing generated files
- Generate new client code
- Provide instructions for next steps
cd src/adguard-api-dotnet
# Generate C# client
openapi-generator-cli generate \
-i api/openapi.json \
-g csharp \
-o . \
--additional-properties=\
targetFramework=net10.0,\
packageName=AdGuard.ApiClient,\
packageVersion=1.0.0,\
jsonLibrary=Newtonsoft.Json,\
validatable=false,\
netCoreProjectFile=true,\
nullableReferenceTypes=truecd src/adguard-api-dotnet
docker run --rm \
-v "${PWD}:/local" \
openapitools/openapi-generator-cli generate \
-i /local/api/openapi.json \
-g csharp \
-o /local \
--additional-properties=\
targetFramework=net10.0,\
packageName=AdGuard.ApiClient,\
packageVersion=1.0.0,\
jsonLibrary=Newtonsoft.Json,\
validatable=false,\
netCoreProjectFile=true,\
nullableReferenceTypes=trueCheck the generated files in src/AdGuard.ApiClient/:
git status src/adguard-api-dotnet/src/AdGuard.ApiClient/
git diff src/adguard-api-dotnet/src/AdGuard.ApiClient/The repository contains customizations in the following locations:
src/AdGuard.ApiClient/Helpers/- Custom helper classessrc/AdGuard.ConsoleUI/- Console application (not auto-generated)
Ensure these customizations are preserved or updated as needed.
cd src/adguard-api-dotnet
dotnet restore AdGuard.ApiClient.slnx
dotnet build AdGuard.ApiClient.slnx --no-restoreFix any compilation errors that may arise from API changes.
dotnet test AdGuard.ApiClient.slnx --no-buildUpdate tests as needed to accommodate API changes.
If the API has changed, update:
docs/api/- API endpoint documentationdocs/guides/api-client-usage.md- Usage examplessrc/adguard-api-dotnet/README.md- Client library README
The ConsoleUI application depends on the API client. Test it manually:
cd src/adguard-api-dotnet/src/AdGuard.ConsoleUI
dotnet runVerify all menu options and API operations work correctly.
Error: OpenAPI specification not found at: api/openapi.json
Solution: Ensure you have downloaded the latest specification and placed it in the correct location.
Error: Unsupported generator version
Solution: Update OpenAPI Generator CLI:
npm install -g @openapitools/openapi-generator-cli@latestCommon issues:
- Breaking API changes: Review the OpenAPI spec diff to understand what changed
- Missing dependencies: Run
dotnet restore - Namespace conflicts: Check for duplicate model names
If tests fail after regeneration:
- Review API endpoint changes in the spec
- Update test expectations to match new API behavior
- Add tests for new endpoints/models
The generation scripts use these properties:
| Property | Value | Description |
|---|---|---|
targetFramework |
net10.0 |
Target .NET version |
packageName |
AdGuard.ApiClient |
NuGet package name |
packageVersion |
1.0.0 |
Package version |
jsonLibrary |
Newtonsoft.Json |
JSON serialization library |
validatable |
false |
Disable model validation |
netCoreProjectFile |
true |
Use .NET Core project format |
nullableReferenceTypes |
true |
Enable nullable reference types |
To modify generation settings, edit the script or use .openapi-generator-ignore to exclude files from regeneration.
Example .openapi-generator-ignore:
# Don't regenerate helper classes
src/AdGuard.ApiClient/Helpers/*
# Don't regenerate tests
src/AdGuard.ApiClient.Test/*
| Date | API Version | Generator Version | Changes |
|---|---|---|---|
| 2025-12-14 | 1.11 | 7.16.0 | Initial documentation |
- AdGuard DNS API Documentation
- OpenAPI Generator Documentation
- API Client Usage Guide
- ConsoleUI Architecture
For issues with:
- OpenAPI spec: Contact AdGuard support
- Generation process: Check OpenAPI Generator issues
- This repository: Open an issue on GitHub
Planned enhancements for the update process:
- Automated Spec Fetching: Script to automatically check for and download new spec versions
- System.Text.Json Migration: Update to use modern .NET serialization (see
src/adguard-api-dotnet/.github/upgrades/tasks.md) - CI/CD Integration: Automated generation and testing in GitHub Actions
- Version Tracking: Maintain changelog of API version updates