Collection-level behaviors

Some schema behaviors impact how the collection behaves. This can include how a collection or filtered and sorted.

Sorting a collection

You can specify a property is sortable. This gives callers the ability to sort the collection based on that property. For more information, see Sortable properties.

Default sorts

You can specify that a collection has a default sort order. This sort order is used when the caller does not specify a sort of their own. This is done in the API's apiconfig extension file.

Every API has an apiconfig extension file named <api_collection>_ext-1.0.schema.json. This file maps both element resource and collection resources to Gosu impl files. It can also define default sort orders for collections.

For example, the following code specifies that, by default, CustomEntitiesExt collections are sorted by expirationDate (ascending). If any elements have the same value, they are sorted by customDescription (ascending).

CustomEntitiesExt:
  defaultSort:
    - expirationDate
    - customDescription

To specify a descending order, use the following syntax:

- "-<propertyName>"

For example, the following code specifies that, by default, CustomEntitiesExt collections are sorted by expirationDate (descending). If any elements have the same value, they are sorted by customDescription (ascending).

CustomEntitiesExt:
  defaultSort:
    - "-expirationDate"
    - customDescription

Filtering a collection

You can specify a property is filterable. This gives callers the ability to filter the collection based on that property. For more information, see Filterable properties.