Sorting Issue: Incorrect Order when Sorting Monsters by Size
Issue: When attempting to sort monsters by size using the Open5E API, there is an inconsistency in the sorting order. Currently, when sorting in descending order, the first results include "Titanic" monsters, followed by "Tiny" monsters, which deviates from the expected sorting order.
Steps to Reproduce: Use the API endpoint for sorting monsters by size in descending order: https://api.open5e.com/monsters/?ordering=-size Observe that the first results include "Titanic" monsters, but instead of continuing in descending order, the subsequent monsters are "Tiny."
Expected Behavior: When sorting monsters by size in descending order, the expected order should be from the largest size category ("Titanic") to the smallest size category ("Tiny") according to the standard D&D size classification.
Note: If I'm using the API incorrectly, please clarify the correct usage. However, if this is indeed a bug, I am willing to try to solve it and submit a pull request.
Thank you for your assistance!
This is because the API lacking any awareness for what "size" classification means in D&D and is just sorting alphabetically. A possible solution is to add a new numeric field e.g. size_rating where a tiny creature is 0, small is 1, and so forth. This would be similar to how the cr and challenge_rating fields work.
Size is defined here on the Monster Model: https://github.com/open5e/open5e-api/blob/b16e3d12b739eb1801935f2ebc6c90d47029f5b3/api/models/monster.py#L11
Thanks. So just to be sure, I need to add the representation in open5e-api/api/models/monster.py and I need to add the data itself in the for all the monsters in the json. Do i need to change something in api_v2?
also i have found that there is a file Monster.json_SKIPPED. do i need to change it?
i have created a pull request that can be seen here #401
I have an alternative solution to this that covers all approaches in #425
It looks great! Does it require any changes to the monster.json?.
I'm calling this resolved within V2. While it doesn't solve v1 at this time, the long-term plan will be to transition to v2. This feature is fully supported in v2 by doing a size lookup for any creature or item, then sorting on the Rank field. https://api-beta.open5e.com/v2/sizes/