Polish "Specify language derived from Content-Type in body snippets"
See gh-797
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.restdocs.snippet.TemplatedSnippet;
|
||||
* document a RESTful resource's request or response body.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
* @author Achim Grimm
|
||||
*/
|
||||
public abstract class AbstractBodySnippet extends TemplatedSnippet {
|
||||
|
||||
@@ -73,11 +74,7 @@ public abstract class AbstractBodySnippet extends TemplatedSnippet {
|
||||
protected Map<String, Object> createModel(Operation operation) {
|
||||
try {
|
||||
MediaType contentType = getContentType(operation);
|
||||
String language = null;
|
||||
if (contentType != null) {
|
||||
language = (contentType.getSubtypeSuffix() != null) ? contentType.getSubtypeSuffix()
|
||||
: contentType.getSubtype();
|
||||
}
|
||||
String language = determineLanguage(contentType);
|
||||
byte[] content = getContent(operation);
|
||||
if (this.subsectionExtractor != null) {
|
||||
content = this.subsectionExtractor.extractSubsection(content, contentType);
|
||||
@@ -94,6 +91,13 @@ public abstract class AbstractBodySnippet extends TemplatedSnippet {
|
||||
}
|
||||
}
|
||||
|
||||
private String determineLanguage(MediaType contentType) {
|
||||
if (contentType == null) {
|
||||
return null;
|
||||
}
|
||||
return (contentType.getSubtypeSuffix() != null) ? contentType.getSubtypeSuffix() : contentType.getSubtype();
|
||||
}
|
||||
|
||||
private Charset extractCharset(MediaType contentType) {
|
||||
if (contentType == null) {
|
||||
return null;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
[source,options="nowrap"]
|
||||
[source{{#language}},{{language}}{{/language}},options="nowrap"]
|
||||
----
|
||||
{{body}}
|
||||
----
|
||||
@@ -1,3 +1,3 @@
|
||||
```
|
||||
```{{#language}}{{language}}{{/language}}
|
||||
{{body}}
|
||||
```
|
||||
Reference in New Issue
Block a user