[英]How to add swagger annotation for rest endpoint @GetMapping(“/**”)?
I wanted to add swagger implementation for below snippet. 我想在下面的代码片段中添加大张旗鼓的实现。 But couldn't find exact annotation to read url input from swagger.
但是找不到确切的注释来读取招摇的网址输入。
Tried using, 尝试使用,
@ApiOperation(httpMethod = "GET",value = "Get Value",response = String.class)
@ApiImplicitParams({@ApiImplicitParam(name="basePath",paramType = "path")
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
above code didn't help. 上面的代码没有帮助。
@GetMapping(value = "/**")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
Expectation is to get a url as input via swagger-ui and return the same as response. 期望通过swagger-ui获得URL作为输入,并返回与响应相同的URL。
Let suppose that your controller look like : 假设您的控制器看起来像:
package com.sample.controller;
@RestController
@RequestMapping
@Api(value = "GreetingsController", tags = {"Just for greetings"})
Public class GreetingsController{
@ApiOperation(httpMethod = "GET", value = "Get value",notes = "description")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 500, message = "Internal Error")
})
@GetMapping(value = "/")
public String getUrlPath(HttpServletRequest request){
return request.getServletPath();
}
}
The Dependency: 依赖关系:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version> <!-- maybe there a new version -->
</dependency>
Configurations: 配置:
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configurable
public class AppConfig{
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).groupName("GroupeName").apiInfo(apiInfo())
.select().paths(PathSelectors.regex(".*controller.*")).build();
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("©Licence").licenseUrl("").version("1.0").build();
}
}
Application.yml: Application.yml:
server:
port: 8111
servlet:
context-path: /exampleApp
Access url : http://localhost:8111/exampleApp/swagger-ui.html
访问网址:
http://localhost:8111/exampleApp/swagger-ui.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.