Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query string is duplicated in generated snippets #286

Closed
jkubrynski opened this issue Jul 29, 2016 · 14 comments
Closed

Query string is duplicated in generated snippets #286

jkubrynski opened this issue Jul 29, 2016 · 14 comments

Comments

@jkubrynski
Copy link

After upgrading to 1.1.1.RELEASE query string is duplicated in generated snippets:

1.1.0.RELEASE exams?count=10&page=1

1.1.1.RELEASE exams?count=10&page=1?count=10&page=1

@wilkinsona
Copy link
Member

wilkinsona commented Jul 29, 2016

There are several tests around query strings that don't have any duplication so it's not immediately obvious what the cause may be. Can you please provide some more details:

  • Which snippets are affected?
  • Are you using MockMvc or RestAssured?
  • How are you creating the request?

A small sample that reproduces the problem would be ideal

@jkubrynski
Copy link
Author

Almost all snippets, including curl-request.adoc or http-request.adoc. I'm using MockMvc:

mockMvc.perform(
  get('/exams')
    .header("name", "value")
    .param('count', '10')
    .param('page', '1')
    .accept(MediaType.APPLICATION_JSON))
  .andDo(document(....)

@wilkinsona
Copy link
Member

wilkinsona commented Jul 29, 2016

Thanks, I can see where the problem is. It was introduced by the fix for gh-239.

@wilkinsona
Copy link
Member

@jkubrynski This should be fixed in the latest 1.1.2 snapshots available from https://repo.spring.io/libs-snapshot. Early testing of a snapshot would be much appreciated.

@jkubrynski
Copy link
Author

Thanks @wilkinsona !

I confirm - it works correctly now :)

@3gcodes
Copy link

3gcodes commented Aug 1, 2016

I'm running into this problem. Can someone tell me how to use the latest snapshot where this is fixed via gradle?

@jkubrynski
Copy link
Author

@gdboling

dependencies {
    compile 'org.springframework.restdocs:spring-restdocs-mockmvc:1.1.2.BUILD-SNAPSHOT'
} repositories {
    maven {
        url 'https://repo.spring.io/libs-snapshot'
    }
}

@3gcodes
Copy link

3gcodes commented Aug 1, 2016

Hm, I'm still getting duplicate request params:

[source,bash]
----
$ curl 'http://localhost:8080/api/notifications?type=A?type=A' -i -H 'X-Auth-Company: ABC' -H 'X-Auth-User: 1234' -H 'Content-Type: application/json;charset=UTF-8'
----

Here's my test

MockHttpServletRequestBuilder getRequest = get(URL);
getRequest.header("X-Auth-Company", "ABC");
getRequest.header("X-Auth-User", "1234");
getRequest.param("type", "A");

mockMvc.perform(getRequest.contentType(contentType))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.notifications", hasSize(1)))
        .andDo(document("index", preprocessRequest(), preprocessResponse(prettyPrint())));

@wilkinsona
Copy link
Member

@gdboling Can you share a complete example please, or at least let me know the value of URL in the code above?

@3gcodes
Copy link

3gcodes commented Aug 1, 2016

For now, here's URL:

URL = "/api/notifications";

And here's the controller method:

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity<Map<String, List>> fetch(HttpServletRequest request,
                                                   @RequestParam(value = "type", defaultValue = "E", required = false) String type) {
    String companyId = request.getHeader("X-Auth-Company");
    String authId = request.getHeader("X-Auth-User");
    List<Notification> notifications = notificationService.findAllByRecipient(companyId, authId, type);
    Map<String, List> result = new HashMap<>();
    result.put(Notification.class.getAnnotation(JsonPluralRoot.class).value(), notifications);
    return new ResponseEntity<>(result, HttpStatus.OK);
}

I'll see if I can provide a basic example via an empty project soon.

@3gcodes
Copy link

3gcodes commented Aug 1, 2016

Here's the simplest project. Just run gradle asciidoc which will run the tests and generate the documentation. You'll then see the following for the curl command:

$ curl 'http://localhost:8080/api/notifications?type=A?type=A' -i -H 'Content-Type: application/json;charset=UTF-8'

demo.zip

@embee1981
Copy link

@gdboling
Heya, I was about to comment that the fix was not working for me as well in my simple test case and the demo.zip project above.

However, once I added to the dependencies section

testCompile('org.springframework.restdocs:spring-restdocs-core:1.1.2.BUILD-SNAPSHOT')

all is well :-)

[source,bash]
----
$ curl 'http://localhost:8080/api/notifications?type=A' -i -H 'Content-Type: application/json;charset=UTF-8'
----

I had to do a similar thing when upgrading to 1.1.1, as for some reason the core jar wouldn't upgrade without specifically calling it out in the dependencies (used gradle 2.14 and 2.14.1)

@3gcodes
Copy link

3gcodes commented Aug 2, 2016

@embee1981 very good find! Works fine for me with the added dependency as well. I'm assuming that once this is released, the core dependency will no longer be needed?

@wilkinsona
Copy link
Member

Reopening as the fix has introduced a cycle between org.springframework.restdocs.operation and org.springframework.restdocs.cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants