Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow api responses to be ordered #78

Merged
merged 7 commits into from
Sep 4, 2024
Merged

Allow api responses to be ordered #78

merged 7 commits into from
Sep 4, 2024

Conversation

jhsimpson
Copy link
Collaborator

addresses the first half of #36
Adds a new query parameter to each api endpoint called 'ordering'.
Also fixes some typos in the descriptions of other query parameters.

Adds  a new query parameter 'ordering' to the /tools GET request.
Defines 3 properties that this request can be ordered by.

related to #36
show how to request descending order in responses.
Add 'ordering' as a query parameter for all api endpoints.
@jhsimpson jhsimpson added this to the v1.3.0 milestone Jun 12, 2024
@jackdos
Copy link
Collaborator

jackdos commented Jun 25, 2024

@jhsimpson is the d-{order_field} a convention you've seen or used elsewhere? I've been having a quick dig around how other APIs do this and can't see an obvious consensus. I've seen sort, sortBy, orderBy among others, so I don't have a particularly strong opinion on "ordering", but I've not seen the d- elsewhere. I've seen just a negation (e.g. ?sort_by=-field), specific second parameter for direction (e.g. ?sort_by=field&order/direction=asc/desc), and combination using a separator (e.g. ?sort_by=field:asc).

Given that there doesn't seem to be a particularly strong convention, I'm mostly happy as long as we're consistent, just wondering where the d- came from?

changes the prefix used to specify 'descending' from "d-" to "-".

The "d-" convention was a workaround to a bug in the typescript openapi-generator , but that bug has been fixed.  Using a simple - is more common.
@jhsimpson
Copy link
Collaborator Author

jhsimpson commented Jul 10, 2024

It is a fair question. The 'd-' is not a common convention. It is a workaround to a bug that used to exist in the openapi-generator that couldn't handle keys in an enum that begin with + or -. I added a commit just now to change this to using a simple '-' instead of 'd-'.

I agree there isn't a single dominant convention, and I do not personally have a strong inclination to one over the other. Of the 3 examples you gave, I prefer using a '-' to indicate descending order (?ordering=foo,-bar) over the use of a separator (?ordering=foo,bar:desc) or the use of a 2nd query parameter for direction.

The convention of a '-' for reverse ordering is used in Django (see for example https://medium.com/@KaziMushfiq1234/ordering-filter-in-django-rest-framework-cfe0a86adee6).
The OData protocol uses " desc" (like $orderby=Rating desc , see
https://www.odata.org/documentation/odata-version-2-0/uri-conventions/).

@jhsimpson jhsimpson requested a review from jackdos July 10, 2024 13:06
@jhsimpson jhsimpson self-assigned this Jul 10, 2024
api/par-api.yaml Outdated Show resolved Hide resolved
jhsimpson and others added 2 commits July 22, 2024 15:33
make the description of how to order match the implementation.
jackdos
jackdos previously approved these changes Aug 7, 2024
api/par-api.yaml Outdated
Comment on lines 148 to 149
- -name
- -last-modified-date
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these double-hyphened repeats deliberate? It might just be outside of my experience. Every ordering param has a repeat set, am curious.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhhh, the penny drops, it's for reverse ordering...

@jhsimpson jhsimpson closed this Sep 4, 2024
Add a new `orderNameLastModDateParam` to support a standard way of ordering most get requests.
Addresses the first half of #36
@carlwilson carlwilson merged commit 6fa48d6 into main Sep 4, 2024
10 checks passed
@carlwilson carlwilson deleted the feat/add-ordering branch September 4, 2024 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants