【问题标题】:Swagger includePatterns()招摇包含模式()
【发布时间】:2015-08-15 02:51:02
【问题描述】:

Swagger 配置:

@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.java,在includePatterns()方法中,当我给出模式时 作为/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/.*

【问题讨论】:

    标签: java swagger swagger-ui spring-restcontroller swagger-maven-plugin


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-15
      • 2022-09-28
      • 1970-01-01
      • 2019-04-01
      • 2021-09-28
      • 2021-05-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多