diff --git a/entity-api-spec.yaml b/entity-api-spec.yaml index 7cd58bfe..169d52ae 100644 --- a/entity-api-spec.yaml +++ b/entity-api-spec.yaml @@ -434,7 +434,7 @@ components: - block - section - suspension - description: 'A code representing the type of specimen. Must be an organ, block, section, or suspension' + description: 'A code representing the type of specimen. Must be an organ, block, section, or suspension, in all lower case.' protocol_url: type: string description: 'The protocols.io doi url pointing the protocol under wich the sample was obtained and/or prepared.' @@ -482,7 +482,7 @@ components: - TR - UR - UT - description: 'Organ code specifier, only set if sample_category == organ. Valid values found in: [organ types](https://github.com/hubmapconsortium/search-api/blob/main/src/search-schema/data/definitions/enums/organ_types.yaml)' + description: 'Organ code specifier, only set if sample_category == organ. Valid values found in: [organ types](https://ontology.api.hubmapconsortium.org/organs/by-code?application_context=HUBMAP)' organ_other: type: string description: The organ type provided by the user if "other" organ type is selected diff --git a/src/app.py b/src/app.py index 23f16fc1..26d907ef 100644 --- a/src/app.py +++ b/src/app.py @@ -1272,7 +1272,15 @@ def create_multiple_samples(count): # No need to log the validation errors bad_request_error(str(e)) - # `direct_ancestor_uuid` is required on create + try: + schema_manager.execute_property_level_validators('before_property_create_validators', normalized_entity_type, request, {}, json_data_dict) + # Currently only ValueError + except ValueError as e: + bad_request_error(e) + except schema_errors.UnimplementedValidatorException as uve: + internal_server_error(uve) + + # `direct_ancestor_uuid` is required on create for a Sample. # Check existence of the direct ancestor (either another Sample or Donor) direct_ancestor_dict = query_target_entity(json_data_dict['direct_ancestor_uuid'], user_token) @@ -1288,7 +1296,7 @@ def create_multiple_samples(count): if ('organ' not in json_data_dict) or (not json_data_dict['organ']): bad_request_error("A valid organ code is required since the direct ancestor is a Donor") - # Generate 'before_create_triiger' data and create the entity details in Neo4j + # Generate 'before_create_trigger' data and create the entity details in Neo4j generated_ids_dict_list = create_multiple_samples_details(request, normalized_entity_type, user_token, json_data_dict, count) # Also index the each new Sample node in elasticsearch via search-api diff --git a/src/schema/schema_validators.py b/src/schema/schema_validators.py index 5a6fd5e1..1529cc02 100644 --- a/src/schema/schema_validators.py +++ b/src/schema/schema_validators.py @@ -564,8 +564,14 @@ def validate_sample_category(property_key, normalized_entity_type, request, exis sample_category = new_data_dict[property_key].lower() if sample_category not in defined_tissue_types: - raise ValueError(f"Invalid sample_category: {sample_category}") - + raise ValueError(f"Invalid sample_category: {sample_category}." + f" Should be one of {', '.join(defined_tissue_types)}.") + + # Given the sample_category is a defined_tissue_types element, assure the request has + # the proper case for storage + if new_data_dict[property_key] != sample_category: + raise ValueError(f"The case of sample_category '{new_data_dict[property_key]}'" + f" must be specified as '{sample_category}'.") """ Validate the provided value of Publication.publication_date is in the correct format against ISO 8601 Format: