为什么 Swagger 会在请求中包含不必要的变量 URL?

Why does Swagger include unnecessary variables into the request URL?

我目前正在训练使用 Swagger2 和 Spring MVC 记录我的 REST 接口“/news/rest/v1/articles”。它看起来像这样:

@RestController
@Api(
        description = "My News interface",
        produces = "application/json; charset=utf-8"
)
public class NewsController {
    @RequestMapping(
            method = RequestMethod.GET,
            value = "/news/rest/v1/articles",
            produces = {"application/json; charset=utf-8"}
    )
    @ApiOperation(
            value = "Returns news according to the given limit and language"
    )
    @ApiResponses(
            value = {
                    @ApiResponse(
                            code = 503,
                            message = "in case the news cannot be retrieved"
                    )
            }
    )
    public String getNews(
            @ApiParam(
                    value = "limitation of news elements",
                    required = false,
                    defaultValue = "-1" // -1 means no limitation
            )
            @RequestParam(defaultValue = "-1")
            Integer limit,

            @ApiParam(
                    value = "the language",
                    required = true,
                    allowableValues = "de,fr,it,en"
            )
            @RequestParam(defaultValue = "de")
            @Valid
            @Pattern(regexp = "de|fr|it|en")
            String language

            throws HTTPException {
        // implementation
    }
}

如果我部署我的应用程序并导航到 Swagger-UI,一切看起来都很好,除了我无法使用 "Try it out!"- 按钮这一事实。问题是 Swagger 使用的生成的 URL 有点奇怪……看起来像这样:

http://localhost:8080/myApp/api/news/rest/v1/articles{?limit,language}?limit=-1&language=de

我不太明白为什么请求中包含字符串“{?limit,language}”URL。如果我在没有 "{?limit,language}" 字符串的情况下手动调用非常 URL,它工作得很好...

如果有人能给我指点,我将不胜感激。

此致 沃尔特

我在这里遇到了同样的问题:

您需要设置

enableUrlTemplating(false)

Docket配置中