Skip to content

Valueless query parameters are duplicated in request snippets #647

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

Closed
bruno2git opened this issue Oct 4, 2019 · 1 comment
Closed

Valueless query parameters are duplicated in request snippets #647

bruno2git opened this issue Oct 4, 2019 · 1 comment
Labels
Milestone

Comments

@bruno2git
Copy link

I'm using Spring REST Docs (2.0.3.RELEASE) and MockMvc (spring-test 5.0.5.RELEASE).

When the documented request contains a query parameter that has no assigned value (empty string) the snippets produced by CliDocumentation.curlRequest() and HttpDocumentation.httpRequest() show the parameter duplicated.

My setup:

@Before
public void setUp() {
    this.documentationHandler = document("{class-name}/{method-name}",
            preprocessRequest(prettyPrint()),
            preprocessResponse(prettyPrint()));
    this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
            .defaultRequest(get("/")
                    .contextPath(contextPath))
            .apply(documentationConfiguration(this.restDocumentation).uris()
                    .withScheme(scheme)
                    .withHost(host)
                    .withPort(port))
            .alwaysDo(this.documentationHandler)
            .build();
}

My test:

@Test
public void getBookDescriptionNullCodeTest() throws Exception {
    this.mockMvc.perform(
            get("/my.app/{catalogue}/$lookup", "books").param("code", "")
                    .contentType(MediaType.APPLICATION_JSON_UTF8))
            .andExpect(status().isUnprocessableEntity())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
            ...

The curl snippet (note the ?code=&code=):

[source,bash]
----
$ curl 'http://localhost:8080/my.app/books/$lookup?code=&code=' -i -X GET \
    -H 'Content-Type: application/json;charset=UTF-8'
----

This appears to be similar to #286, however this only happens for valueless parameters and that bug was fixed in version 1.1.2.RELEASE.

@wilkinsona
Copy link
Member

Thank you for opening this, @bruno2git. Just to join some dots, here is the question on Stack Overflow that led to this issue being opened.

@wilkinsona wilkinsona added type: bug A bug and removed status: waiting-for-triage Untriaged issue labels Oct 4, 2019
@wilkinsona wilkinsona added this to the 2.0.5.RELEASE milestone Oct 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants