Slide 24
Slide 24 text
サーバサイドでのスキーマ管理と統合
2024/4/18 #APINight
• 仕様をアノテーションで宣⾔。すぐ下に実装。
• レスポンスの型定義(仕様)と⽣成(実装)とを紐づけ。
ここでの定義はOpenAPIドキュメントとしていつでも出⼒可能
#[OA¥Schema(
title: 'User',
properties: [
new OA¥Property(property: 'name', type: 'string'),
new OA¥Property(property: 'email', type: 'string', format: 'email'),
new OA¥Property(property: 'birthdate', type: 'string', format: 'date-time'),
],
required: ['name', 'email', 'birthdate'],
)]
class UserResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'name' => $this->resource->name,
'email' => $this->resource->email,
'birthdate' => $this->resource->birthdate->toIso8601String(),
];
}
}
スキーマ駆動開発による品質とスピードの両⽴ 23
仕様
実装