Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
AI

AI Prompt: Generate Complete API Documentation from Codebase

- 22.03.26 - ErcanOPAK

📚 Documentation in Minutes, Not Days

Writing API docs manually takes forever. AI reads your code and generates complete documentation with examples.

The Documentation Prompt

Generate comprehensive API documentation for this codebase:

[Paste controllers/routes/API code]

Include:
1. Endpoint descriptions (what each does)
2. HTTP methods and paths
3. Request parameters (query, body, headers)
4. Request body schemas with types
5. Response schemas (success and error)
6. Status codes (200, 400, 401, 404, 500)
7. Authentication requirements
8. Example requests (curl and JavaScript)
9. Example responses (JSON)
10. Rate limiting info if applicable

Format as Markdown with clear sections.
Make it ready for README.md or documentation site.

Example Output Quality

## Create User

**POST** `/api/users`

Creates a new user account.

### Authentication
Requires API key in header: `X-API-Key`

### Request Body
```json
{
  "name": "string (required, 2-50 chars)",
  "email": "string (required, valid email)",
  "role": "string (optional, default: 'user')",
  "age": "number (optional, 18+)"
}
```

### Response (201 Created)
```json
{
  "id": "uuid",
  "name": "John Doe",
  "email": "john@example.com",
  "role": "user",
  "createdAt": "2024-03-19T10:30:00Z"
}
```

### Error Responses
- **400 Bad Request**: Invalid input
- **401 Unauthorized**: Missing/invalid API key
- **409 Conflict**: Email already exists
- **500 Server Error**: Internal error

### Example Request
```bash
curl -X POST https://api.example.com/api/users \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your_key_here" \
  -d '{"name":"John Doe","email":"john@example.com"}'
```

### Example JavaScript
```javascript
const response = await fetch('https://api.example.com/api/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your_key_here'
  },
  body: JSON.stringify({
    name: 'John Doe',
    email: 'john@example.com'
  })
});
const data = await response.json();
```

Advanced: Generate OpenAPI Spec

Convert this API code to OpenAPI 3.0 specification:

[Paste code]

Generate complete openapi.yaml with:
- All endpoints
- Request/response schemas
- Authentication schemes
- Example values
- Descriptions

Make it importable to Swagger/Postman.

🎯 Documentation Types

  • API Reference: Complete endpoint documentation
  • Getting Started Guide: Quick start tutorial
  • SDK Documentation: Client library usage
  • Error Handling Guide: All error codes explained
  • Webhooks Docs: Webhook payload examples

💡 Pro Tips

  • Update regularly: Regenerate docs when API changes
  • Add context: Include “This is a payment processing API” in prompt
  • Request examples in multiple languages: curl, JavaScript, Python, etc.
  • Ask for diagrams: “Include mermaid diagram of authentication flow”

“Had 47 API endpoints, zero documentation. Used AI to generate complete docs in 30 minutes. Added examples, error codes, everything. Partners can finally integrate without asking questions.”

— API Product Manager

Related posts:

AI Prompt: Optimize Slow SQL Queries with AI Analysis

AI Prompt: The Emergency Plumber - DIY Leak Management

Generate Code Reviews Like a Senior Engineer

Post Views: 4

Post navigation

Docker: Add Health Checks to Detect and Restart Failing Containers
AI Prompt: Transform Data Between Formats (CSV, JSON, XML, SQL)

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

April 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
27282930  
« Mar    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (751)
  • Add Constraint to SQL Table to ensure email contains @ (578)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (564)
  • Average of all values in a column that are not zero in SQL (531)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (489)
  • Find numbers with more than two decimal places in SQL (447)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries
  • SQL: Use Window Functions for Advanced Analytical Queries
  • .NET Core: Use Background Services for Long-Running Tasks
  • .NET Core: Use Minimal APIs for Lightweight HTTP Services
  • Git: Use Cherry-Pick to Apply Specific Commits Across Branches
  • Git: Use Interactive Rebase to Clean Up Commit History Before Merge

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (950)
  • How to add default value for Entity Framework migrations for DateTime and Bool (858)
  • Get the First and Last Word from a String or Sentence in SQL (836)
  • How to select distinct rows in a datatable in C# (805)
  • How to make theater mode the default for Youtube (751)

Recent Posts

  • C#: Use Init-Only Setters for Immutable Objects After Construction
  • C#: Use Expression-Bodied Members for Concise Single-Line Methods
  • C#: Enable Nullable Reference Types to Eliminate Null Reference Exceptions
  • C#: Use Record Types for Immutable Data Objects
  • SQL: Use CTEs for Readable Complex Queries

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com