Open rashadkhan359 opened 1 month ago
Thanks for offering this @rashadkhan359!
I'm happy to include these properties, since it reflects what we already show in the BookStack search UI.
I'd rather not go down the path of optional data via the include
tag though, as I'd prefer to keep the scope of what's provided in the API aligned with our UI and what's sensible, otherwise our scope could go wild with adding extra include
tags to suit all potential use-cases.
Therefore please could you remove the include
system and just include these properties for this specific response.
Also,, rather than new custom properties like book_title
I'd prefer if we just loaded book
and chapter
properties to allow multiple properties (limited to just id, name and slug) of those elements to be shown where needed, like so:
{
// ...
"book": {
"id": 4,
"name": "My great book",
"slug": "my-great-book"
}
// ...
}
Hello @ssddanbrown, Thank you for the wonderful and insightful feedback. I've made the requested changes and updated the docs as well accordingly.
Purpose
Add the ability to include book and chapter titles in the
/api/search
endpoint results through an optionalinclude
parameter. This makes it easier for API consumers to show the full content hierarchy context for search results without additional API calls.Closes
API Request #5140
Implementation
New Features
include
parameter to/api/search
endpointtitles
- Includesbook_title
andchapter_title
for applicable entitiestags
- Include associated tags (existing functionality now controlled viainclude
)Multiple includes can be combined using comma separation.(if we want to extend on it.)
Changes
ApiEntityListFormatter::withRelatedTitles()
,ApiEntityListFormatter::loadRelatedTitles()
andSearchApiController::parseIncludes()
method.SearchApiController::$rules
SearchApiController::all()
ApiEntityListFormatter::format()
Technical Details
include
for it to be included. This behavior if problematic can be altered easily.)Testing
New test cases cover:
All existing tests pass without modification.
Documentation
The API documentation has been edited as well to cater to the new changes.
Example Request
GET /api/search?query=example&include=titles,tags
Example Response
PS
This is my first-ever contribution to open source projects. I kindly ask for a thorough review, and I'm eager to improve upon any mistakes I may have made.