Specify language derived from Content-Type in body snippets

See gh-797
This commit is contained in:
Achim Grimm
2022-04-24 21:33:00 +02:00
committed by Andy Wilkinson
parent bdba92efe7
commit 9a44205253
7 changed files with 42 additions and 4 deletions

View File

@@ -20,6 +20,8 @@ import java.io.IOException;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.restdocs.AbstractSnippetTests;
import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateFormat;
@@ -58,6 +60,20 @@ public class RequestBodySnippetTests extends AbstractSnippetTests {
assertThat(this.generatedSnippets.snippet("request-body")).is(codeBlock(null, "nowrap").withContent(""));
}
@Test
public void requestWithMediaTypeJson() throws IOException {
requestBody().document(this.operationBuilder.request("http://localhost")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).build());
assertThat(this.generatedSnippets.snippet("request-body")).is(codeBlock("json", "nowrap").withContent(""));
}
@Test
public void requestWithMediaTypeXml() throws IOException {
requestBody().document(this.operationBuilder.request("http://localhost")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_ATOM_XML_VALUE).build());
assertThat(this.generatedSnippets.snippet("request-body")).is(codeBlock("xml", "nowrap").withContent(""));
}
@Test
public void subsectionOfRequestBody() throws IOException {
requestBody(beneathPath("a.b")).document(

View File

@@ -20,6 +20,8 @@ import java.io.IOException;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.restdocs.AbstractSnippetTests;
import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateFormat;
@@ -58,6 +60,20 @@ public class ResponseBodySnippetTests extends AbstractSnippetTests {
assertThat(this.generatedSnippets.snippet("response-body")).is(codeBlock(null, "nowrap").withContent(""));
}
@Test
public void responseWithMediaTypeJson() throws IOException {
new ResponseBodySnippet().document(this.operationBuilder.response()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).build());
assertThat(this.generatedSnippets.snippet("response-body")).is(codeBlock("json", "nowrap").withContent(""));
}
@Test
public void responseWithMediaTypeXml() throws IOException {
new ResponseBodySnippet().document(this.operationBuilder.response()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_ATOM_XML_VALUE).build());
assertThat(this.generatedSnippets.snippet("response-body")).is(codeBlock("xml", "nowrap").withContent(""));
}
@Test
public void subsectionOfResponseBody() throws IOException {
responseBody(beneathPath("a.b"))