og-soft / laravel-openapi-value-object
从值对象生成Laravel应用程序的OpenAPI规范
1.0.4
2021-03-05 07:28 UTC
Requires
- php: ^8.0
- cweagans/composer-patches: ^1.7
- doctrine/annotations: ^1.12
- ogsoft/laravel-openapi: ^1.2
Requires (Dev)
- orchestra/testbench: ^5.3|^6.0
- phpunit/phpunit: ^9.4
README
此库扩展了 vyuldashev/laravel-openapi。主要思想是无需手动创建模式
class UserCreateRequestBody extends RequestBodyFactory { public function build(): RequestBody { return RequestBody::create('UserCreate') ->description('User data') ->content( MediaType::json()->schema(UserSchema::ref()) ); } }
该库获取任何PHP类,并自动从类属性生成模式。您应使用PHP文档注释
class CarRequest { /** * Car name <-- auto parsed title * * This is a car name description... <-- auto parsed description * * @var string */ protected string $name; /** * Engine power in kW * * More is better * * @var int */ protected int $enginePower; /** * Wheels of car * * It is necessary to move * @var WheelValueObject[] */ protected array $wheels; /** * @return string */ public function getName(): string { return $this->name; } /** * @param string $name * @return CarValueObject */ public function setName(string $name): CarValueObject { $this->name = $name; return $this; } /** * @return int */ public function getEnginePower(): int { return $this->enginePower; } /** * @param int $enginePower * @return CarValueObject */ public function setEnginePower(int $enginePower): CarValueObject { $this->enginePower = $enginePower; return $this; } /** * @return WheelValueObject[] */ public function getWheels(): array { return $this->wheels; } /** * @param WheelValueObject[] $wheels * @return CarValueObject */ public function setWheels(WheelValueObject ...$wheels): CarValueObject { $this->wheels = $wheels; return $this; } }
输出为
(...) 'properties' => [ 'name' => [ 'title' => 'Car name', 'description' => 'This is a car name description...', 'type' => 'string', 'nullable' => false, ], 'enginePower' => [ 'title' => 'Engine power in kW', 'description' => 'More is better', 'type' => 'integer', 'nullable' => false, ], 'wheels' => [ 'title' => 'Wheels of car', 'description' => 'It is necessary to move', 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => [ 'size' => [ 'type' => 'integer', 'nullable' => true, ], 'tire' => [ 'type' => 'object', 'properties' => [ 'winter' => [ 'type' => 'boolean', 'nullable' => false, ], ], ], ], ], 'nullable' => false, ], ] (...)
用法
检查 examples/cartore/CarController.php
控制器和 exmples/carstore/OpenApi
目录。
待办事项
在拉取请求被接受后更新 composer.json
。
变更记录
- 2021-03-05 - 支持
@example