Php-Swagger代码了解

前言 良好的文档规范,对于前后端的沟通是很有必要的,减少没必要的误解和争执,前端也可以根据文档的格式先制定出页面的流程和提前mock数据开发 目标 前置条件 zircote/swagger-php document 正式内容 1. 基础了解定义文档的语法 文档描述 @OA\Info(title=“Fapi”, version=“0.1”,description=“antdv5的接口前缀为/api/v2 当前版本为/api/返回列表的格式有区别外其他一致”), 文档中的api路径 @OA\Server(url=“http://www.github.com/",description="github",), 预先定义好返回数据的格式 @OA\Schema( schema=“Pagination”, @OA\Property(property=“current”, type=“integer”), @OA\Property(property=“total”, type=“integer”), @OA\Property(property=“pageSize”, type=“integer”), ) 分组每种接口的类别,如/user, /order /record 等, @OA\Tag(name=“api-tag”, description=“Tag”) 编写接口的声明 @OA\Post( path="/api/index", summary="api name", operationId="UniqueOperationId", tags={"api-tag"}, @OA\Parameter(in="query", name="fIDDomainFolder", required=false,schema={"type":"string"},description=""), @OA\Parameter(in="query", name="intActive", required=false,schema={"type":"integer"},description=""), @OA\Parameter(in="query", name="timetype", required=false,schema={"type":"string","enum":{"created_at","expired_at","update_at"}},description="时间类型"), @OA\Response( response="200", description="An example resource", @OA\JsonContent( @OA\Property(property="Pagination",type="object", ref="#/components/schemas/Pagination"), ) ), ) 2. 将定义好的注释声明生成openapi.json $openapi = \OpenApi\Generator::scan([ path . 'api', path . 'model', ]); $openapi->toJson() 3....

八月 12, 2022 · 1 分钟 · Ken