ASP.NET Core
Two paths. If the project exports a swagger.json, it is used. Otherwise controllers annotated with [ApiController] are scanned.
Prerequisites
Section titled “Prerequisites”- An ASP.NET Core project folder with a
.csproj. - The .NET SDK (8, 9, or 10) to build the demo.
appctlinstalled.
The demo in this repo
Section titled “The demo in this repo”examples/demos/aspnet-api/ is a minimal Web API project with an ItemsController that exposes full CRUD over an in-memory list. It includes Swashbuckle.AspNetCore so Swagger is available at /swagger/v1/swagger.json.
1. Build and run
Section titled “1. Build and run”cd examples/demos/aspnet-apidotnet builddotnet run --urls "http://localhost:5001"Real build output on this machine (dotnet 10.0.100):
DemoApi -> bin/Debug/net8.0/DemoApi.dllBuild succeeded. 0 Warning(s) 0 Error(s)Check a real endpoint:
curl -s -X POST http://localhost:5001/api/Items \ -H "Content-Type: application/json" \ -d '{"name":"NB","description":"Notebook"}'Output:
{"id":1,"name":"NB","description":"Notebook"}2. Sync path A: swagger.json (preferred)
Section titled “2. Sync path A: swagger.json (preferred)”With the server running, save the Swagger document and run sync. appctl detects swagger.json in the project folder and delegates to OpenAPI sync.
curl -s http://localhost:5001/swagger/v1/swagger.json -o swagger.jsonappctl sync --aspnet . --base-url http://localhost:5001 --forceReal output:
delegating to OpenAPI sync via ./swagger.jsonSynced Aspnet: 1 resources, 5 tools written to .appctlGenerated tools:
items: list_items, create_items, get_items, update_items, delete_items3. Sync path B: controller scan (no swagger.json)
Section titled “3. Sync path B: controller scan (no swagger.json)”rm swagger.jsonappctl sync --aspnet . --base-url http://localhost:5001 --forceReal output:
Synced Aspnet: 1 resources, 5 tools written to .appctlGenerated tools (naming is rougher):
Items: items_ok, items_getbyid, items_create, items_update, items_deleteThe first tool is called items_ok because the controller scan reads the C# identifier near the [HttpGet] attribute, which is the Ok(...) method call, not the C# method name. Prefer the Swagger path when you can.
What appctl reads
Section titled “What appctl reads”swagger.jsonif present anywhere in the project directory. When found, the sync defers to OpenAPI.- Otherwise,
.csfiles with a[Route(...)]attribute and any of[HttpGet],[HttpPost],[HttpPatch],[HttpDelete].
- Keep
Swashbuckleand export swagger at build time. You get cleaner tool names and correct parameter schemas. - The controller scan does not read
[FromBody]model types; parameter schemas will be empty.