lsbproject / request-doc-bundle
此包已被放弃,不再维护。未建议替代包。
request-bundle 的 OpenApi 3.0 自动文档
v3.0.0
2021-08-13 19:50 UTC
Requires
- php: >=7.4
- lsbproject/request-bundle: ^6
- nelmio/api-doc-bundle: ^v4
Requires (Dev)
- roave/security-advisories: dev-latest
README
request-bundle 的 OpenApi 3.0 自动文档。为 nelmio/api-doc-bundle 添加了 AbstractRequest
描述器
安装
步骤 1: 下载包
打开命令行,进入您的项目目录,并执行以下命令以下载此包的最新稳定版本
$ composer require lsbproject/request-doc-bundle
此命令要求您全局安装了 Composer,如 Composer 文档的安装章节中所述。
步骤 2: 启用包(如果未安装 composer flex)
然后,通过将其添加到项目 config/bundles.php 文件中注册的包列表中来启用该包
// config/bundles.php return [ // ... LSBProject\RequestDocBundle\LSBProjectRequestDocBundle::class => ['all' => true], ];
示例
<?php declare(strict_types=1); namespace App\DTO; use App\Entity\TestEntity; use App\Service\TestService; use LSBProject\RequestBundle\Configuration as LSB; use LSBProject\RequestBundle\Request\RequestInterface; use OpenApi\Annotations as OA; use Symfony\Component\Validator\Constraints as Assert; /** * @OA\RequestBody(@OA\MediaType(mediaType="application/json")) */ class TestRequest implements RequestInterface { /** * @Assert\NotBlank() * @Assert\Choice({"foo", "bar"}) * @LSB\PropConverter(name="foo_bar") * @LSB\RequestStorage({LSB\RequestStorage::QUERY}) * @OA\Property(description="Some awesome property") */ public string $foo; /** * Some awesome title * * Interesting description * * @LSB\PropConverter("App\Service\TestService") * @LSB\RequestStorage({LSB\RequestStorage::BODY}) */ public TestService $service; /** * @LSB\RequestStorage({LSB\RequestStorage::QUERY}) */ public int $testId; /** * @Assert\NotBlank() * @LSB\RequestStorage({LSB\RequestStorage::BODY}) */ private bool $barBaz; /** * @LSB\Entity(options={"id": "test_id"}) * @LSB\RequestStorage({LSB\RequestStorage::BODY}) */ public TestEntity $entity; /** * @LSB\Entity(expr="repository.find(id)", mapping={"id": "test_id"}) * @LSB\RequestStorage({LSB\RequestStorage::BODY}) */ public TestEntity $entityB; /** * @LSB\Entity(options={"mapping": {"bar_baz": "text"}}) * @LSB\RequestStorage({LSB\RequestStorage::BODY}) */ public TestEntity $entityC; /** * @LSB\PropConverter(isDto=true) * @LSB\RequestStorage({LSB\RequestStorage::QUERY}) */ public SubRequest $params; public function setBarBaz(bool $flag): void { $this->barBaz = $flag; } public function getBarBaz(): bool { return $this->barBaz; } }
在控制器中无需用注解指向模型。只需在方法参数中注入类即可。
/** * @Route("/123") */ public function test(TestRequest $testRequest): Response { return new Response((string)$testRequest->params->subfoo); }