在swagger-php
的Example
下有示例寫法。拿過來分析記錄。php
swagger官方註解:https://bfanger.nl/swagger-explained/#schemaObject
gojson
/** * @SWG\Swagger( * schemes={"http"}, * host="api.com", * basePath="/v1", * @SWG\Info( * version="1.0.0", * title="API接口文檔", * description="測試swagger文檔項目", * @SWG\Contact( * name="wxp", * email="panxxxx@163.com" * ) * ), * @SWG\ExternalDocumentation( * description="wxp", * url="./" * ) * ) */
效果圖:api
Base URL 是 host + basePath 拼接出來的
。Info : 文檔描述。app
ExternalDocumentation":外部文檔連接。測試
Contact :聯繫開發者,發送郵件。ui
/** * @SWG\Tag( * name="pet", * description="你的寵物信息", * @SWG\ExternalDocumentation( * description="查看更多", * url="" * ) * ) * @SWG\Tag( * name="store", * description="查看寵物店訂單" * ) * @SWG\Tag( * name="user", * description="用戶操做記錄", * @SWG\ExternalDocumentation( * description="關於寵物店", * url="http://swagger.io" * ) * ) */
/** * @SWG\Get( * path="/pet/{petId}", * summary="經過ID查詢寵物", * description="返回寵物信息", * operationId="getPetById", * tags={"pet"}, * consumes={"application/json", "application/xml"}, * produces={"application/xml", "application/json"}, * @SWG\Parameter( * description="ID of pet to return", * in="path", * name="petId", * required=true, * type="integer", * format="int64" * ), * @SWG\Response( * response=200, * description="successful operation", * @SWG\Schema(ref="#/definitions/Pet") * ), * @SWG\Response( * response="400", * description="Invalid ID supplied" * ), * @SWG\Response( * response="404", * description="Pet not found" * ), * security={ * {"api_key": {}} * } * ) */
parameters:參數列表url
response: 描敘了來自API操做的單個響應spa
<?php /** * @SWG\Schema( * property="name", * type="array", * @SWG\Items( * required={"username"}, * @SWG\Property( * property="firstName", * type="string", * description="firstName" * ), * @SWG\Property( * property="ID", * type="integer", * description="user_id" * ), * @SWG\Property( * property="username", * type="string", * description="username" * ) * ) * ) */