Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add API Documentation-Driven Design to API documentation #2682

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

chronark
Copy link
Collaborator

@chronark chronark commented Nov 25, 2024

This PR adds the API Documentation-Driven Design.mdx file to the API documentation.

Summary by CodeRabbit

  • New Features
    • Introduced a comprehensive guide on "API Documentation-Driven Design," outlining best practices for effective API documentation.
    • Highlighted key principles of API design and provided structured templates for documentation.
    • Discussed the role of REST API documentation with examples, including interactive elements and code snippets.
    • Introduced FastAPI and various documentation formats to enhance usability and developer experience.

Copy link

vercel bot commented Nov 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 1:12pm
play 🛑 Canceled (Inspect) Nov 26, 2024 1:12pm
workflows ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 1:12pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 26, 2024 1:12pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
dashboard ⬜️ Ignored (Inspect) Visit Preview Nov 26, 2024 1:12pm

Copy link

changeset-bot bot commented Nov 25, 2024

⚠️ No Changeset found

Latest commit: 0080ad4

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Nov 25, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

A new file, api-documentation-driven-design.mdx, has been introduced to provide a comprehensive guide on best practices for creating effective API documentation alongside API development. The document covers key principles of API design, structured approaches to documentation, and highlights the role of REST API documentation, including various formats and tools to enhance usability and developer experience.

Changes

File Path Change Summary
apps/www/content/glossary/api-documentation-driven-design.mdx New file created to guide on API documentation-driven design, covering best practices, principles, and tools.

Possibly related PRs

Suggested labels

Documentation

Suggested reviewers

  • mcstepp
  • perkinsjr
  • MichaelUnkey

Warning

Rate limit exceeded

@chronark has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 27 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between d9571f5 and 0080ad4.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
apps/www/content/glossary/api-documentation-driven-design.mdx (3)

6-6: Consider adding relevant categories

The categories array is empty. Consider adding relevant categories like "API Design", "Documentation", or "Best Practices" to improve content discoverability.


88-92: Consider adding FastAPI code examples

The FastAPI section would be more valuable with practical code examples demonstrating automatic documentation generation. Consider adding a simple example showing how to use FastAPI's documentation features.

Example addition:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(
    title="Sample API",
    description="A sample API demonstrating FastAPI's automatic documentation"
)

class Item(BaseModel):
    name: str
    description: str | None = None

@app.post("/items/")
async def create_item(item: Item):
    """
    Create a new item.
    
    This endpoint demonstrates FastAPI's automatic documentation generation.
    """
    return item

62-66: Enhance security principles with specific recommendations

The security principle could be expanded with specific recommendations. Consider adding examples of security best practices such as:

  • Rate limiting
  • Input validation
  • Authentication methods (OAuth2, API keys)
  • HTTPS enforcement
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 46b0691 and d9571f5.

📒 Files selected for processing (1)
  • apps/www/content/glossary/api-documentation-driven-design.mdx (1 hunks)
🔇 Additional comments (1)
apps/www/content/glossary/api-documentation-driven-design.mdx (1)

52-57: LGTM! Clear and well-structured introduction

The introduction effectively defines API Documentation-Driven Design and its importance, with good use of formatting for emphasis.

Comment on lines +34 to +39
- url: https://example.com/writing-effective-api-documentation
title: Writing Effective API Documentation
- url: https://example.com/api-documentation-best-practices
title: API Documentation Best Practices
- url: https://example.com/spec-driven-development-introduction
title: "Spec-Driven Development: An Introduction"
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Replace placeholder URLs with actual resources

The recommended reading section contains example.com placeholder URLs which don't provide value to readers. Consider replacing these with actual, authoritative resources about API documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

question: What are the benefits of API Documentation-Driven Design?
- answer: Implementing API Documentation-Driven Design involves several steps. First, you need to define the functionality of your API and write detailed documentation that includes information about the API's endpoints, request/response formats, and error codes. Tools like Swagger or Apiary can be used to create this documentation. Once the documentation is complete, you can use it as a guide to develop your API. As you develop the API, you should continuously update the documentation to reflect any changes or additions to the API. Finally, once the API is complete, you should review the documentation to ensure it accurately represents the API's functionality.
question: How to implement API Documentation-Driven Design?
updatedAt: 2024-11-25T19:00:39.000Z
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix future timestamp

The updatedAt field is set to November 25, 2024, which is a future date. This should be set to the current date or removed to let the system handle it automatically.

Comment on lines 1 to 101
title: "API Doc-Driven Design: Best Practices Guide"
description: Master API Documentation-Driven Design. Learn principles, create templates, explore RESTful API patterns. Start now.
h1: "API Doc-Driven Design: Principles & Templates"
term: API Documentation-Driven Design
categories: []
takeaways:
tldr: API Documentation-Driven Design is a development approach where API documentation is created in parallel with API development, enhancing usability and developer experience.
definitionAndStructure:
- key: API Documentation
value: Developer Guide
- key: Driven Design
value: Parallel Development
- key: Spec-Driven Development
value: Automated Documentation
historicalContext:
- key: Introduced
value: Est. ~2010s
- key: Origin
value: Software Development (API Documentation-Driven Design)
- key: Evolution
value: Standardized API Documentation-Driven Design
usageInAPIs:
tags:
- API Documentation
- Developer Experience
- API Design
description: API Documentation-Driven Design is used to create clear, user-friendly API documentation that enhances developer experience. It involves creating documentation in parallel with API development, often using specifications like OpenAPI for standardization. This approach ensures that the API documentation is always up-to-date and accurately reflects the API's capabilities.
bestPractices:
- Create documentation in parallel with API development to ensure it's always up-to-date.
- Use specifications like OpenAPI, RAML, and API Blueprint to standardize and automate the documentation process.
- Cater to various user groups by using user-friendly language and providing clear instructions.
recommendedReading:
- url: https://example.com/writing-effective-api-documentation
title: Writing Effective API Documentation
- url: https://example.com/api-documentation-best-practices
title: API Documentation Best Practices
- url: https://example.com/spec-driven-development-introduction
title: "Spec-Driven Development: An Introduction"
didYouKnow: API Documentation-Driven Design is similar to Test-Driven Development, where tests are written before the code, ensuring that the code meets the requirements from the start.
faq:
- answer: API Documentation-Driven Design is a development approach where the API documentation is written before the actual API is developed. The idea is to define the API's functionality, endpoints, request/response formats, and error codes in the documentation first. This approach helps to ensure that the API is designed with the end-user in mind, and it can also help to identify potential issues or gaps in the API's design before any code is written. It's a part of the larger concept of 'Design First' approach in API development.
question: What is API Documentation-Driven Design?
- answer: API Documentation-Driven Design has several benefits. First, it ensures that the API is user-centric because it forces developers to think about how the API will be used before they start coding. Second, it can help to identify potential issues or gaps in the API's design early in the development process, which can save time and resources. Third, it can make the development process more efficient by providing a clear roadmap for developers to follow. Finally, it can improve the quality of the API documentation, as the documentation is considered an integral part of the development process, not an afterthought.
question: What are the benefits of API Documentation-Driven Design?
- answer: Implementing API Documentation-Driven Design involves several steps. First, you need to define the functionality of your API and write detailed documentation that includes information about the API's endpoints, request/response formats, and error codes. Tools like Swagger or Apiary can be used to create this documentation. Once the documentation is complete, you can use it as a guide to develop your API. As you develop the API, you should continuously update the documentation to reflect any changes or additions to the API. Finally, once the API is complete, you should review the documentation to ensure it accurately represents the API's functionality.
question: How to implement API Documentation-Driven Design?
updatedAt: 2024-11-25T19:00:39.000Z
slug: api-documentation-driven-design
---

**API Documentation-Driven Design** is a methodology that prioritizes the structure of API documentation in guiding the design of an API. This approach emphasizes the importance of creating comprehensive **API documentation templates** before writing any code, ensuring that the API's interface is user-centric and well-defined from the outset. By adopting this method, developers can design APIs that are not only easier to use but also more understandable and integrable by other developers.

## Understanding API Documentation-Driven Design

API Documentation-Driven Design reverses the traditional API development process. Instead of coding first and documenting later, this approach advocates for writing the API documentation first. This preliminary documentation acts as a contract that guides the development process, helping to identify potential issues and user experience enhancements early in the cycle. This proactive strategy reduces the need for significant revisions after the code has been written, aligning with **API design best practices**.

## Key Principles of API Design Best Practices

To create effective APIs, developers should adhere to the following **API design best practices**:

- **Consistency**: Ensure uniformity in naming and accessing resources and methods.
- **Simplicity**: Design APIs to be intuitive, facilitating easy integration for developers.
- **Flexibility**: Allow for future changes without compromising existing functionality.
- **Security**: Integrate security measures at every level of the API design.
- **Documentation**: Maintain clear and comprehensive documentation that is essential for usability and maintenance.

## Creating Effective API Documentation Templates

An effective **API documentation template** should encompass the following elements:

- **Overview**: A concise description of the API's functionality.
- **Authentication**: Clear instructions on how the API handles authentication.
- **Endpoints**: A detailed list of endpoints, including paths, methods, request parameters, and response objects.
- **Examples**: Clear examples of requests and responses to guide developers.
- **Error Codes**: Information on possible errors and their meanings.

## Examples of REST API Documentation

Good **REST API documentation examples** typically include:

- **Interactive Examples**: Tools like Swagger UI allow users to make API calls directly from the documentation.
- **Code Snippets**: Provide code snippets in various programming languages to aid developers.
- **HTTP Methods**: Detailed descriptions of each method, expected responses, and status codes.

## Utilizing FastAPI for Documentation-Driven Design

**FastAPI** is a modern, fast web framework for building APIs with Python 3.7+ that supports **Documentation-Driven Design**. Key features of FastAPI include:

- **Automatic Interactive API Documentation**: FastAPI generates interactive API documentation using Swagger UI and ReDoc, enabling developers to test the API directly from their browser.
- **Schema Generation**: FastAPI automatically generates JSON Schema definitions for all models, streamlining the documentation process.

## Sample API Documentation Formats

Common formats for API documentation include:

- **OpenAPI/Swagger**: JSON or YAML format that describes the entire API, including entries for all endpoints, their operations, parameters, and responses.
- **Markdown**: A simple and easy-to-update format that can be used for narrative documentation.
- **Postman Collections**: Allows developers to import and make requests directly within Postman, facilitating real-time testing and interaction.

By adhering to these guidelines and utilizing the appropriate tools, API developers can ensure that their APIs are not only functional but also user-friendly and well-documented from the start. For further insights, consider exploring **API documentation-driven design best practices on GitHub** or reviewing **sample API documentation PDFs** to enhance your understanding of **RESTful API design patterns and best practices**.
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Example URLs need to be replaced with actual resources

The document contains placeholder example URLs (example.com) in the recommended reading section that should be replaced with actual, relevant resources.

  • Replace placeholder URLs in the recommendedReading section:
    - url: https://example.com/writing-effective-api-documentation
    - url: https://example.com/api-documentation-best-practices
    - url: https://example.com/spec-driven-development-introduction

Otherwise, the document is well-structured and contains no broken internal links or cross-references.

🔗 Analysis chain

Verify internal references and links

Let's verify that all internal references in the document are valid and accessible within the repository.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other related API documentation files
echo "Checking for related API documentation files..."
fd -e mdx -e md . apps/www/content/ | grep -i "api"

# Check for potential broken internal links
echo "Checking for potential broken internal links..."
rg -l "\[.*?\]\((?!http).*?\)" apps/www/content/glossary/api-documentation-driven-design.mdx

Length of output: 702


Script:

#!/bin/bash
# Check for internal links with a simpler pattern
echo "Checking for markdown links..."
rg "\[.+?\]\(.+?\)" apps/www/content/glossary/api-documentation-driven-design.mdx

# Check if the recommended reading URLs are accessible
echo "Checking recommended reading URLs..."
rg "url: " apps/www/content/glossary/api-documentation-driven-design.mdx

# Check for related API documentation files
echo "Checking for cross-references..."
rg -l "api-documentation" apps/www/content/

Length of output: 692

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@p6l-richard, thank you for addressing the issue.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

Copy link
Contributor

github-actions bot commented Nov 25, 2024

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
apps/www/content/glossary/api-documentation-driven-design.mdx (2)

58-77: Consider adding versioning guidelines

The principles and template sections are well-structured. Consider adding versioning guidelines to help users understand how to handle API changes and maintain backward compatibility.

Add a bullet point under principles:

 - **Security**: Integrate security measures at every level of the API design.
 - **Documentation**: Maintain clear and comprehensive documentation that is essential for usability and maintenance.
+- **Versioning**: Define clear versioning strategies to manage API evolution and maintain backward compatibility.

86-92: Consider adding practical FastAPI examples

The FastAPI section would benefit from practical code examples demonstrating automatic documentation generation.

Consider adding a code example like:

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(
    title="Sample API",
    description="A sample API demonstrating automatic documentation"
)

class Item(BaseModel):
    name: str
    description: str | None = None
    price: float

@app.post("/items/")
async def create_item(item: Item):
    """
    Create a new item with the following parameters:
    - **name**: Item name
    - **description**: Optional item description
    - **price**: Item price
    """
    return item
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d9571f5 and 0080ad4.

📒 Files selected for processing (1)
  • apps/www/content/glossary/api-documentation-driven-design.mdx (1 hunks)
🔇 Additional comments (2)
apps/www/content/glossary/api-documentation-driven-design.mdx (2)

52-56: Well-structured introduction!

The introduction effectively defines the concept and uses appropriate formatting for key terms.


93-101: Strong conclusion with practical guidance!

The section effectively covers documentation formats and provides clear next steps for implementation.

answer: API Documentation-Driven Design has several benefits. First, it ensures that the API is user-centric because it forces developers to think about how the API will be used before they start coding. Second, it can help to identify potential issues or gaps in the API's design early in the development process, which can save time and resources. Third, it can make the development process more efficient by providing a clear roadmap for developers to follow. Finally, it can improve the quality of the API documentation, as the documentation is considered an integral part of the development process, not an afterthought.
- question: How to implement API Documentation-Driven Design?
answer: Implementing API Documentation-Driven Design involves several steps. First, you need to define the functionality of your API and write detailed documentation that includes information about the API's endpoints, request/response formats, and error codes. Tools like Swagger or Apiary can be used to create this documentation. Once the documentation is complete, you can use it as a guide to develop your API. As you develop the API, you should continuously update the documentation to reflect any changes or additions to the API. Finally, once the API is complete, you should review the documentation to ensure it accurately represents the API's functionality.
updatedAt: 2024-11-26T13:08:39.000Z
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update the timestamp to the current date

The updatedAt field is set to November 26, 2024, which is a future date. This should be set to the current date or removed to let the system handle it automatically.

-updatedAt: 2024-11-26T13:08:39.000Z
+updatedAt: 2023-11-26T13:08:39.000Z

Committable suggestion skipped: line range outside the PR's diff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants