作者:要么永远要么消失_324 | 来源:互联网 | 2023-07-16 19:00
在swagger-php的Example下有示例写法。拿过来分析记录。swagger官方注解:https:bfanger.nlswagger-explained#schemaObj
在swagger-php
的Example
下有示例写法。拿过来分析记录。
swagger官方注解:https://bfanger.nl/swagger-explained/#schemaObject
go
1. 文档标题部分
/**
* @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="./"
* )
* )
*/
效果图:
2. tag标签部分,用于文档分类
/**
* @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"
* )
* )
*/
- name : 名称(功能模块)
- description : 描述
3. 接口注释写法
/**
* @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": {}}
* }
* )
*/
4. 定义对象
5.type 为array的写法
/**
* @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"
* )
* )
* )
*/