Check if kwargs contains all the primary key fields except the id field.
(
model_operator: ModelOperator,
object_id_required: bool,
path_params: Dict,
)
| 83 | |
| 84 | |
| 85 | def check_path_params( |
| 86 | model_operator: ModelOperator, |
| 87 | object_id_required: bool, |
| 88 | path_params: Dict, |
| 89 | ): |
| 90 | """Check if kwargs contains all the primary key fields except the id field.""" |
| 91 | entity_class = model_operator.entity_class |
| 92 | id_field_name = entity_class.id_field_name() |
| 93 | primary_key_fields = entity_class.primary_key_fields() |
| 94 | |
| 95 | # Only the id field is required |
| 96 | required_fields = [field for field in primary_key_fields if "id" in field] |
| 97 | |
| 98 | # If the id field is required, add it to the required fields |
| 99 | for k in required_fields: |
| 100 | if k not in path_params and (k != id_field_name or object_id_required): |
| 101 | raise_request_validation_error(f"Missing path parameter: {k}") |
| 102 | |
| 103 | # check all oath params are alphanumeric |
| 104 | for k, v in path_params.items(): |
| 105 | if not alphanumeric_pattern.match(v): |
| 106 | raise_request_validation_error(f"Invalid path parameter: {k}") |
| 107 | |
| 108 | # Check each id field |
| 109 | try: |
| 110 | entity_class.validate_path_params(path_params) |
| 111 | except ValidationError as exc: |
| 112 | detail = exc.errors()[0] |
| 113 | raise_request_validation_error(f"{detail['loc'][0]}: {detail['msg']}") |
| 114 | |
| 115 | return |
| 116 | |
| 117 | |
| 118 | async def path_params_required(request: Request) -> Dict[str, str]: |
no test coverage detected