dotnet-openapi-discovery
Discover current OpenAPI documentation for .NET WebAPI endpoints. Use when agent needs to find OpenAPI documentation, create requests in .http files, or test endpoints. The skill can start the service if not running, download OpenAPI JSON, and generate VS Code REST Client format requests or curl commands for testing.
SKILL.md
| Name | dotnet-openapi-discovery |
| Description | Discover current OpenAPI documentation for .NET WebAPI endpoints. Use when agent needs to find OpenAPI documentation, create requests in .http files, or test endpoints. The skill can start the service if not running, download OpenAPI JSON, and generate VS Code REST Client format requests or curl commands for testing. |
name: dotnet-openapi-discovery description: Discover current OpenAPI documentation for .NET WebAPI endpoints. Use when agent needs to find OpenAPI documentation, create requests in .http files, or test endpoints. The skill can start the service if not running, download OpenAPI JSON, and generate VS Code REST Client format requests or curl commands for testing.
.NET OpenAPI Discovery
Overview
This skill enables the agent to discover current OpenAPI documentation for .NET WebAPI projects. It can start the service if needed, download OpenAPI JSON, and use it to create requests in .http files or test endpoints via curl.
When to Use
This skill activates when:
- Agent explicitly requests OpenAPI documentation
- Agent wants to create requests in .http files
- Agent wants to test specific endpoints
- User query contains keywords: "openapi", "swagger", "api documentation", ".http", "test endpoint"
Workflow
Follow these steps sequentially:
Step 1: Detect .NET WebAPI Project
- Search for
.csprojfiles in the workspace root - Read the
.csprojfile to verify it contains ASP.NET Core references:- Look for
Microsoft.AspNetCore.Appframework reference - Or
Microsoft.AspNetCore.Apppackage reference - Or
Microsoft.NET.Sdk.WebSDK
- Look for
- If no WebAPI project is found, inform the user and end workflow
- Search for
launchSettings.jsonin:Properties/launchSettings.json(preferred location)launchSettings.json(root directory)
Step 2: Determine Base URL and Launch Profile
- Read and parse
launchSettings.jsonas JSON - Extract the
profilesobject - Select a launch profile in this priority order:
- Profile named
"http"(if exists) - Profile named
"https"(if exists) - First profile in the profiles object
- Profile named
- Extract the base URL:
- Extract the first URL from
applicationUrl(split by semicolon if multiple URLs) - If
applicationUrlcontains multiple URLs separated by semicolons, prefer HTTP over HTTPS - Remove any trailing slashes
- Example:
http://localhost:5000orhttps://localhost:5001
- Extract the first URL from
Step 3: Check if Service is Running
-
Extract the port number from the base URL (from Step 2)
-
Check if the service is running using one of these methods:
Method A: HTTP Request (preferred)
- Use
curl -f --max-time 2 <base-url>or similar HTTP request - If the request succeeds (exit code 0), the service is running
- If it fails or times out, the service is not running
Method B: Port Check (fallback)
- On macOS/Linux:
lsof -i :<port>ornetstat -an | grep :<port> - On Windows:
netstat -an | findstr :<port> - If port is in use, service may be running (but verify with HTTP request)
- Use
-
If service is not running:
- Start the service using
dotnet run --launch-profile <profile-name>in background - Wait 3-5 seconds for startup
- Verify service is responding (repeat check)
- Start the service using
Step 4: Discover OpenAPI Endpoint
- Try standard OpenAPI paths in this order (see openapi-paths.md for details):
/openapi/v1.json(modern .NET withapp.MapOpenApi())/swagger/v1/swagger.json(legacy Swashbuckle)/openapi.json/swagger.json
- For each path, attempt GET request:
curl -f --max-time 5 <base-url><path> - If successful, proceed to Step 5
- If all paths fail:
- Check
Program.csfor custom OpenAPI configuration - Look for
MapOpenApi()orMapSwagger()calls to determine custom paths - If still not found, inform the user that OpenAPI endpoint could not be discovered
- Check
Step 5: Download and Parse OpenAPI JSON
- Download OpenAPI JSON from the discovered endpoint
- Parse the JSON structure:
- Extract
pathsobject (contains all endpoints) - For each path, extract HTTP methods (
get,post,put,delete, etc.) - Extract
parameters(query params, path params, headers) - Extract
requestBodyfor POST/PUT requests - Extract
responsesfor response schemas
- Extract
- Store parsed data in memory for use in Step 6
Step 6: Use OpenAPI Documentation
Choose the appropriate action based on user request:
Option A: Create .http Request File
- Determine target file:
- If user specified a file, use that
- Otherwise, create or append to
api.httporrequests.httpin workspace root
- Format requests using VS Code REST Client format:
### GET /api/cars/{id} GET http://localhost:5000/api/cars/1 ### POST /api/cars POST http://localhost:5000/api/cars Content-Type: application/json { "name": "Toyota", "model": "Camry" } - For each endpoint:
- Add comment with method and path:
### GET /api/cars - Add request line with full URL
- Add query parameters if present (append
?param=value) - Add headers if needed (Content-Type, Authorization)
- Add request body for POST/PUT requests (use example from schema if available)
- Add comment with method and path:
- Replace path parameters with example values (e.g.,
{id}→1)
Option B: Test Endpoint via curl
- Identify the endpoint to test from user request
- Construct curl command based on OpenAPI specification:
curl -X GET http://localhost:5000/api/cars/1 \ -H "Content-Type: application/json" - For POST/PUT requests, include request body:
curl -X POST http://localhost:5000/api/cars \ -H "Content-Type: application/json" \ -d '{"name":"Toyota","model":"Camry"}' - Execute the curl command and display results
- Verify response status code matches expected values from OpenAPI spec
Edge Cases
No launchSettings.json Found
- Use default ports:
- HTTP:
http://localhost:5000 - HTTPS:
https://localhost:5001(if HTTPS is preferred)
- HTTP:
- Use profile name
"http"or"https"when runningdotnet run - If neither profile exists, run
dotnet runwithout--launch-profile
Service Already Running
- If Step 3 detects the service is running, proceed directly to Step 4
- Do not attempt to start another instance
OpenAPI Endpoint Not Found
- Try all standard paths (Step 4)
- Check
Program.csfor custom configuration - Inform user if OpenAPI endpoint cannot be discovered
- Suggest checking if OpenAPI is configured in the project
Startup Failure
- If
dotnet runfails, inform the user about the error - Show the error message from the command output
- Do not proceed with OpenAPI discovery if service cannot start
Invalid OpenAPI JSON
- If JSON parsing fails, inform the user
- Display error message
- Suggest verifying the OpenAPI endpoint returns valid JSON
Missing Request Body Schema
- For POST/PUT requests without request body schema, use generic JSON structure
- Include placeholder values based on parameter names
- Add comment indicating schema was not available
Technical Notes
OpenAPI Path Discovery
See openapi-paths.md for detailed information about standard OpenAPI paths in .NET WebAPI projects.
VS Code REST Client Format
- Use
###for request separators - Include method and path in separator comment
- Full URL on request line
- Headers on separate lines
- Empty line before request body
- JSON body indented with 2 spaces
Parsing OpenAPI JSON Structure
paths: Object where keys are endpoint paths (e.g.,/api/cars)- Each path contains HTTP methods as keys (
get,post, etc.) parameters: Array of parameter objects withname,in(query/path/header),required,schemarequestBody.content: Object with content types as keys (e.g.,application/json)requestBody.content[type].schema: JSON schema for request bodyresponses: Object with status codes as keys (e.g.,200,400)
Service Check Commands
HTTP Request:
curl -f --max-time 2 http://localhost:5000
Port Check (macOS/Linux):
lsof -i :5000
# or
netstat -an | grep :5000
Port Check (Windows):
netstat -an | findstr :5000
Starting Service
# From project root directory
dotnet run --launch-profile http
Resources
references/
- openapi-paths.md: Documentation of standard OpenAPI paths in .NET WebAPI projects, including discovery strategies and configuration examples.