OpenAPI规范支持请求正文(对于POST请求等最为有用):
paths:
/pets:
post:
summary: Add a new pet
requestBody:
description: Optional description in *Markdown*
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
'201':
description: Created
Laravel请求方法通常看起来像这样:
public function create(JsonRequest $request): UserResource
{
$data = $request->json()->all();
$user = User::create($data);
$user->save();
return new UserResource($user);
}
是否有办法从中发现请求主体(请求主体可能包括/需要哪些字段,字段具有哪些类型),以便能够将其包含在API规范中?