Skip to content

Scramble extension that integrates with Spatie query builder

License

Notifications You must be signed in to change notification settings

exonn-GmbH/scramble-spatie-query-builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scramble extension for Spatie Query Builder

Preview

Introduction

This is the Scramble extension, which detects the usage of the Spatie query builder in your api routes and automatically adds applicable query parameters to the openapi definition.

Installation

composer install exonn-gmbh/scramble-spatie-query-builder

Usage

  1. Register the extension in your config/scramble.php file
'extensions' => [
    // ...
    \Exonn\ScrambleSpatieQueryBuilder\AllowedFieldsExtension::class
    \Exonn\ScrambleSpatieQueryBuilder\AllowedSortsExtension::class
    \Exonn\ScrambleSpatieQueryBuilder\AllowedFiltersExtension::class
    \Exonn\ScrambleSpatieQueryBuilder\AllowedFilterModesExtension::class
    \Exonn\ScrambleSpatieQueryBuilder\AllowedIncludesExtension::class
],
  1. You are done, now check your Scramble docs for routes that use Spatie query builder, you should see new query parameters documented

Customization

By default this extension automatically updates openapi definition for you, but if you want to customize its default behaviour, you can do it in the following way

  1. Open your AppServiceProvider.php and add the following code example in the boot method
public function boot(): void
{
    // ...
    AllowedIncludesExtension::hook(function(Operation $operation, Parameter $parameter) {
        // Customize the example
        $parameter->example(['repositories.issues', 'repositories']);
        // Customize the description
        $parameter->description('Allows you to include additional model relations in the response');
    });
}
  1. Customize for your needs

TODO

  • Add tests