在Linux系统中使用Swagger时,通过合理运用Swagger生态工具链,Python开发者可将接口测试效率提升%以上。以下是详细指南:
sudo apt update
sudo apt install openjdk-11-jdk
sudo apt install maven
springdoc-openapi-starter-webmvc-ui
库来集成Swagger。在pom.xml
中添加以下依赖:<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.1.0</version>
</dependency>
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@OpenAPIDefinition(info = @Info(title = "My API", version = "1.0"))
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.OAS_30)
.select()
.apis(RequestHandlerSelectors.basePackage("com.example.demo.controller"))
.paths(PathSelectors.any())
.build();
}
}
@Api
注解标记Controller类的功能。@ApiParam
注解;对于对象参数,使用@ApiModel
和@ApiModelProperty
注解。以上就是在Linux中使用Swagger的最佳实践。