簡體   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