2016-03-03 110 views

回答

0

我目前正在研究它,我正在使用Springfox庫來記錄它。

<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency>

<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency>

我揚鞭配置是這樣的:

我的一個端點的
@Configuration 
@EnableSwagger2 
@EnableWebMvc 
public class SwaggerConfig { 

    @Bean 
    public Docket documentation() { 
     return new Docket(DocumentationType.SWAGGER_2) 
      .select() 
       .apis(RequestHandlerSelectors.any()) 
       .paths(PathSelectors.any()) 
       .build() 
      .useDefaultResponseMessages(false) 
      .pathMapping("/") 
      .apiInfo(apiInfo()); 
    } 



    /** 
    * API INFO 
    * @return 
    */ 
    private ApiInfo apiInfo() { 
     return new ApiInfoBuilder() 
       .title("xxx") 
       .description("xxx") 
       .version("xxx")     
       .contact("xxx") 
       .build(); 
    } 
} 

第一部分(注:有標註一個地圖沒有適當的方式2.4。 0添加支持,但我還沒有嘗試過。)

@Api(value = "xxx") 
@FrameworkEndpoint 
@SessionAttributes("authorizationRequest") 
public class OAuthAuthorizationEndpoint { 

    private AuthorizationEndpoint authorizationEndpoint; 

    /** 
    * @param endpoint 
    *  base AuthorizationCheckpoint 
    */ 
    public OAuthAuthorizationEndpoint(AuthorizationEndpoint endpoint){ 
     this.authorizationEndpoint = endpoint; 
    } 
@ApiOperation(value = "xxx", httpMethod = "GET", notes = "xxx") 
    @ApiResponses(value = { 
      @ApiResponse(code = 400, message = "Invalid input:...", response = Auth400Response.class), 
      @ApiResponse(code = 200, message = "Ok", response = Auth200Response.class) 
      }) 
    @RequestMapping(value = "/oauth/authorize", produces = "application/json") 
    @ResponseBody 
    public ModelAndView authorize(@ApiIgnore Map<String, Object> model, 
      @ApiParam(value = "xxx", required = true, defaultValue = "xxx") @RequestParam String response_type, 
      @ApiParam(value = "xxx", required = true) @RequestParam String client_id, 
      @ApiParam(value = "xxx", required = true) @RequestParam String redirect_uri, 
      @ApiParam(value = "xxx", required = false, defaultValue = "/") @RequestParam String realm, 
      @ApiParam(value = "xxx", required = false) @RequestParam String state, 
      @ApiIgnore SessionStatus sessionStatus, @ApiIgnore Principal principal){ 
     Map<String, String> parameters = new HashMap<String, String>(); 
     parameters.put("response_type", response_type); 
     parameters.put("client_id", client_id); 
     parameters.put("realm", realm); 
     parameters.put("redirect_uri", redirect_uri); 
     parameters.put("state", state); 
     return this.authorizationEndpoint.authorize(model, parameters, sessionStatus, principal); 

這可能會幫助你。