exonn-gmbh/scramble-spatie-query-builder

This is the Scramble extension, which detects the usage of the Spatie query builder and adds applicable query parameters to the openapi definitions

v0.9.1 2024-04-05 15:25 UTC

This package is auto-updated.

Last update: 2024-05-05 15:40:30 UTC


README

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\Extension::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
{
    // ...
    Extension::hook(function(Operation $operation, Parameter $parameter, \Laya\ScrambleQueryBuilder\QueryBuilderFeature $feature) {
        if($feature->getMethodName() === 'allowedIncludes') {
            // Customize the example
            $parameter->example(['repositories.issues', 'repositories']);
            // Customize the description
            $parameter->description('Allows you to include additional model relations in the response');
        }
            
        if($feature->getMethodName() === 'allowedSorts') { 
            // ...
        }
            
        if($feature->getMethodName() === 'allowedFields') {
            // ...
        }
            
        if($feature->getMethodName() === 'allowedFilters') {
             // ...
        }
    });
}
  1. Customize for your needs

TODO

  • Add tests