Api docs generator

From pnp/copilot-prompts · View interactive version

Api docs generator is an AI agent skill from the GitHub repository pnp/copilot-prompts. Generate structured API reference documentation from source code, OpenAPI specs, or route definitions. Trigger phrases include "generate API docs", "document this API", "create API reference", "write endpoint docs", "scaffold API docs".

How to use this skill

Skill file

API Documentation Generator

Generate clean, structured Markdown API reference docs from source code, OpenAPI/Swagger specs, or route definitions.

Gather Context

Before writing anything, determine:

  1. Source — Controller, route file, OpenAPI spec (JSON/YAML), or a set of files?
  2. API name — e.g., "User Management API". Infer from class/file name if not stated.
  3. Base URL — e.g., https://api.example.com/v1. Default to https://api.example.com if unknown.
  4. Auth method — Bearer token (default), API key, OAuth 2.0, or none.
  5. Output format:
  1. Language/framework — Auto-detect from file extensions, imports, and decorators.

If context is missing: In conversational mode, ask. In agent/inline mode, use sensible defaults and note your assumptions at the top of the output.

Analyzing the Source

From Source Code

Read the file(s) and extract:

Framework detection hints:

| Signal | Framework |

|--------|-----------|

| [ApiController], [HttpGet] | ASP.NET Core |

| @app.get(), @router.post() | FastAPI |

| router.get(), app.use() | Express.js |

| @GetMapping, @RestController | Spring Boot |

| @Controller, @Get() | NestJS |

| resources :users | Rails |

From OpenAPI/Swagger Specs

Parse the spec and map directly:

Prefer descriptions from the spec. Only infer descriptions when the spec omits them.

Handling Incomplete Source

If the source references models, DTOs, or types defined in other files:

Documentation Template

# {API Name} — API Reference

> Base URL: `{base-url}`
> Authentication: {auth-method}
> Version: {version}

## Table of Contents

- [Authentication](#authentication)
- [{Resource Group}](#{resource-group-slug})
  - [{METHOD} {path}](#{endpoint-anchor})

## Authentication

{How to authenticate: header format, token acquisition, expiration/refresh if known.}

**Header format:**

Authorization: Bearer {token}


---

## {Resource Group}

### {METHOD} `{path}`

{One-line description from doc comments or inferred from the code.}

**Parameters**

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `id` | path | integer | ✅ | Resource ID |
| `limit` | query | integer | ❌ | Max results (default: 20) |

**Request Body** *(POST/PUT/PATCH only)*

{

"email": "string — the user's email address",

"displayName": "string — display name"

}


**Responses**

| Status | Description |
|--------|-------------|
| `200 OK` | Returns the resource |
| `404 Not Found` | Resource not found |

{

"id": 42,

"email": "jane@example.com",

"displayName": "Jane Smith",

"createdAt": "2026-01-15T10:30:00Z"

}


**Example**

curl -X GET "{base-url}/{path}" \

-H "Authorization: Bearer eyJhbG..."

For per-endpoint format: one file per endpoint named {method}-{path-slug}.md (e.g., get-users-id.md), each using the endpoint section above, plus a README.md that links to all of them grouped by resource.

Common API Patterns to Document

When you encounter these in the source, document them:

Rules

Do:

Don't:

Example

Input — ASP.NET Core controller:

[ApiController]
[Route("api/[controller]")]
public class UsersController : ControllerBase
{
    /// <summary>Gets a user by their ID.</summary>
    [HttpGet("{id}")]
    public async Task<ActionResult<UserDto>> GetUser(int id) { }

    /// <summary>Creates a new user.</summary>
    [HttpPost]
    public async Task<ActionResult<UserDto>> CreateUser([FromBody] CreateUserRequest request) { }
}

Output:

# Users API — API Reference

> Base URL: `https://api.example.com`
> Authentication: Bearer token

## Users

### GET `/api/users/{id}`

Gets a user by their ID.

**Parameters**

| Name | In | Type | Required | Description |
|------|----|------|----------|-------------|
| `id` | path | integer | ✅ | The user's unique ID |

**Responses**

| Status | Description |
|--------|-------------|
| `200 OK` | Returns the user |
| `404 Not Found` | User not found |

{

"id": 42,

"email": "jane@example.com",

"displayName": "Jane Smith",

"createdAt": "2026-01-15T10:30:00Z"

}


**Example**

curl -X GET "https://api.example.com/api/users/42" \

-H "Authorization: Bearer eyJhbG..."


---

### POST `/api/users`

Creates a new user.

**Request Body**

{

"email": "string — the user's email address",

"displayName": "string — the user's display name",

"role": "string — user role (admin, member, viewer)"

}


**Responses**

| Status | Description |
|--------|-------------|
| `201 Created` | User created successfully |
| `400 Bad Request` | Invalid request body |
| `409 Conflict` | Email already exists |

{

"id": 43,

"email": "john@example.com",

"displayName": "John Doe",

"createdAt": "2026-02-18T14:00:00Z"

}


**Example**

curl -X POST "https://api.example.com/api/users" \

-H "Authorization: Bearer eyJhbG..." \

-H "Content-Type: application/json" \

-d '{"email": "john@example.com", "displayName": "John Doe", "role": "member"}'

Pre-Delivery Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.