【发布时间】:2019-05-07 14:53:13
【问题描述】:
我的 Web 应用程序不是基于 Symfony 或任何其他开源框架。
我如何仍然使用包 nelmio/api-doc-bundle 从类注释生成我的 API 文档?
【问题讨论】:
-
你需要它的依赖,它依赖于各种 Symfony 组件,所以它们需要安装。您无需在任何不想使用的地方直接在应用程序代码中使用它们。
我的 Web 应用程序不是基于 Symfony 或任何其他开源框架。
我如何仍然使用包 nelmio/api-doc-bundle 从类注释生成我的 API 文档?
【问题讨论】:
nelmio-api-doc bundle 只是 symfony 平台,所以你不能在没有 symfony 的情况下使用它。
如果您只想使用 API 文档,那么 https://swagger.io/swagger-ui/ 可能会对您有所帮助。 swagger 提供基于 ymal 和 json(注解也是 symfony 的一部分)的文档,并实现了大多数流行的工作平台。
实际上 nelmio-api-doc 包使用 swagger-ui 作为 API 文档提供者(在配置设置中 https://github.com/nelmio/NelmioApiDocBundle)
【讨论】:
你当然可以在 lib 中使用 require,但由于它是一个 Symfony 包,它会带来很多不必要的膨胀。
为什么不试试 PHP Swagger? https://github.com/zircote/swagger-php
这是你可以用它做的事情的类型:
/**
*
* @OA\Get(
* path="/oauth2/authorize",
* @OA\Response(response="200", description="An access token"),
* tags={"auth"},
* @OA\Parameter(
* name="response_type",
* in="query",
* type="string",
* description="the type of response",
* required=true,
* default="code"
* ),
* @OA\Parameter(
* name="client_id",
* in="query",
* type="string",
* description="the client identifier",
* required=true,
* default="testclient"
* ),
* @OA\Parameter(
* name="client_secret",
* in="query",
* type="string",
* description="the client identifier",
* required=false,
* default="testclient"
* ),
* @OA\Parameter(
* name="redirect_uri",
* in="query",
* type="string",
* description="where to send the response",
* required=false
* ),
* @OA\Parameter(
* name="state",
* in="query",
* type="string",
* description="with a CSRF token. This parameter is optional but highly recommended.",
* required=false,
* ),
* @OA\Parameter(
* name="scope",
* in="query",
* type="string",
* description="allowed scopes, space separated",
* required=false,
* )
* )
*/
public function authorizeAction()
{
// code
}
以下是 Swagger UI 生成的演示: https://petstore.swagger.io/
【讨论】: