diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java index a182d8df..edacab16 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java @@ -47,8 +47,6 @@ public class LinksSnippet extends TemplatedSnippet { private final Map descriptorsByRel = new LinkedHashMap<>(); - private final Set requiredRels = new HashSet<>(); - private final LinkExtractor linkExtractor; /** @@ -79,9 +77,6 @@ public class LinksSnippet extends TemplatedSnippet { Assert.hasText(descriptor.getRel()); Assert.hasText(descriptor.getDescription()); this.descriptorsByRel.put(descriptor.getRel(), descriptor); - if (!descriptor.isOptional()) { - this.requiredRels.add(descriptor.getRel()); - } } } @@ -105,7 +100,15 @@ public class LinksSnippet extends TemplatedSnippet { Set undocumentedRels = new HashSet(actualRels); undocumentedRels.removeAll(this.descriptorsByRel.keySet()); - Set missingRels = new HashSet(this.requiredRels); + Set requiredRels = new HashSet<>(); + for (Entry relAndDescriptor : this.descriptorsByRel + .entrySet()) { + if (!relAndDescriptor.getValue().isOptional()) { + requiredRels.add(relAndDescriptor.getKey()); + } + } + + Set missingRels = new HashSet(requiredRels); missingRels.removeAll(actualRels); if (!undocumentedRels.isEmpty() || !missingRels.isEmpty()) { @@ -133,4 +136,14 @@ public class LinksSnippet extends TemplatedSnippet { return model; } + /** + * Returns a {@code Map} of {@link LinkDescriptor LinkDescriptors} keyed by their + * {@link LinkDescriptor#getRel() rels}. + * + * @return the link descriptors + */ + protected final Map getDescriptorsByRel() { + return this.descriptorsByRel; + } + } \ No newline at end of file diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java index 33aa114c..80cd3708 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java @@ -146,4 +146,14 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet { */ protected abstract byte[] getContent(Operation operation) throws IOException; + /** + * Returns the list of {@link FieldDescriptor FieldDescriptors} that will be used to + * generate the documentation. + * + * @return the field descriptors + */ + protected final List getFieldDescriptors() { + return this.fieldDescriptors; + } + } \ No newline at end of file diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java index bafbdd37..804fb591 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java @@ -94,4 +94,15 @@ public abstract class AbstractParametersSnippet extends TemplatedSnippet { protected abstract void verificationFailed(Set undocumentedParameters, Set missingParameters); + /** + * Returns a {@code Map} of {@link ParameterDescriptor ParameterDescriptors} that will + * be used to generate the documentation key by their + * {@link ParameterDescriptor#getName()}. + * + * @return the map of path descriptors + */ + protected final Map getFieldDescriptors() { + return this.descriptorsByName; + } + } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java index 1e7dcc1d..3ec4afbb 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java @@ -81,4 +81,23 @@ public abstract class TemplatedSnippet implements Snippet { */ protected abstract Map createModel(Operation operation); + /** + * Returns the additional attributes that will be included in the model during + * template rendering. + * + * @return the additional attributes + */ + protected final Map getAttributes() { + return this.attributes; + } + + /** + * Returns the name of the snippet that will be created. + * + * @return the snippet name + */ + protected final String getSnippetName() { + return this.snippetName; + } + } \ No newline at end of file