plantbreeding / BrAPI

Repository for version control of the BrAPI specifications
https://brapi.org
MIT License
55 stars 32 forks source link

Make BrAPI Lists Ordered #615

Open mlm483 opened 1 week ago

mlm483 commented 1 week ago

Feature Request

@BrapiCoordinatorSelby I think BrAPI lists serve the most use cases if they are ordered lists. Currently, there is nothing in the spec that requires ordering to be preserved. The BrAPI-Java-TestServer generally returns list items in the same order they were created in, but this is only due to the default order in which PostgreSQL returns rows when an ORDER BY clause is omitted and is not guaranteed by any means.

Possible Implementations

Adopt UUID v7

Version 7 UUIDs are time-sortable, the first 48 bits are a timestamp with millisecond precision. For entities created by the same system in the same millisecond, implementations usually use an increasing counter to ensure monotonicity within each millisecond as well.

Pros

Cons

Add Field(s) to List Items

Adding a created timestamp and/or an integer list position field to list items could work in at least two ways. (1) The new field could be added to the API spec and explicitly passed back and forth when creating and reading lists (an integer position would make sense in this case) or (2) it could be a means of transparently preserving the original order of the list (a timestamp would be suitable in this case).

Pros

Cons

mlm483 commented 4 days ago

An example of transparently maintaining the ordering of BrAPI lists can be seen here in Breeding Insight's fork of the BrAPI-Java-TestServer.

BrapiCoordinatorSelby commented 4 days ago

hmmm I'm not sure I see the argument for adding an explicit order field to the Lists spec. JSON arrays are ordered and the order will be maintained from client to server. its up to the server implementation to maintain the order of the items sent from the client. And that can be done without altering the spec, as you have demonstrated with the test server. I would be open to adding text to the spec stating that maintaining the order is a required/recommended best practice. But I don't see why the JSON data models need to become more complicated?

mlm483 commented 4 days ago

I see your point. I thought of a case where adding an explicit order field could be useful, though it might not be real use case.

I realize that's a little contrived, but it does make me think that if the documentation is changed to recommend that implementations preserve order, it would be worth describing the recommended behavior of the /lists/{listDbId}/data POST endpoint specifically as well. I think append is the most natural behavior.