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

Apply decorator to validate request on route functions. #5947

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from

Commits on Jun 28, 2023

  1. Configuration menu
    Copy the full SHA
    281023a View commit details
    Browse the repository at this point in the history
  2. Fix serialized name handling in validate_request decorator

    ---------------------------------------
    The previous implementation of the validate_request decorator did not correctly handle the serialized names of fields in the DTO class when populating attribute values from the request. This commit addresses the issue by updating the decorator to access the serialized names directly from the serialized_name attribute of each field.
    
    The updated implementation iterates over the fields in the DTO class and checks for the presence of the serialized names in the request body. If a matching serialized name is found, the corresponding value is assigned to the DTO attribute. This ensures that fields with serialized names, specified using the serialized_name parameter in the field definitions, are properly set.
    Aadesh-Baral committed Jun 28, 2023
    Configuration menu
    Copy the full SHA
    2a1ab0c View commit details
    Browse the repository at this point in the history
  3. Update decorator to handle invalid/empty json body.

    -----------------------------------------------
    This commit refactors the request body handling in the validate_request decorator. Previously, the code attempted to access request.json directly, which could raise a "Failed to decode JSON object" error when the request body was empty or contained invalid JSON.
    
    To address this issue, the code has been updated to use a try-except block. It now checks request.is_json and handles two scenarios:
    
    - If request.is_json is True, indicating a JSON content type, it tries to access request.json to retrieve the JSON payload. If the request body contains invalid JSON, the WerkzeugBadRequest exception is caught, and the body is set to an empty dictionary.
    
    - If request.is_json is False or request.json raises an error for any reason, body is also set to an empty dictionary.
    Aadesh-Baral committed Jun 28, 2023
    Configuration menu
    Copy the full SHA
    21558f1 View commit details
    Browse the repository at this point in the history