Commit Graph

57 Commits

Author SHA1 Message Date
Andy Wilkinson
2f568c2121 Install spring-restdocs-asciidoctor before building samples 2016-10-21 23:12:11 +01:00
Andy Wilkinson
319bd139fc Polish contribution and rework to use default attribute rather than macro
Rather than introducing a custom macro, this commit opts to implicitly
configure the snippets attribute instead. The attribute is configured
will the path into which snippets are generated, relative to the
directory that contains the Asciidoctor document that is being
rendered.

The samples and documentation have been updated to use the new
spring-restdocs-asciidoctor module and the implicitly configured
snippets attribute.

Closes gh-297
2016-10-21 22:42:11 +01:00
Andy Wilkinson
f2717363f0 Raise the minimum Spring Framework version to 4.3.x
Closes gh-284
2016-07-26 12:09:20 +01:00
Andy Wilkinson
67d31fd7d9 Upgrade to Jacoco 0.7.7.201606060606
Closes gh-282
2016-07-25 14:29:52 +01:00
Andy Wilkinson
4f87f55aaa Fix link to Spring Framework javadoc 2016-05-31 10:04:30 +01:00
Andy Wilkinson
34ec9d523d Polish "Add Grails sample app" (1338df9)
The sole structural change is to rearrange the build slightly so that,
like the other samples, the version of the Grails sample's REST Docs
dependency is automatically updated.

See gh-250
2016-05-31 10:00:52 +01:00
Andy Wilkinson
6935f603f2 Polish ResourceBundleConstraintDescriptionResolver and related tests
Closes gh-234
2016-05-24 16:27:37 +01:00
Andy Wilkinson
7f02cdf725 Upgrade to JMustache 1.12
Closes gh-246
2016-05-24 11:04:30 +01:00
Andy Wilkinson
75ea210187 Build against Spring Framework 4.2.x 2016-05-05 14:29:20 +01:00
Andy Wilkinson
873159cec8 Merge branch '1.0.x' 2016-05-05 11:36:25 +01:00
Andy Wilkinson
e37d0ff560 Use Maven Central rather than JCenter 2016-05-05 11:35:07 +01:00
Andy Wilkinson
feb2f352f6 Fix compiler warnings 2016-04-04 13:26:41 +01:00
Andy Wilkinson
67920dd9f6 Merge branch '1.0.x' 2016-02-16 11:12:54 +00:00
Andy Wilkinson
36bacb470b Move to the offical SonarQube plugin 2016-02-16 11:11:53 +00:00
Andy Wilkinson
d84fca4d63 Ensure that version updates are applied to Slate sample 2016-02-16 10:47:07 +00:00
Andy Wilkinson
4c5095589a Ensure that REST Assured module is installed before sample is built 2016-02-15 17:57:51 +00:00
Andy Wilkinson
ba76c2f843 Add a sample showing how to use Spring REST Docs with Slate
Closes gh-124
2016-02-15 17:52:08 +00:00
Andy Wilkinson
c8ecd25591 Add a sample demonstrating how to use REST Assured
Closes gh-198
2016-02-15 17:12:16 +00:00
Andy Wilkinson
0ef9307481 Add support for manually managing the RestDocumentationContext
In 1.0, the reliance on JUnit was more widespread than it should have
been. It should have been isolated to the JUnit TestRule implementation,
RestDocumentation. Unfortunately, RestDocumentation was also an argument
to MockMvcRestDocumentation.documentationConfiguration which made it
impossible to use Spring REST Docs without having JUnit on the
classpath.

This commit introduces JUnitRestDocumentation and
ManualRestDocumentation. The format is a direct replacement for
RestDocumentation which has been reworked to delegate to
JUnitRestDocumentation. The latter allows manual management of the
RestDocumentationContext, primarily for use with TestNG.

A new interface, RestDocumentationContextProvider, has been introduced.
It is implemented by RestDocumentation, JUnitRestDocumentation and
ManualRestDocumentation.
MockMvcRestDocumentation.documentationConfiguration has been overridden
to also accept a RestDocumentationContextProvider. The method that
accepts a RestDocumentation has been deprecated, as has
RestDocumentation itself.

The documentation has been updated to encourage the use of
JUnitRestDocumentation and a sample illustrating the use of Spring REST
Docs with TestNG has been added.

Closes gh-171
2016-02-09 17:31:32 +00:00
Andy Wilkinson
27f919748b Upgrade to the latest version of the Spring IO Plugin 2016-02-03 17:18:44 +00:00
Andy Wilkinson
130b411e2a Add support for using REST Assured to generate documentation snippets
This commit adds a new module, spring-restdocs-restassured, that
can be used to generate documentation snippets when testing a service
with REST Assured.

Please refer to the updated reference documentation for details.

Thanks to Johan Haleby for making a change to REST Assured so that
path parameters could be documented.

Closes gh-102
2016-01-29 12:31:37 +00:00
Andy Wilkinson
8914ab5767 Merge branch '1.0.x' 2016-01-17 20:26:40 +00:00
Andy Wilkinson
194e62bde3 Remove assumption that working directory will be the project’s root
The plugin for building the samples assumed that the current working
directory would be the directory containing the project’s build.gradle.
While this is generally true on the command line (it isn’t if
-project-dir is used), it isn’t true in Gradle’s IDE integration. This
was leading to an NPE as the sampleBuild task was being configured
to depend on a null task as a result of not finding the sample’s pom.xml
or build.grade file.

This commit corrects the main build.gradle to configure each sample’s
working directory relative to the root project’s directory, rather
than relying on the working directory. It also improves
SampleBuildConfigurer so that it will throw an exception if it fails to
find a sample’s build.gradle or pom.xml rather than continuing
and triggering an NPE inside Gradle.

Closes gh-185
2016-01-17 20:25:21 +00:00
Andy Wilkinson
437d2bcbce Uniquely identify the 1.0.x branch in Sonar 2015-12-09 21:15:44 +00:00
Andy Wilkinson
88d3e72ae9 Upgrade to Spring Framework 4.1.8.RELEASE 2015-12-09 10:48:56 +00:00
Andy Wilkinson
6debc593e5 Don't apply to Spring IO Plugin to the docs project 2015-10-07 10:38:50 +01:00
Andy Wilkinson
0213c9e6fd Add the Spring IO plugin to the build 2015-10-07 09:47:21 +01:00
Andy Wilkinson
f07f23ec85 Update versions of various dependencies 2015-10-06 16:49:07 +01:00
Andy Wilkinson
130a230105 Configure checkstyle and update code to comply
This commit configures Checkstyle and updates the build to comply with
that configuration. The Eclipse JDT metadata has also been updated
so that the output of Eclipse’s code formatting and clean-up is
compliant with Checkstyle.

The use of the latest version (6.10.1) of Checkstyle has required an
upgrade to Gradle 2.7. Gradle hardcode’s the name of the Checkstyle’s
main class which has changed between version 5 (Gradle’s default) and
version 6.

Closes gh-119
2015-09-23 15:50:42 +01:00
Paul-Christian Volkmer
ccb5f3d191 Configure the build to use Checkstyle
This commit adds checkstyle plugin and provides a simple config file.

Closes gh-125
2015-09-23 10:11:26 +01:00
Andy Wilkinson
ce26bd4b1a Polish contribution
- Make commons-codec an optional dependency
 - Isolate knowledge of basic auth header to code that produces the
   -u option

Closes gh-120
2015-09-16 17:39:24 -04:00
Andy Wilkinson
dc9af9599e Include documentation samples in the main docs zip
Previously, to see an example of the documentation that can be
produced by Spring REST Docs, users had to clone the repository and
build one of the samples.

This commit makes it easier to see what Spring REST Docs can do by
updating the docs zip that's automatically published to docs.spring.io
to include both the API Guide and the Getting Started Guide from the
RESTful notes sample.

Closes gh-112
2015-09-10 10:10:05 +01:00
Andy Wilkinson
51051de4c4 Improve contents of generated pom files
Previously, the generated pom files were uncustomised and relied on
Gradle’s default output. Such pom files are problematic for a couple
of reasons: they include test dependencies and they don’t include the
metadata that’s required for publishing to Maven Central.

This commit customises the generated pom files to include the required
metadata and to remove any test dependencies.
2015-09-03 15:07:59 +01:00
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
ff822bd88d Provide an API to ease documenting a request field’s constraints
Previously, users that wanted to document a request field’s constraints
had to roll their own solution. This commit introduces a new API that
makes it easier to document constraints. Support is provided for
discovering Bean Validation constraints and resolving descriptions for
them. The constraint descriptions can then be used as required. For
example, they can included in a field’s description or in an additional
constraints attribute that’s included in an additional table column via
the use of a custom snippet template.

Closes gh-42
2015-08-25 15:00:40 +01:00
Andy Wilkinson
e5c992c249 Upgrade to Spring Framework 4.1.7.RELEASE 2015-07-28 17:44:50 +01:00
Andy Wilkinson
e91e8c8490 Upgrade to Gradle 2.5 2015-07-28 11:58:04 +01:00
Andy Wilkinson
4f850cddd9 Use a template engine to produce the documentation snippets
This commit introduces a new TemplateEngine abstraction that is used
to produce the documentation snippets. A default JMustache-based
implementation is provided. JMustache has been repackaged and embedded
to prevent unwanted conflicts and side-effects.

By default, snippet templates are loaded from the classpath in the
org.springframework.restdocs.templates package. Default snippet
templates are provided for all of the snippets that can be generated.
Each of these templates is named after the snippet that it will
produce – the snippet {name}.adoc is produced by the snippet template
default-{name}.snippet. A snippet named {name}.snippet, if present,
will be used in preference to the default snippet, thereby allowing
the default snippets to be overriden.
2015-07-28 10:54:07 +01:00
Andy Wilkinson
e5840cd48f Set the group on the root project so the docs are published correctly
See gh-37
2015-06-16 17:30:09 +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
e5f35c98f3 Add support for post-processing a response before it is documented
This commit adds support for post-processing a response before it is
documented. Post-processors are provided to pretty-print JSON and XML
responses, remove headers from the response, and mask the hrefs of
Atom- and HAL-formatted links in JSON responses.

Response post-processing is configured prior to configuring the
documentation. For example,

mockMvc.perform(get("/").accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
		.andDo(modifyResponseTo(prettyPrintContent(), removeHeaders("a"),
				maskLinks()).andDocument("post-processed"));

Closes gh-61
Closes gh-31
Closes gh-54
2015-04-30 14:06:40 +01:00
Andy Wilkinson
bad5bdabaa Improve test failure output to ease diagnosis of Travis CI failures 2015-04-29 09:34:52 +01:00
Andy Wilkinson
764daf7c99 Add support for documenting fields in payloads that contain arrays
Previously the path used to document a field had to be dot-separated,
with each segment of the path being used as a key in a map. This made
it impossible to document fields in a payload within an array.

This commit adds support for using [] in a field’s path to represent an
array. For example, the fields in following JSON payload:

{
    "id": 67,
    “date”: "2015-01-20",
    "assets": [
        {
            "id":356,
            "name": "sample"
        }
    ]
}

Can now be documented using the following paths:

 - id
 - date
 - assets[].id
 - assets[].name

Closes gh-60
2015-04-27 16:43:50 +01:00
Andy Wilkinson
c496cfc699 Extract the logic for building the samples into a plugin 2015-04-20 19:48:35 +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
86b431018d Apply custom host and port configuration correctly
Previously, a custom host was configured by setting the request’s
remote host. This is in correct as the remote host as the client’s host.
The custom port was also being configured by setting the request’s
remote port and server port. Only the latter is required.

This commit correct the logic by setting the request’s server name and
server port when configuring a custom host and custom port respectively.
The tests have been improved by introducing the use of Spring HATEOAS’s
BasicLinkBuilder to verify that the configured request produces the
expected scheme, host and port in any generated links.

Closes gh-44
2015-03-25 14:40:27 +00:00
Andy Wilkinson
8b133c7c66 Customize the mvn command based on the OS when building the samples
See gh-33
2015-03-17 14:06:33 +00:00
Andy Wilkinson
45fe87995f Use MAVEN_HOME when calling mvn to build the samples using Maven
See gh-33
2015-03-17 10:42:43 +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
e8243457d0 Improve testing of CurlDocumentation 2015-02-18 13:11:07 +00:00