在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" * ) * ) * ) */