Skip to content

Add API mod page search endpoint with scope checks#114

Merged
ItsNeil17 merged 4 commits into
HytaleModding:mainfrom
Alechilles:feature/api-mod-search-endpoint
May 1, 2026
Merged

Add API mod page search endpoint with scope checks#114
ItsNeil17 merged 4 commits into
HytaleModding:mainfrom
Alechilles:feature/api-mod-search-endpoint

Conversation

@Alechilles
Copy link
Copy Markdown
Contributor

Summary

Adds an API-key scoped search endpoint for mod documentation pages and hardens the implementation for production use.

What Changed

  • Added GET /api/mods/{mod}/pages/search (scope: read:mods:search)
  • Searches published pages by title, slug, and content
  • Returns ranked results with id, title, slug, kind, url, and snippet
  • Added read:mods:search to make:apikey available scopes

Security / Robustness

  • Avoids route collision with page slug search by using /pages/search
  • Rejects wildcard-only queries (%/_) with 422 to avoid broad table scans
  • Keeps existing API key, scope, visibility, and external_access checks

Performance / Consistency

  • Removed an unnecessary owner eager load in the search mod lookup path
  • Kept API style consistent with existing ModController client endpoints

Tests

  • Added feature coverage for:
    • API key requirement
    • scope requirement (read:mods:search)
    • ranked published-result behavior
    • mod id + limit behavior
    • external_access denial
    • wildcard-only query rejection
    • regression: page slug search still resolves via GET /api/mods/{mod}/{page}
  • Full suite passes locally: 156 tests, 599 assertions

@Alechilles
Copy link
Copy Markdown
Contributor Author

Context: https://discord.com/channels/1440173445039132724/1477353404564246682/1490101028115316908

The purpose of this PR is to enable a Discord bot I made to search full content on the wiki instead of just slugs. I theoretically could scrape the pages and cache the content but it seems silly to essentially duplicate the content when we could just use the HytaleModding API directly.

@ItsNeil17 ItsNeil17 requested review from Copilot and removed request for okunamayanad April 5, 2026 06:14
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new API-key + scope protected endpoint to search published documentation pages for a given mod, along with supporting CLI scope discovery and feature tests.

Changes:

  • Added GET /api/mods/{mod}/pages/search endpoint gated by read:mods:search.
  • Implemented page search in ModController@search (title/slug/content matching + ranked ordering + snippets).
  • Added feature tests covering auth/scope/access checks, ranking behavior, and route collision regression.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
tests/Feature/Api/ModApiSearchTest.php Adds feature tests for the new scoped search endpoint and route-collision regression.
routes/api.php Registers the new /pages/search route with the read:mods:search scope middleware.
app/Http/Controllers/Api/Client/ModController.php Implements the search handler, including validation, access checks, ranking, and response shaping.
app/Console/Commands/MakeApiKey.php Exposes the new read:mods:search scope in the interactive scope selection list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/Http/Controllers/Api/Client/ModController.php Outdated
Comment thread app/Http/Controllers/Api/Client/ModController.php Outdated
Comment thread app/Console/Commands/MakeApiKey.php
@Alechilles
Copy link
Copy Markdown
Contributor Author

@ItsNeil17 hey just wondering if you know when this will be merged? :)

@ItsNeil17 ItsNeil17 merged commit 92b08e8 into HytaleModding:main May 1, 2026
4 checks passed
@ItsNeil17
Copy link
Copy Markdown
Member

Squash merged. Please use conventional commit messages from next time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants