本文主要是介绍Pont深坑,与swagger 2.9的兼容问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Pont是一个很好的前后端一体化工具,能够帮助自动生成API代码。
今天正在整Pont的时候,发现个别API参数在pont里无法导出,经过反复的对比发现。只要使用了@ApiParam或@ApiImplicitParam的参数,都无法正常被pont导出。例如定义的接口如下:
@PostMapping("testPost")@ApiOperation(value = "后台管理员登录aaaa")public String testPost(@ApiParam("登录ID--》") String loginId,String userPsw, String validateCode, String sid,@ApiIgnore RequestSite adminSite, HttpServletResponse response){return loginId + " " + userPsw;}
发现实际生成的Pont接口api.d.ts如下:
declare namespace API {/*** Common Admin Controller*/export namespace commonAdmin {/*** 后台管理员登录* /admin/common/doLogin*/export namespace doLogin {export class Params {}export type Response = stringexport const init: Responseexport function request(params: Params, body: string, options?: any): Promise<Response>}
被@ApiParam注解的项,无法被正常导出。
看了下swagger的docs接口,生成的API json如下:
"/admin/common/testPost": {"post": {"tags": ["common-admin-controller"],"summary": "后台管理员登录aaaa","operationId": "testPostUsingPOST","parameters": [{"name": "adminToken","in": "header","description": "adminToken 后台Token","required": false,"type": "string"}, {"in": "body","name": "loginId","description": "登录ID--》","required": false,"schema": {"type": "string"}}, {"name": "sid","in": "query","description": "sid","required": false,"type": "string"}, {"name": "userPsw","in": "query","description": "userPsw","required": false,"type": "string"}, {"name": "validateCode","in": "query","description": "validateCode","required": false,"type": "string"}],"responses": {"200": {"description": "OK","schema": {"type": "string"}},"401": {"description": "Unauthorized"},"403": {"description": "Forbidden"},"404": {"description": "Page Not Found"},"500": {"description": "Server Internal Error"}},"deprecated": false}},
使用swagger参数注解的项格式有点小变化,例如type放到了schema项之内。可能这个差异导致了pont解析不出来吧。
目前暂时的解决方法就是,不使用@ApiParam和@ApiImplicitParam注解。
可能 Swagger V3接口可以正常吧,暂时不调整了。
这篇关于Pont深坑,与swagger 2.9的兼容问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!