Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to get started with swagger ui

Shulou Source: shulou.com Published: 2022-06-02 03:22:22 10月03日 Update

This article introduces you how to get started with swagger ui, the content is very detailed, interested friends can use for reference, I hope it can be helpful to you.

Quick start

1 introduce related dependencies

Com.yishuifengxiao.common common-spring-boot-starter 4.1.2

2 enable configuration

Add the following configuration to the configuration file to quickly turn on the swagger-ui function.

The path of the controller code that yishuifengxiao.swagger.base-package= needs to scan

After adding the above configuration, you can view the swagger-ui enhancement documentation through http://ip:port/doc.html.

You can also view swagger-ui native documents through http://ip:port/swagger-ui.html.

In addition, you can view metadata through http://ip:port/v2/api-docs

This only simplifies the scanning annotations of swagger-ui, and other API annotations that must be swagger-ui in the software development process can not be omitted.

Here is an example of a simple swagger-ui configuration document

@ Api (value = "[test interface] test interface", tags = {"test interface"}) @ Valid@Controller@RequestMapping@Slf4jpublic class WebConftroller {@ ApiImplicitParams ({@ ApiImplicitParam (name = "username", value = "login user name"), @ ApiImplicitParam (name = "loginIp", value = "login ip"), @ ApiImplicitParam (name = "pass", value = "login result, true indicates success False failed "), @ ApiImplicitParam (name =" pageSize ", value =" Page size, paging size cannot be less than 1, default value is 20 "), @ ApiImplicitParam (name =" pageNum ", value =" Page number of the current page, page number cannot be less than 1 " Default is 1 ")}) @ ApiOperation (value =" paging query login record ", notes =" paging query login record ") @ GetMapping (" / demo ") @ ResponseBody public Response findPage (HttpServletRequest request, HttpServletResponse response, @ RequestParam (value =" username ", required = false) String username, @ RequestParam (value =" loginIp ", required = false) String loginIp, @ RequestParam (value =" pass ", required = false) Boolean pass @ RequestParam (name = "pageSize", defaultValue = "20", required = false) Integer pageSize, @ RequestParam (name = "pageNum", defaultValue = "1", required = false) Integer pageNum) {return Response.suc () }}

Special thanks:

The function in the doc.html interface of this function uses the function of brother Dao's swagger-bootstrap-ui. Here, I would like to thank brother Dao for his strong support. For more information on swagger-bootstrap-ui, please refer to brother Dao's swagger-bootstrap-ui document.

Configuration parameter # title of swagger-ui document yishuifengxiao.swagger.title=API interface document # swagger-ui document description yishuifengxiao.swagger.description= interface description document # name of urlyishuifengxiao.swagger.terms-of-service-url= http://www.yishuifengxiao.com/# swagger-ui document grouping for swagger-ui project service yishuifengxiao.swagger.group-name=default# swagger-ui document version yishuifengxiao.swagger.version=1.0.0# project contact name yishuifengxiao Urlyishuifengxiao.swagger.contact-url= http://www.yishuifengxiao.com/# project contact email address yishuifengxiao.swagger.contact-email=zhiyubujian@163.com for .swagger.contact-user=yishuifengxiao# project contact

The above general configurations all have default values. Users can use the default configuration if they do not have special needs when using the general components of easy Water and Wind Shaw.

Advanced configuration

In general, the regular configuration of swagger-ui can be used to meet daily development needs, but in some cases, some advanced configuration may be required. For example, by adding a default parameter in batches on all API interfaces, the advanced configuration features of common components are now available.

Yishuifengxiao.swagger.contact.auths [0] .name = Authorizationyishuifengxiao.swagger.contact.auths [0] .description = custom required request header yishuifengxiao.swagger.contact.auths [0] .modelRef = stringyishuifengxiao.swagger.contact.auths [0] .parameterType = headeryishuifengxiao.swagger.contact.auths [0] .required = false

The above example configuration adds a request header parameter named Authorization in bulk to all requests in the API document. Yishuifengxiao.swagger.contact.auths is an array and multiple configurations can be added.

On how to get started with swagger ui to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Configuration documentation interface features login parameters project size test contact advanced content can be passed name general situation more comments users examples Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi Huawei Linux Shulou Information MySQL