0
タイトルには、私が記録しようとしているコントローラエンドポイントがあります。エンドポイントは2つのパラメータを取ることができ、両方ともオプションです。コードを生成すると、パラメータは複製されます。複製リクエストパラメータがスニペットに記録されています
コントローラ
@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");
}
}
ドキュメント
@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());
}
そしてここでは、http-request.adoc春ブーツ1.4.0を実行している
[source,http,options="nowrap"]
----
GET /bitbucket/project?key=KEY&key=KEY HTTP/1.1
Host: localhost:8080
----
のために生成スニペットです残りの部分 ドキュメント1.1.1
まだ1.1.2にアップデートした後の問題 – ndrone
spring-restdocs-coreの1.1.2を使用していますか? Springブートを使用しているときは、pom.xmlまたはbuild.gradleで 'spring-restdocs.version'を無効にする必要があります。 –
私はそれを試して、あなたに戻ってきます。私はpom.xmlの依存レベルでバージョンを変更しただけです。 – ndrone