Skip to content

Commit

Permalink
fix(openapi): fix sort criteria parameter (#12090)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHolstien authored Dec 11, 2024
1 parent d953718 commit 59dd8be
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions docs/how/updating-datahub.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This file documents any backwards-incompatible changes in DataHub and assists pe
- #12056: The DataHub Airflow plugin no longer supports Airflow 2.1 and Airflow 2.2.
- #12056: The DataHub Airflow plugin now defaults to the v2 plugin implementation.
- OpenAPI Update: PIT Keep Alive parameter added to scroll. NOTE: This parameter requires the `pointInTimeCreationEnabled` feature flag to be enabled and the `elasticSearch.implementation` configuration to be `elasticsearch`. This feature is not supported for OpenSearch at this time and the parameter will not be respected without both of these set.
- OpenAPI Update 2: Previously there was an incorrectly marked parameter named `sort` on the generic list entities endpoint for v3. This parameter is deprecated and only supports a single string value while the documentation indicates it supports a list of strings. This documentation error has been fixed and the correct field, `sortCriteria`, is now documented which supports a list of strings.

### Breaking Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.MediaType;
Expand Down Expand Up @@ -190,7 +191,8 @@ public ResponseEntity<S> getEntities(
@RequestParam(value = "count", defaultValue = "10") Integer count,
@RequestParam(value = "query", defaultValue = "*") String query,
@RequestParam(value = "scrollId", required = false) String scrollId,
@RequestParam(value = "sort", required = false, defaultValue = "urn") String sortField,
@RequestParam(value = "sort", required = false, defaultValue = "urn") @Deprecated
String sortField,
@RequestParam(value = "sortCriteria", required = false) List<String> sortFields,
@RequestParam(value = "sortOrder", required = false, defaultValue = "ASCENDING")
String sortOrder,
Expand Down Expand Up @@ -222,14 +224,20 @@ public ResponseEntity<S> getEntities(
authentication.getActor().toUrnStr() + " is unauthorized to " + READ + " entities.");
}

SortOrder finalSortOrder =
SortOrder.valueOf(Optional.ofNullable(sortOrder).orElse("ASCENDING"));

List<SortCriterion> sortCriteria;
if (!CollectionUtils.isEmpty(sortFields)) {
if (!CollectionUtils.isEmpty(sortFields)
&& sortFields.stream().anyMatch(StringUtils::isNotBlank)) {
sortCriteria = new ArrayList<>();
sortFields.forEach(
field -> sortCriteria.add(SearchUtil.sortBy(field, SortOrder.valueOf(sortOrder))));
sortFields.stream()
.filter(StringUtils::isNotBlank)
.forEach(field -> sortCriteria.add(SearchUtil.sortBy(field, finalSortOrder)));
} else if (StringUtils.isNotBlank(sortField)) {
sortCriteria = Collections.singletonList(SearchUtil.sortBy(sortField, finalSortOrder));
} else {
sortCriteria =
Collections.singletonList(SearchUtil.sortBy(sortField, SortOrder.valueOf(sortOrder)));
sortCriteria = Collections.singletonList(SearchUtil.sortBy("urn", finalSortOrder));
}

ScrollResult result =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,19 +570,15 @@ private static void addExtraParameters(final Components components) {
"SortBy" + MODEL_VERSION,
new Parameter()
.in(NAME_QUERY)
.name("sort")
.name("sortCriteria")
.explode(true)
.description("Sort fields for pagination.")
.example(PROPERTY_URN)
.schema(
new Schema()
.type(TYPE_ARRAY)
._default(List.of(PROPERTY_URN))
.items(
new Schema<>()
.type(TYPE_STRING)
._enum(List.of(PROPERTY_URN))
._default(PROPERTY_URN))));
.items(new Schema<>().type(TYPE_STRING)._default(PROPERTY_URN))));
components.addParameters(
"SortOrder" + MODEL_VERSION,
new Parameter()
Expand Down

0 comments on commit 59dd8be

Please sign in to comment.