package com.example.config
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.google.common.base.Predicate;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
public @Bean Docket restApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().paths(paths()).build();
}
/**
* Url for documentation.
*
* @return
*/
private Predicate<String> paths() {
return regex("/basepackage of your restcontroller/*");
}
/**
* Description your application
*
* @return
*/
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("App title").description("App description")
.termsOfServiceUrl("").license("").licenseUrl("").version("1.0").build();
}
}
Вот пример контроллера:
@Api(value = "membre")
@RestController
public class ExampleControleur {
@RequestMapping(value = "/find", method = RequestMethod.GET, produces = {
MediaType.APPLICATION_JSON_VALUE }, consumes = { MediaType.APPLICATION_JSON_VALUE })
@ApiOperation(httpMethod = "GET", value = "example text", notes = "note text ")
@ResponseBody
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK !"),
@ApiResponse(code = 422, message = "description."),
@ApiResponse(code = 401, message = "description"),
@ApiResponse(code = 403, message = "description"),
@ApiResponse(code = 404, message = "description"),
@ApiResponse(code = 412, message = "description."),
@ApiResponse(code = 500, message = "description.") })
@ApiImplicitParams({
@ApiImplicitParam(name = "params1", value = "description.", required = true, dataType = "string", paramType = "query", defaultValue = "op"),
@ApiImplicitParam(name = "params2", value = "description.", required = true, dataType = "string", paramType = "query")})
public ResponseEntity<MyObject> getObjet(@RequestParam(value = "params1", required = true) Params1 params1,
@RequestParam(value = "params2", required = true) String param2){
}
}
Вы можете протестировать с этим классом, но я полагаю, что вы написали все аннотации swagger в ваших контроллерах!
Вы можете добавить в свой основной класс @ComponentScan(basePackages={"the package of your config swagger class"})
URL-адрес доступа должен быть http://localhost:port/context-path if you have it/swagger-ui.html