Back to all reviewers

Standardize API parameter handling

apache/airflow
Based on 6 comments
Python

Use consistent parameter handling patterns across API endpoints to ensure maintainability and predictable behavior. Follow these guidelines: 1. Use FastAPI's native parameter handling for lists:

API Python

Reviewer Prompt

Use consistent parameter handling patterns across API endpoints to ensure maintainability and predictable behavior. Follow these guidelines:

  1. Use FastAPI’s native parameter handling for lists: ```python

    Good

    def get_dependencies( node_ids: list[str] | None = Query(None) ) -> BaseGraphResponse: pass

Avoid

def get_dependencies( node_ids: str | None = Query(None, description=”Comma-separated list of node ids”) ) -> BaseGraphResponse: ids_to_fetch = [nid.strip() for nid in node_ids.split(“,”)] if node_ids else []


2. Define constants for query parameter limits:
```python
MAX_SORT_PARAMS = 2

def get_order_by_columns(self, order_by_list: list[str]) -> list:
    if len(order_by_list) > MAX_SORT_PARAMS:
        raise HTTPException(
            400,
            f"Ordering with more than {MAX_SORT_PARAMS} parameters is not allowed"
        )
  1. Use explicit pagination parameters:
    def list_items(
     offset: int = 0,
     limit: int = 50,  # Make limits configurable
    ) -> Response:
     pass
    

This standardization improves API usability, reduces code duplication, and makes the API behavior more predictable for clients.

6
Comments Analyzed
Python
Primary Language
API
Category

Source Discussions