diff --git a/rest-notes-spring-data-rest/.settings/org.eclipse.jdt.core.prefs b/rest-notes-spring-data-rest/.settings/org.eclipse.jdt.core.prefs index a92f7ab8..03628c92 100644 --- a/rest-notes-spring-data-rest/.settings/org.eclipse.jdt.core.prefs +++ b/rest-notes-spring-data-rest/.settings/org.eclipse.jdt.core.prefs @@ -36,8 +36,8 @@ org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=1 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 diff --git a/rest-notes-spring-hateoas/.settings/org.eclipse.jdt.core.prefs b/rest-notes-spring-hateoas/.settings/org.eclipse.jdt.core.prefs index a92f7ab8..03628c92 100644 --- a/rest-notes-spring-hateoas/.settings/org.eclipse.jdt.core.prefs +++ b/rest-notes-spring-hateoas/.settings/org.eclipse.jdt.core.prefs @@ -36,8 +36,8 @@ org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=1 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 diff --git a/spring-restdocs-core/.settings/org.eclipse.jdt.core.prefs b/spring-restdocs-core/.settings/org.eclipse.jdt.core.prefs index 521f4160..83412a90 100644 --- a/spring-restdocs-core/.settings/org.eclipse.jdt.core.prefs +++ b/spring-restdocs-core/.settings/org.eclipse.jdt.core.prefs @@ -36,8 +36,8 @@ org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16 org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 +org.eclipse.jdt.core.formatter.blank_lines_before_field=1 +org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=1 org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 org.eclipse.jdt.core.formatter.blank_lines_before_method=1 diff --git a/spring-restdocs-core/.settings/org.eclipse.jdt.ui.prefs b/spring-restdocs-core/.settings/org.eclipse.jdt.ui.prefs index 0fc7e2d2..0abc6562 100644 --- a/spring-restdocs-core/.settings/org.eclipse.jdt.ui.prefs +++ b/spring-restdocs-core/.settings/org.eclipse.jdt.ui.prefs @@ -58,5 +58,64 @@ cleanup.use_type_arguments=false cleanup_profile=_Spring Rest Docs Cleanup Conventions cleanup_settings_version=2 eclipse.preferences.version=1 +editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true formatter_profile=_Spring Rest Docs Java Conventions formatter_settings_version=12 +sp_cleanup.add_default_serial_version_id=true +sp_cleanup.add_generated_serial_version_id=false +sp_cleanup.add_missing_annotations=true +sp_cleanup.add_missing_deprecated_annotations=true +sp_cleanup.add_missing_methods=false +sp_cleanup.add_missing_nls_tags=false +sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=true +sp_cleanup.add_serial_version_id=false +sp_cleanup.always_use_blocks=true +sp_cleanup.always_use_parentheses_in_expressions=false +sp_cleanup.always_use_this_for_non_static_field_access=false +sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false +sp_cleanup.convert_to_enhanced_for_loop=false +sp_cleanup.correct_indentation=false +sp_cleanup.format_source_code=true +sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false +sp_cleanup.make_local_variable_final=true +sp_cleanup.make_parameters_final=false +sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false +sp_cleanup.make_variable_declarations_final=false +sp_cleanup.never_use_blocks=false +sp_cleanup.never_use_parentheses_in_expressions=true +sp_cleanup.on_save_use_additional_actions=false +sp_cleanup.organize_imports=true +sp_cleanup.qualify_static_field_accesses_with_declaring_class=false +sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +sp_cleanup.qualify_static_member_accesses_with_declaring_class=false +sp_cleanup.qualify_static_method_accesses_with_declaring_class=false +sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_type_arguments=true +sp_cleanup.remove_trailing_whitespaces=false +sp_cleanup.remove_trailing_whitespaces_all=true +sp_cleanup.remove_trailing_whitespaces_ignore_empty=false +sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_nls_tags=false +sp_cleanup.remove_unused_imports=false +sp_cleanup.remove_unused_local_variables=false +sp_cleanup.remove_unused_private_fields=true +sp_cleanup.remove_unused_private_members=false +sp_cleanup.remove_unused_private_methods=true +sp_cleanup.remove_unused_private_types=true +sp_cleanup.sort_members=false +sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false +sp_cleanup.use_blocks=false +sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=true +sp_cleanup.use_parentheses_in_expressions=false +sp_cleanup.use_this_for_non_static_field_access=false +sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true +sp_cleanup.use_this_for_non_static_method_access=false +sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true +sp_cleanup.use_type_arguments=false diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationProperties.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationProperties.java index 8ecc84b5..fe644def 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationProperties.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationProperties.java @@ -51,7 +51,8 @@ class DocumentationProperties { } File getOutputDir() { - String outputDir = this.properties.getProperty("org.springframework.restdocs.outputDir"); + String outputDir = this.properties + .getProperty("org.springframework.restdocs.outputDir"); if (StringUtils.hasText(outputDir)) { return new File(outputDir).getAbsoluteFile(); } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationWriter.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationWriter.java index a3bdbc8c..178bb37b 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationWriter.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/DocumentationWriter.java @@ -38,7 +38,8 @@ public class DocumentationWriter extends PrintWriter { }); } - public void codeBlock(String language, DocumentationAction... actions) throws Exception { + public void codeBlock(String language, DocumentationAction... actions) + throws Exception { println(); if (language != null) { println("[source," + language + "]"); @@ -52,6 +53,7 @@ public class DocumentationWriter extends PrintWriter { } public interface DocumentationAction { + void perform() throws Exception; } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentation.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentation.java index 2aa9865a..160119ca 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentation.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentation.java @@ -20,22 +20,23 @@ import java.util.Map; public class RestDocumentation { - public static RestDocumentationResultHandler document(String outputDir) throws Exception { - return new RestDocumentationResultHandler(outputDir); - } + public static RestDocumentationResultHandler document(String outputDir) + throws Exception { + return new RestDocumentationResultHandler(outputDir); + } - public static LinkDescriptor linkWithRel(String rel) { - return new LinkDescriptor(rel); - } + public static LinkDescriptor linkWithRel(String rel) { + return new LinkDescriptor(rel); + } - public static LinkExtractor halLinks() { - return new LinkExtractor() { + public static LinkExtractor halLinks() { + return new LinkExtractor() { - @SuppressWarnings("unchecked") - @Override - public Map extractLinks(Map responseJson) { - return (Map) responseJson.get("_links"); - } - }; - } + @SuppressWarnings("unchecked") + @Override + public Map extractLinks(Map responseJson) { + return (Map) responseJson.get("_links"); + } + }; + } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandler.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandler.java index 1e00cf4d..e1b96b84 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandler.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandler.java @@ -28,25 +28,28 @@ import org.springframework.test.web.servlet.ResultHandler; public class RestDocumentationResultHandler implements ResultHandler { - private final String outputDir; - private ResultHandler linkDocumentingResultHandler; + private final String outputDir; - public RestDocumentationResultHandler(String outputDir) { - this.outputDir = outputDir; - } + private ResultHandler linkDocumentingResultHandler; - @Override - public void handle(MvcResult result) throws Exception { - documentCurlRequest(outputDir).includeResponseHeaders().handle(result); - documentCurlResponse(outputDir).includeResponseHeaders().handle(result); - documentCurlRequestAndResponse(outputDir).includeResponseHeaders().handle(result); - if(linkDocumentingResultHandler != null) { - linkDocumentingResultHandler.handle(result); - } - } + public RestDocumentationResultHandler(String outputDir) { + this.outputDir = outputDir; + } - public RestDocumentationResultHandler withLinks(LinkExtractor linkExtractor, LinkDescriptor... descriptors) { - linkDocumentingResultHandler = new LinkDocumentingResultHandler(outputDir, linkExtractor, Arrays.asList(descriptors)); - return this; - } + @Override + public void handle(MvcResult result) throws Exception { + documentCurlRequest(outputDir).includeResponseHeaders().handle(result); + documentCurlResponse(outputDir).includeResponseHeaders().handle(result); + documentCurlRequestAndResponse(outputDir).includeResponseHeaders().handle(result); + if (linkDocumentingResultHandler != null) { + linkDocumentingResultHandler.handle(result); + } + } + + public RestDocumentationResultHandler withLinks(LinkExtractor linkExtractor, + LinkDescriptor... descriptors) { + linkDocumentingResultHandler = new LinkDocumentingResultHandler(outputDir, + linkExtractor, Arrays.asList(descriptors)); + return this; + } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandlers.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandlers.java index cd1d7c7c..04afb317 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandlers.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/core/RestDocumentationResultHandlers.java @@ -16,8 +16,8 @@ package org.springframework.restdocs.core; -import static org.springframework.restdocs.core.IterableEnumeration.iterable; import static org.junit.Assert.fail; +import static org.springframework.restdocs.core.IterableEnumeration.iterable; import java.io.File; import java.io.FileNotFoundException; @@ -47,6 +47,7 @@ public abstract class RestDocumentationResultHandlers { public static CurlResultHandler documentCurlRequest(String outputDir) { return new CurlResultHandler(outputDir, "request") { + @Override public void handle(MvcResult result, DocumentationWriter writer) throws Exception { @@ -58,24 +59,26 @@ public abstract class RestDocumentationResultHandlers { public static CurlResultHandler documentCurlResponse(String outputDir) { return new CurlResultHandler(outputDir, "response") { + @Override public void handle(MvcResult result, DocumentationWriter writer) throws Exception { - writer.codeBlock("http", new CurlResponseDocumentationAction(writer, result, - getCurlConfiguration())); + writer.codeBlock("http", new CurlResponseDocumentationAction(writer, + result, getCurlConfiguration())); } }; } public static CurlResultHandler documentCurlRequestAndResponse(String outputDir) { return new CurlResultHandler(outputDir, "request-response") { + @Override public void handle(MvcResult result, DocumentationWriter writer) throws Exception { writer.shellCommand(new CurlRequestDocumentationAction(writer, result, getCurlConfiguration())); - writer.codeBlock("http", new CurlResponseDocumentationAction(writer, result, - getCurlConfiguration())); + writer.codeBlock("http", new CurlResponseDocumentationAction(writer, + result, getCurlConfiguration())); } }; } @@ -174,16 +177,16 @@ public abstract class RestDocumentationResultHandlers { } public static abstract class RestDocumentationResultHandler implements ResultHandler { - + private String outputDir; - + private String fileName; public RestDocumentationResultHandler(String outputDir, String fileName) { this.outputDir = outputDir; this.fileName = fileName; } - + abstract void handle(MvcResult result, DocumentationWriter writer) throws Exception; @@ -198,19 +201,18 @@ public abstract class RestDocumentationResultHandlers { } } - protected PrintStream createPrintStream() - throws FileNotFoundException { - + protected PrintStream createPrintStream() throws FileNotFoundException { + File outputFile = new File(this.outputDir, this.fileName + ".asciidoc"); if (!outputFile.isAbsolute()) { outputFile = makeAbsolute(outputFile); } - + if (outputFile != null) { outputFile.getParentFile().mkdirs(); return new PrintStream(new FileOutputStream(outputFile)); } - + return System.out; } @@ -249,10 +251,11 @@ public abstract class RestDocumentationResultHandlers { private final LinkExtractor extractor; - public LinkDocumentingResultHandler(String outputDir, LinkExtractor linkExtractor, List descriptors) { + public LinkDocumentingResultHandler(String outputDir, + LinkExtractor linkExtractor, List descriptors) { super(outputDir, "links"); this.extractor = linkExtractor; - for (LinkDescriptor descriptor: descriptors) { + for (LinkDescriptor descriptor : descriptors) { Assert.hasText(descriptor.getRel()); Assert.hasText(descriptor.getDescription()); this.descriptorsByRel.put(descriptor.getRel(), descriptor); @@ -262,7 +265,8 @@ public abstract class RestDocumentationResultHandlers { @SuppressWarnings("unchecked") @Override void handle(MvcResult result, DocumentationWriter writer) throws Exception { - Map json = this.objectMapper.readValue(result.getResponse().getContentAsString(), Map.class); + Map json = this.objectMapper.readValue(result.getResponse() + .getContentAsString(), Map.class); Map links = this.extractor.extractLinks(json); Set actualRels = links.keySet(); @@ -277,10 +281,12 @@ public abstract class RestDocumentationResultHandlers { if (!undocumentedRels.isEmpty() || !missingRels.isEmpty()) { String message = ""; if (!undocumentedRels.isEmpty()) { - message += "Links with the following relations were not documented: " + undocumentedRels; + message += "Links with the following relations were not documented: " + + undocumentedRels; } if (!missingRels.isEmpty()) { - message += "Links with the following relations were not found in the response: " + missingRels; + message += "Links with the following relations were not found in the response: " + + missingRels; } fail(message); }