Commit Graph

18 Commits

Author SHA1 Message Date
Andy Wilkinson
2b2b6fcd25 Isolate and reduce Spring Test dependencies
This commit splits Spring REST Docs into two projects –
spring-restdocs-core and spring-restdocs-mockmvc.

spring-restdocs-core contains the vast majority of the code but does not
depend on a specific test framework other than JUnit. The use of a
Spring Test TestExecutionListener has been replaced with a JUnit test
rule. The rule is declared once per test class and configured with
the output directory to which the generated snippets should be written.
This simplifies the implementation as thread local storage is no longer
required to transfer information about the test that’s running into
Spring REST Docs. Instead, this transfer is now handled by the new test
rule. It has also simplified the configuration as it’s no longer
necessary for users to provide a system property that configures the
output directory.

spring-restdocs-mockmvc contains code that’s specific to using Spring
REST Docs with Spring MVC Test’s MockMvc. This is currently the only
testing framework that’s supported, but it paves the way for adding
support for additional frameworks. REST Assured is one that users seem
particularly interested in (see gh-80 and gh-102).

Closes gh-107
2015-09-03 14:19:32 +01:00
Andy Wilkinson
bc5a9c3714 Update the samples to use Spring Boot 1.2.5 2015-08-19 18:01:25 +01:00
Andy Wilkinson
32bb724a3d Update the samples to align with recent API changes 2015-08-19 17:25:56 +01:00
Andy Wilkinson
0c8a71370b Rework the API to improve readability and extensibility
This commit updates the API to improve its extensibility and
readability.

SnippetWritingResultHandler has been replaced with a  more general
purpose Snippet interface. Snippets are now provided to the main
document method using varargs rather than the various with… methods
that were previously used. As a result a custom Snippet implementation
can now be used in exactly the same way as any of the built-in
snippets:

this.mockMvc.perform(get("/"))
        .andExpect(status().isOk())
        .andDo(document("index-example",
                links(
                        linkWithRel("notes").description("…"),
                        linkWithRel("tags").description("…")),
                responseFields(
                        fieldWithPath("_links").description("…")),
                yourCustomSnippet()));

Control of the snippets that are generated by default is now available
via RestDocumentationConfigurer:

this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
        .apply(documentationConfiguration().snippets()
               .withDefaults(curlRequest(), yourCustomSnippet()))
        .build();

See gh-73
2015-08-10 12:06:32 +01:00
Andy Wilkinson
8e2fc7f45d Provide support for documenting path parameters
This commit adds support for documenting a request's path parameters.
For example:

mockMvc.perform(
		get("/locations/{latitude}/{longitude}", 51.5072, 0.1275))
			.andExpect(status().isOk())
			.andDo(document("locations").withPathParameters(
					parameterWithName("latitude")
							.description("The location's latitude"),
					parameterWithName("longitude")
							.description("The location's longitude")
			));

Closes gh-86
2015-07-29 14:50:49 +01:00
Andy Wilkinson
cdcddcf91b Update the samples to use Spring Boot 1.2.4.RELEASE 2015-06-24 14:36:47 +01:00
Andy Wilkinson
b6c64dfd26 Update the samples to build against correct version of main project
This should have been done as part of 0e5151e91.
2015-06-23 14:05:07 +01:00
Andy Wilkinson
8307fb5428 Add reference documentation and create docs zip
Add reference documentation for the project and add a docs artifact
that contains both the reference documentation and the javadoc.

See gh-37
2015-06-16 17:14:31 +01:00
Andy Wilkinson
0c0d3b89bd Default snippet encoding to UTF-8 and make it configurable
Previously, snippets were written to disk using the JVM’s default
encoding. While this could be controlled by the file.encoding system
property it was not ideal as, if the proper was not always set, it could
lead to platform-dependent output being generated. Furthermore,
Asciidoctor uses UTF-8 encoding by default so there was a risk of the
snippets being generated in a different encoding to the encoding
expected by Asciidoctor.

This commit updates the configuration so that, by default, snippets are
encoded as UTF-8. The RestDocumentationConfigurer API has been enhanced
to allow this default to be configured as part of building the
MockMvc instance. This enhancement as brought with it a more fluent
configuration API that separates configuration that is related to URIs
from configuration that is related to snippets.

Closes gh-67
2015-05-13 11:18:56 +01:00
Andy Wilkinson
90bbb5ab9e Update samples to make them compatible with Java 7
The main project supports Java 7 or later, but, prior to this commit,
the Spring HATEOAS sample required Java 8. This commit updates updates
the Spring HATEOAS sample to make it compatible with Java 7 and
updates the build configuration of both samples to specify Java 7.

Closes gh-51
2015-05-05 12:09:45 +01:00
Andy Wilkinson
8166c5e3e7 Add a task that verifies the includes in a sample’s .adoc files
Enhance buildSamples such that, once a sample has been built, it looks
at the generated HTML files and checks that they do not contain any
output that's indicative of a malformed include in a source .adoc
file.

This additional verification found another malformed include which
this commit corrects.
2015-04-21 12:32:31 +01:00
Preben Asmussen
18c7799b8f Fix the artifact id in pom.xml of rest-notes-spring-data-rest
Closes gh-53
2015-04-20 09:50:36 +01:00
Andy Wilkinson
bcda6fe459 Update the main project and Gradle samples to use Gradle 2.3 2015-04-16 12:34:28 +01:00
Andy Wilkinson
f93981fce2 Align with the Asciidoctor team's preferred file extension, .adoc
Closes gh-45
2015-04-16 12:31:29 +01:00
Andy Wilkinson
e00734d693 Add support for generating an HTTP request documentation snippet
Closes gh-13
2015-04-16 12:03:21 +01:00
Andy Wilkinson
2b44452de1 Improve support for documenting fields in req and resp payloads
This commit improves the support for documenting the fields found
in request and response payloads. The improvements include:

 - Using the term "payload" rather than "state" as the latter is
   somewhat HAL-specific
 - Code simplification, including the removal of the Path abstraction
 - Automatically determining the type of a field based on the payload
   that's being tested
 - Updating the samples to use the new API

In addition to these improvements, support for documenting field
constraints has been removed as more thought is required. The
FieldDescriptor abstraction is used to describe both request and
response fields, however it's not clear that contraints apply to both
and they certainly don't apply in the same way. For the time being at
least, users who want to document a field's constraints can do so as
part of its description.

Closes gh-24
2015-03-24 16:31:52 +00:00
Andy Wilkinson
1eeb605108 Support using alwaysDo to automatically document every MockMvc call
The MVC test framework provides an alwaysDo method which allows the
configuration of a result handler to be that will be invoked for every
call to perform. Previously, this method could not be used for
producing documentation snippets as the snippets would overwrite each
other.

This commit adds support for writing snippets to a parameterized
output directory. Two parameters are supported: method name and step.
Method name is the name of the currently executing test method. Step
is a count of the number of calls to MockMvc.perform that have been
made in that method.

Closes gh-14
2015-02-25 12:22:00 +00:00
Andy Wilkinson
42270b127c Improve code structure, javadoc, and build configuration
This commit makes extensive changes to the structure of the code. It
introduces a number of separate packages to provide better separation
of the various areas of functionality. Alongside this change the project
has been renamed from spring-restdocs-core to spring-restdocs.

The build has been improved to provide support for building the samples
from the main build using the buildSamples task. While this change has
been made, the samples remain standalone projects so that their
configuration is not dependent on the main project’s build. Running
buildSamples will build the samples using both Maven and Gradle.

All of the main project’s classes now have javadoc and licence/copyright
headers.
2015-02-16 16:46:56 +00:00