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

[SDESK-7487] Add docstrings about usage of url in endpoints #2832

Merged
merged 4 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions superdesk/core/resources/resource_rest_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
# at https://www.sourcefabric.org/superdesk/license

import math
from inspect import get_annotations
from typing import Annotated, List, Optional, cast, Dict, Any, Type, get_args, get_origin
from typing import List, Optional, cast, Dict, Any, Type

from dataclasses import dataclass
from pydantic import ValidationError, BaseModel, NonNegativeInt
Expand All @@ -20,7 +19,9 @@
from bson import ObjectId

from superdesk.core import json
from superdesk.core.app import get_app_config, get_current_async_app
from superdesk.utils import get_cors_headers
from superdesk.errors import SuperdeskApiError
from superdesk.core.app import get_current_async_app
from superdesk.core.types import (
SearchRequest,
SearchArgs,
Expand All @@ -31,14 +32,12 @@
Response,
RestGetResponse,
)
from superdesk.errors import SuperdeskApiError
from superdesk.resource_fields import STATUS, STATUS_OK, ITEMS
from superdesk.core.web import RestEndpoints, ItemRequestViewArgs, Endpoint
from superdesk.utils import get_cors_headers, join_url_parts

from .model import ResourceModel
from .resource_config import ResourceConfig
from .validators import AsyncValidator, convert_pydantic_validation_error_for_response
from .validators import convert_pydantic_validation_error_for_response


@dataclass
Expand Down
1 change: 1 addition & 0 deletions superdesk/core/types/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class SearchArgs(TypedDict, total=False):
filters: list[dict[str, Any]]

#: A JSON string containing the field projections to filter out the returned fields
# Kept for compatibility with python-eve. Use `SearchRequest.projection` preferably.
projections: str

version: VersionParam | None
Expand Down
5 changes: 5 additions & 0 deletions superdesk/core/types/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ class Endpoint:
"""Base class used for registering and processing endpoints"""

#: URL for the endpoint
#: If the URL starts with "/", it will be used as-is.
#: Otherwise, the API prefix will be prepended to the URL.
#: For example:
#: - "items" -> "{api_prefix}{api_version}/items"
#: - "/custom/path" -> "/custom/path"
url: str

#: Name of the endpoint (must be unique)
Expand Down
16 changes: 10 additions & 6 deletions superdesk/core/web/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,16 @@ def __call__(self, args: dict[str, Any], params: dict[str, Any], request: Reques

def endpoint(url: str, name: str | None = None, methods: list[HTTP_METHOD] | None = None, auth: AuthConfig = None):
"""Decorator function to convert a pure function to an Endpoint instance

This is then later used to register with a Module or the app.

:param url: The URL of the endpoint
:param name: The optional name of the endpoint
:param methods: The optional list of HTTP methods allowed
which is later used to register with a Module or the app.

Args:
url: The URL of the endpoint. If it starts with "/", it will be used exactly as provided.
Otherwise, the API prefix and version will be automatically prepended.
For example:
- "items" becomes "{api_prefix}{api_version}/items"
- "/custom/path" stays as "/custom/path"
name: The optional name of the endpoint
methods: The optional list of HTTP methods allowed
"""

def convert_to_endpoint(func: EndpointFunction):
Expand Down
Loading