2

招摇配置:

@EnableSwagger
@Configuration
public class SwaggerConfig {

  private SpringSwaggerConfig springSwaggerConfig;

  @Autowired
  public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig) {
    this.springSwaggerConfig = springSwaggerConfig;
  }

  @Bean
  public SwaggerSpringMvcPlugin swaggerSpringMvcPlugin() {

    return new SwaggerSpringMvcPlugin(springSwaggerConfig)
            .swaggerGroup("sample-app")
            .includePatterns(
                    "/account/*"
            )
            .apiInfo(apiInfo())
            .build();
  }

  private ApiInfo apiInfo() {
    ApiInfo apiInfo = new ApiInfo(
            "sample-app",
            "sample-app doc",
            "",
            "support@sample-app",
            "",
            ""
    );
    return apiInfo;
  }

休息控制器

@RestController
@RequestMapping(value = "/account")
@Api(value = "Change Account details", description = "")
public class ChangeAccountController {

@ApiOperation(value = "Change address")
    @RequestMapping(value = "/addresschange", method = RequestMethod.POST)
    public String addressChange(HttpServletRequest httpRequest, HttpServletResponse httpResponse,
            @Valid @RequestBody User user) throws ServletException, IOException {
        // logic and return something!          
    }
}

参考:一些信息已经从这里参考:http://java.dzone.com/articles/how-configure-swagger-generate

问题/问题:

在方法中SwaggerConfig.javaincludePatterns()当我给出模式时,/account/*API 不会出现在 Swagger 输出页面中,而如果我包含/account/.*出现的模式。为什么?/account/*在这个用例中和有什么区别/account/.*

更新:

另一个用例

@RestController
@RequestMapping(value = "/score")


@ApiOperation(value = "All score", notes = "")
@RequestMapping(value = "", method = RequestMethod.GET)
public @ResponseBody ActionResult allScores(HttpServletRequest httpRequest,
            HttpServletResponse httpResponse) {

}

如果我将模式添加为/score/*,则 API 将出现在 Swagger 中。我不需要把模式作为/score/.*

4

1 回答 1

3

不同之处在于,如果您编写 /account/*,则表示采用任何以“/account”开头的字符串,然后至少出现 0 次字符 '/',第二个模式匹配以“/account/”开头的字符串,后跟任何字符至少出现 0 次。

有关更多详细信息,请参见例如http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html

于 2015-06-01T15:15:31.987 回答