spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 736 forks source link

Rest-Assured - Query string is duplicated in generated snippets #298

Closed Zasch closed 8 years ago

Zasch commented 8 years ago

There seems to be a problem with curl- and http-snippet generation. The request params are doubled:

$ curl 'http://loclhost/tags/list?page=0&per_page=3?page=0&per_page=3' -i -H 'Accept: application/json'

GET /tags/list?page=0&per_page=3&page=0&per_page=3 HTTP/1.1 Accept: application/json Host: localhost

I use Rest-Assured:

given(this.spec)
                .accept("application/json")
                .filter(document("tag-list",
                preprocessRequest(prettyPrint(), modifyUris().scheme("http").host("loclhost").removePort()),
                preprocessResponse(prettyPrint()),
                requestParameters(
                        parameterWithName("page").description("Number of the page to retrieve").optional(),
                        parameterWithName("per_page").description("Entries per page").optional()
                ),
                responseFields(
                        fieldWithPath("content").description("Array of elements"),
                        fieldWithPath("totalPages").description("Total number of pages"),
                        fieldWithPath("totalElements").description("Total number of elements"),
                        fieldWithPath("first").description("Is this the first page?"),
                        fieldWithPath("last").description("Is this the last page?"),
                        fieldWithPath("numberOfElements").description("Number of elements on this page"),
                        fieldWithPath("sort").description("Sort order").ignored(),
                        fieldWithPath("size").description("Number of elements on each page"),
                        fieldWithPath("number").description("Page number")
                )))
                .when()
                .port(this.port)
                .get("/tags/list?page=0&per_page=3")
                .then()
                .log().ifValidationFails()
                .time(lessThan(2000L))
                .assertThat().statusCode(200)
                .and()
                .assertThat().contentType("application/json")

Maybe, this is related to #286 ?

wilkinsona commented 8 years ago

I suspect it's a duplicate. What version are you using?

Zasch commented 8 years ago

I'm using 1.1.2.RELEASE

testCompile('org.springframework.restdocs:spring-restdocs-restassured:1.1.2.RELEASE')

wilkinsona commented 8 years ago

Thanks. Are you using Spring Boot? If so, its dependency management will be forcing the core module (which is where the fix is) to be 1.1.1.RELEASE. If not, please provide a complete example that reproduces the problem.

Zasch commented 8 years ago

Transitive dependency was in fact spring-restdocs-core:1.1.1.RELEASE.

So this fixes it:

testCompile("org.springframework.restdocs:spring-restdocs-restassured:1.1.2.RELEASE") {
    exclude group: "org.springframework.restdocs", module: "spring-restdocs-core"
}
testCompile("org.springframework.restdocs:spring-restdocs-core:1.1.2.RELEASE")

Thank you.

wilkinsona commented 8 years ago

Great. Btw, there's no need for the exclude there. And if you're using Spring Boot you could just override spring-restdocs.version instead.