我正在编写 OpenAPI 规范并尝试从请求路由/路径的注释中自动(使用 swagger-php)生成我可能的查询参数。我知道我可以为每条路由输入所有可能的参数选项,但我确实需要能够使用注释自动从类的属性中生成可能的参数,就像我可以为请求正文做的那样。(我们将拥有大量的类/路径,并且除非它们像请求正文/JsonContent 那样生成,否则很可能不会发生这种情况。这对于 swagger-php 甚至是一般的 OpenAPI 是否可行?
我让它与 put 和 request body 一起工作,但是对于仍然使用类属性的 get 请求,我该如何做呢?
我可以为请求正文执行此操作:
/**
* @return Response
*
* * @OA\Put(
* path="/persons",
* tags={"Person"},
* @OA\RequestBody(
* request="person",
* required=false,
* description="Optional Request Parameters for Querying",
* @OA\JsonContent(ref="#/components/schemas/Person")
* ),
* @OA\Response(
* response="200",
* description="Returns matching Person Object",
* @OA\JsonContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Person")
* )
* )
* )
*/
写出 30 多个类的每个参数将无法维护:
/** @OA\Get(
* path="/events",
* tags={"Events"},
* @OA\Parameter(
* name="eventID",
* in="query",
* required=false,
* description="The event ID specific to this event",
* @OA\Schema(
* type="string"
* ),
* ),
*
* ....etc