Duplicate Request Parameters being recorded in the snippet [duplicate]

a 夏天 提交于 2019-12-12 02:25:42

问题


As the title suggests I have a Controller endpoint I'm trying to document. The endpoint can take 2 parameters both are optional. When it goes to generate the code the parameter is duplicated.

Controller

@RequestMapping("/bitbucket/project")
    public Project findProject(@RequestParam(value = "key", required = false) String key,
            @RequestParam(value = "name", required = false) String name)
    {
            if (!StringUtils.isEmpty(key))
            {
                    try
                    {
                            Project project = projectService.findProjectByKey(key);
                            if (project == null)
                            {
                                    throw new NotFoundException("Project not found");
                            }
                            else
                            {
                                    return project;
                            }
                    }
                    catch (IOException e)
                    {
                            LOG.error(e.getMessage(), e);
                            throw new ServerException(e.getMessage());
                    }
            }
            else if (!StringUtils.isEmpty(name))
            {
                    try
                    {
                            Project project = projectService.findProjectByName(name);
                            if (project == null)
                            {
                                    throw new NotFoundException("Project not found");
                            }
                            else
                            {
                                    return project;
                            }
                    }
                    catch (IOException e)
                    {
                            LOG.error(e.getMessage(), e);
                            throw new ServerException(e.getMessage());
                    }
            }
            else
            {
                    throw new BadRequestException("Project not found");
            }
    }

Documentation

@Rule
    public JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(
            "target/generated-snippets");

    private RestDocumentationResultHandler document;

    @Autowired
    private WebApplicationContext context;

    private MockMvc mockMvc;

    @Before
    public void setUp()
    {
            this.document = document("{method-name}", preprocessRequest(prettyPrint()),
                    preprocessResponse(prettyPrint()));

            this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
                    .apply(documentationConfiguration(this.restDocumentation))
                    .alwaysDo(this.document).build();
    }

    @Test
    public void findProjectKey() throws Exception
    {
            String projectKey = "KEY";
            when(projectService.findProjectByKey(anyString()))
                    .thenReturn(createProject(projectKey, null, false));

            getMockMvc().perform(get("/bitbucket/project").param("key", projectKey))
                    .andExpect(status().isOk());
    }

And here is the generated snippet for the http-request.adoc

[source,http,options="nowrap"]
----
GET /bitbucket/project?key=KEY&key=KEY HTTP/1.1
Host: localhost:8080

----

Running Spring Boot 1.4.0 and Rest Docs 1.1.1


回答1:


This was due to a bug in 1.1.1. Upgrading to 1.1.2 will fix the problem.



来源:https://stackoverflow.com/questions/39537573/duplicate-request-parameters-being-recorded-in-the-snippet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!