你能相信用谷歌搜索这个结果会有两个惊人的结果吗?
我正在try 使用Spring rest Docs(spring-restdocs-mockmvc
)为我的服务生成API文档.
Running on a macbook pro with M2 processor.
I've read that this issue happens because /
is the root directory on a mac, and that is read only.
I don't know why that path is being used though.
I have the system property org.springframework.restdocs.outputDir
set, and when I check it the path is correct: /Users/me/workspace/my-service/target/generated-snippets
.
我的代码如下所示:
@SpringBootTest()
@ExtendWith(RestDocumentationExtension.class)
class ExampleControllerTest {
@Autowired
private WebApplicationContext context;
private MockMvc mvc;
@BeforeEach
public void setUp(RestDocumentationContextProvider restDocumentation) {
System.out.println("Output Directory: " + System.getProperty("org.springframework.restdocs.outputDir"));
this.mvc = MockMvcBuilders.webAppContextSetup(this.context)
.apply(MockMvcRestDocumentation.documentationConfiguration(restDocumentation))
.build();
}
@Test
public void index() throws Exception {
mvc.perform(MockMvcRequestBuilders.get("/").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()).andExpect(content().string(containsString("\"name\":\"Example Service\"")))
.andDo(MockMvcRestDocumentation.document("/",
responseFields(
fieldWithPath("name").description("The name of the service"),
fieldWithPath("list").description("A list of Integers"),
fieldWithPath("calledTimes").description(
"A count of the number of times this resource has been called"),
fieldWithPath("deployEnvironment").description(
"The environment the service is deployed to")
)
)
);
}
}
我完全不知道在这里该做什么.
When I pause the code with the debugger I can see that the RestDocumentationContextProvider
passed into the setup method has a value called outputDirectory
that is null. So it seems to me that it's not picking up the system property for some reason.
If I look in valuesStore.storedValues
there is one key/value pair with the key class org.springframework.restdocs.ManualRestDocumentation
and a value that contains (among other things) outputDirectory
set to target/generated-snippets
.