繁体   English   中英

如何在没有symfony的情况下使用nelmio / api-doc-bundle?

[英]How to use nelmio/api-doc-bundle without symfony?

我的Web应用程序不基于Symfony或任何其他开源框架。

我如何仍然使用nelmio / api-doc-bundle包从类注释生成API文档?

nelmio-api-doc捆绑包仅由symfony平台制成,因此如果没有symfony,您将无法使用它。

如果您只想使用API​​文档,那么https://swagger.io/swagger-ui/可能会对您有所帮助。 swagger提供了基于ymal和json(注释也是symfony的一部分)的文档,并实现了大多数流行的工作平台。

实际上nelmio-api-doc捆绑包使用swagger-ui作为API文档提供程序(在配置设置https://github.com/nelmio/NelmioApiDocBundle中

您当然可以在lib中要求,但是由于它是一个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/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM