当前位置:网站首页>Swagger documentation details
Swagger documentation details
2022-06-12 09:09:00 【Eden Garden】
1、Swagger Introduce
Swagger Is a specification and complete framework , Used to generate 、 describe 、 Invocation and visualization RESTful Style Web service (http
s://swagger.io/). Its main function is :
- It makes it more convenient to separate the front end from the back end , It's good for teamwork
- Documentation of the interface is automatically generated online , Reduce the burden of writing interface documents for back-end developers
- A functional test Spring Have already put Swagger Include your own criteria , Established Spring-swagger project , Now called Springfox. By means of Introduced in the project Springfox , You can use it very simply and quickly Swagger
2、SpringBoot Integrate Swagger
- Introduce dependencies
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>
We usually configure it in public projects , Because other microservice projects directly or indirectly depend on
2. Modify the configuration file
# Turn on swagger
swagger.enable=true
3. In the corresponding project config Add a configuration class to the package
@Configuration
// And configuration files application.propertis The configuration in corresponds to
// havingValue If the value of is equal to the value of the configuration file , Just open swagger
@ConditionalOnProperty(prefix = "swagger",value = {
"enable"},havingValue = "true")
@EnableSwagger2 // Turn on swagger Annotation support
public class SwaggerConfiguration {
@Bean
public Docket buildDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(buildApiInfo())
.select()
// To scan API(Controller) Basic package
.apis(RequestHandlerSelectors.basePackage("cn.ittest.xxx"))
.paths(PathSelectors.any())
.build();
}
private ApiInfo buildApiInfo() {
Contact contact = new Contact(" The programmer ","","");
return new ApiInfoBuilder()
.title(" Development platform - Customer service API file ")
.description(" Include user services api")
.contact(contact)
.version("1.0.0").build();
}
}
3、Swagger Commonly used annotations
stay Java Class Swagger You can generate Swagger Interface document , Commonly used Swagger The comments are as follows :
@Api: Decorate the whole class , describe Controller The role of
@ApiOperation: A method that describes a class , Or an interface
@ApiParam: Description information of a single parameter
@ApiModel: Use objects to receive parameters
@ApiModelProperty: When receiving parameters with objects , A field describing an object
@ApiResponse:HTTP In response to 1 Description (s)
@ApiResponses:HTTP Respond to the overall description
@ApiIgnore: Use this annotation to ignore this API
@ApiError : Information returned in the event of an error
@ApiImplicitParam: A request parameter
@ApiImplicitParams: Description information of multiple request parameters
@ApiImplicitParam attribute :
We are ConsumerController Add Swagger annotation , The code is as follows :
@RestController
@Api(value = " Test service Controller", tags = "Consumer", description = " Test service API")
public class ConsumerController {
@ApiOperation(" Test whether I love you ")
@PostMapping(path = "/love")
@ApiImplicitParam(name = "name", value = " full name ", required = true, dataType = "String")
public String hi(String name) {
return " I love " + name;
}
}
Access after startup : http://localhost: Port number / service name /swagger-ui.html
The effect is as follows :
Swagger Generate API How documents work :
1、 When the service is started, it will scan SwaggerConfiguration class
2、 The scan package path is specified in this class cn.ittext., You will find the package and sub package marked with @RestController Annotated controller class
3、 according to controller Class Swagger Annotation generation API file
边栏推荐
- [character set 8] char8_ t、char16_ t、char32_ t、wchar、char
- Top command meaning
- Basic exercise letter graphics
- Résoudre le problème de demander à l'élément d'être ouvert lorsque l'unit é est ouverte et que vous n'avez pas été ouvert auparavant (peut - être fermé anormalement auparavant)
- Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?
- MySQL learning records -- III. MySQL query statements
- consul 配置相关
- 43 cas d'analyse du réseau neuronal MATLAB: chapitre 7 régression du réseau RBF - - réalisation de la régression fonctionnelle non linéaire
- ABC253F Operations on a Matrix
- Exists usage in SQL
猜你喜欢

Multi table operation instance

MySQL learning record - II. MySQL create table command

Application method of new version UI of idea + use method of non test qualification and related introduction

43 cas d'analyse du réseau neuronal MATLAB: chapitre 7 régression du réseau RBF - - réalisation de la régression fonctionnelle non linéaire

node示例后台搭建

【字符集七】汉字的宽字符码和多字节码分别是多少

Xshell startup encountered "unable to continue code execution because mfc110.dll cannot be found"

Summary of common character sets

torch. logical_ And() method

MFS explanation (IV) -- MFS management server installation and configuration
随机推荐
MySQL learning records -- III. MySQL query statements
软件测试报告中常见的疏漏,给自己提个醒
Knowledge points of 2022 system integration project management engineer examination: project cost management
Binlog in mysql:
Tool classes for extracting zip files
[character set 7] what are the wide character codes and multi byte codes of Chinese characters
MySQL learning record - II. MySQL create table command
Full alphabetic arrangement (pure alphabetic password dictionary)
Multi table operation instance
【字符集六】宽字符串和多字节字符互转
Technology cloud report: how will the industrial Internet rebuild the security boundary in 2022?
EIP-1559
List < string > sort
Consumer configuration related
Chapter 8 - two basic problems of data processing
(十二)交互组件Selectable
长安链节点证书、角色、权限管理介绍
Diff prime pairs
Binary tree calculation problem
Chapter IV - first procedure