exonn-gmbh / scramble-spatie-query-builder

这是Scramble扩展,用于检测Spatie查询构建器的使用,并将适用的查询参数添加到openapi定义中

v1.0.4 2024-09-05 15:53 UTC

This package is auto-updated.

Last update: 2024-09-05 15:54:33 UTC


README

Preview

简介

这是Scramble扩展,它可以检测您API路由中Spatie查询构建器的使用,并自动将适用的查询参数添加到openapi定义中。

安装

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

用法

  1. 在您的 config/scramble.php 文件中注册此扩展
'extensions' => [
    // ...
    \Exonn\ScrambleSpatieQueryBuilder\AllowedFieldsExtension::class,
    \Exonn\ScrambleSpatieQueryBuilder\AllowedSortsExtension::class,
    \Exonn\ScrambleSpatieQueryBuilder\AllowedFiltersExtension::class,
    \Exonn\ScrambleSpatieQueryBuilder\AllowedIncludesExtension::class,
//    \Exonn\ScrambleSpatieQueryBuilder\AllowedFilterModesExtension::class
],
  1. 完成,现在检查Scramble文档中使用了Spatie查询构建器的路由,您应该会看到新查询参数的文档

自定义

默认情况下,此扩展会自动为您更新openapi定义,但如果您想自定义其默认行为,可以按照以下方式进行操作

  1. 打开您的 AppServiceProvider.php 并在 boot 方法中添加以下代码示例
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. 根据您的需求进行自定义