spring-restdocs

Spring rest docs: Error when creating custom TemplateSnippet

佐手、 提交于 2021-01-29 05:26:01
问题 I want to create a custom HttRequestSnippet with spring rest docs. Because I want the url to be shown as /accounts/{id} and not /accounts/1 , I have to create a custom snippet class. I tried two approaches: I tried to get this going in general. Therefore I pass the uri as a parameter to the class. public class CustomHttpRequestSnippet extends TemplatedSnippet { public CustomHttpRequestSnippet(String uri) { super("custom", Collections.singletonMap("path",uri)); } @Override protected Map<String

Spring REST Docs: how to replace parameters

眉间皱痕 提交于 2021-01-28 04:11:50
问题 In my unit tests we find this.mockMvc .perform(post("/authenticate") .contentType(MediaType.APPLICATION_FORM_URLENCODED) .param("username", "user@example.com") .param("password", "superSecretPassword")) .andExpect(status().isOk()) .andDo(document("preprocessed-request", preprocessRequest(replacePattern(Pattern.compile("superSecretPassword"), "XXX")))); cf. Spring REST Docs documentation This generates build/generated-snippets/preprocessed-request/http-request.adoc with the content [source

java.lang.AssertionError: Status expected:<200> but was:<404> in Junit test

心已入冬 提交于 2020-01-02 11:05:17
问题 I want to create JUnit test for Rest api and generate api doc. I want to test this code: Rest controller @RestController @RequestMapping("/transactions") public class PaymentTransactionsController { @Autowired private PaymentTransactionRepository transactionRepository; @GetMapping("{id}") public ResponseEntity<?> get(@PathVariable String id) { return transactionRepository .findById(Integer.parseInt(id)) .map(mapper::toDTO) .map(ResponseEntity::ok) .orElseGet(() -> notFound().build()); } }

How do I make sure my documentation is up to date with Spring Rest Docs?

こ雲淡風輕ζ 提交于 2019-12-25 15:50:38
问题 I really like the concept of using failed tests to ensure the documentation is up to date. But I don't know how to make it work for nested json. The way Spring REST Docs handles hierarchical payload seems to defeat the purpose: When documenting fields, the test will fail if an undocumented field is found in the payload. Similarly, the test will also fail if a documented field is not found in the payload and the field has not been marked as optional. For payloads with a hierarchical structure,

How to document response fields for an object as Map(HashMap)

穿精又带淫゛_ 提交于 2019-12-25 07:00:00
问题 I am doing documentation for a REST service returning an object like this: Map<String, HashMap<Long, String>> and i find no way to describe response fields for such object. Let's have a look at my code. The service: @RequestMapping(value = "/data", method = RequestMethod.GET) public Map<String, HashMap<Long, String>> getData() { Map<String, HashMap<Long, String>> list = dao.getData(); return list; } My unit-test-based documentation: @Test public void testData() throws Exception { TestUtils

How to ensure load time weaving takes place for Eclipselink when using SpringBootTest with other tests running beforethe Spring one

[亡魂溺海] 提交于 2019-12-24 08:36:02
问题 I'm using Spring Rest Docs to generate documentation for my REST services. This involves running unit(strictly integration) tests that run against a live Spring Boot Container that is kicked off by the test. The test class looks like this: @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = MySpringConfiguration.class) @WebAppConfiguration public class ApiDocumentation { private MockMvc mockMvc; @Rule public final JUnitRestDocumentation restDocumentation = new

Using tabs in AsciiDoc (Spring Rest Docs)

匆匆过客 提交于 2019-12-23 10:54:30
问题 I'm using Spring Rest Docs to generate documentation. I would like to do something like Bootstrap's Togglable tabs. Spring documentation uses togglable tabs, but I don't know how to do it. Here is an example (MockMvc / REST Assured): http://docs.spring.io/spring-restdocs/docs/1.1.0.RELEASE/reference/html5/#documenting-your-api Thanks for helping. 回答1: There's no built-in support for tabs in Asciidoctor but it's very extensible which allows you to add this sort of thing quite easily. The tabs

JsonParseException: Invalid UTF-8 middle byte 0x20 with MockMVC and Maven

徘徊边缘 提交于 2019-12-12 06:40:10
问题 EDIT : If I remove the spring-restdoc code, the test passes with maven. I'm trying to write an integration test with MockMVC in a Spring Boot web app. I have only one test at the moment (steps and code below) that pass if I run it in the IDE but fails with the following stacktrace if executed by Maven: org.springframework.restdocs.payload.PayloadHandlingException: com.fasterxml.jackson.core.JsonParseException: Invalid UTF-8 middle byte 0x20 at [Source: [B@3793896e; line: 30, column: 23] at

spring-restdocs is not recognizing apply()

怎甘沉沦 提交于 2019-12-12 03:24:51
问题 I am trying to generate a Rest API documentation based on spring-restdocs In following code I am getting a compile time error at apply() The method apply(RestDocumentationMockMvcConfigurer) is undefined for the type DefaultMockMvcBuilder @ContextConfiguration(locations = { "classpath:/testApplicationRestService.xml" }) @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration public class CustomerControllerTest { @Rule public final RestDocumentation restDocumentation = new