Commit Graph

71 Commits

Author SHA1 Message Date
Andy Wilkinson
fc3ae3b4a2 Add support for documenting the parts of a multipart request
Closes gh-161
2016-05-12 16:30:36 +01:00
Andy Wilkinson
d362f3f41f Document support for relaxed snippets
Closes gh-223
2016-05-05 14:47:03 +01:00
Andy Wilkinson
60a02a431f Improve documentation of project's requirements
Closes gh-217
2016-05-05 14:37:58 +01:00
Andy Wilkinson
5e2552f8c4 Merge branch '1.0.x' 2016-05-05 12:48:23 +01:00
Andy Wilkinson
6a5fd53910 Update Asciidoctor dependencies 2016-05-05 12:47:22 +01:00
Andy Wilkinson
0e52ef04a1 Document how to ignore common links without repetition
Closes gh-177
2016-04-22 11:18:27 +01:00
Andy Wilkinson
b62c5f0374 Make it easier to document common portions of req and resp payloads
This commit adds a new andWithPrefix(String, FieldDescriptor[]) method
to both RequestFieldsSnippet and ResponseFieldsSnippet. It can be
used to add descriptors to an existing snippet, applying the given
prefix to the additional descriptors as it does so. This allows the
descriptors for a portion of a payload to be created once and then
reused, irrespective of where in the payload the portion appears.

Closes gh-221
2016-04-22 10:30:52 +01:00
Andy Wilkinson
2897b8d1b4 Provide a preprocessor for modifying a request’s parameters
Closes gh-155
2016-04-13 17:50:19 +01:00
Andy Wilkinson
c4b7438708 Derive a link's description from its title
Previously, a LinkDescriptor had to be created with both a rel and a
description. If a description was not provided a failure would occur.

This commit relaxes the above-described restriction by allowing a
link's title to be used as its default description. If a descriptor
has a description, it will always be used irrespective of whether or
not the link has a title. If the descriptor does not have a
description and the link does have a title, the link's title will be
used. If the descriptor does not have a description and the link does
not have a title a failure will occur.

Closes gh-105
2016-04-13 16:16:15 +01:00
Andy Wilkinson
ae53a4e8eb Allow request and path parameters to be marked as optional
Closes gh-169
2016-04-13 12:38:36 +01:00
Andy Wilkinson
ecdc1971c2 Add default descriptions for Hibernate Validator's constraints
Closes gh-151
2016-04-13 12:00:56 +01:00
Andy Wilkinson
8b039e5f81 Add support for reusing a snippet to document common elements
This commit updates all of the Snippet implementations that take one
or more descriptors to provide an and method that can be used to
create a new Snippet that has additional descriptors.

Closes gh-168
2016-04-12 17:37:55 +01:00
Andy Wilkinson
feb2f352f6 Fix compiler warnings 2016-04-04 13:26:41 +01:00
Andy Wilkinson
976c31f860 Merge branch '1.0.x' 2016-04-04 11:43:57 +01:00
Andy Wilkinson
547c4f3fb1 Simplify documentation of Asciidoctor Maven plugin's phase
Previously the phase was documented as `package` by default with
instructions to change it to `prepare-package` if you want to
include the documentation in the project's package. This led to some
confusion and sometimes the step to change it to `prepare-package`
was missed.

This commit updates the documentation to recommend that
`prepare-package` is always used. It works equally well for both
cases (packaging the documentation or not) and avoids the possible
confusion described above.

Closes gh-218
2016-04-04 11:39:56 +01:00
Andy Wilkinson
37e16bc308 Polish contribution
This commit polishes the HTTPie request snippet contribution made in
b26d8c0. It makes the following significant changes:

- Applies project’s coding conventions for formatting and the like
- Moves to a composition-based approach for sharing functionality
  between the curl and HTTPie snippets by replacing AbstractCliSnippet
  with CliOperationRequest.
- Introduces a single package for CLI command snippets, thereby allowing
  more code to be package-private.

See gh-207
2016-03-09 17:38:04 +00:00
Raman Gupta
b26d8c085d Add support for generating an HTTPie snippet
This commit adds support for generating a snippet that contains
the HTTPie command for the request. As the snippet does not require
any additional configuration, it has added to the existing default
snippets.

Httpie does not currently support setting the content type for each
part in a multipart form -- these multipart types are currently
ignored. See:

    https://github.com/jkbrzt/httpie/issues/199
    https://github.com/jkbrzt/httpie/issues/271
    https://github.com/jkbrzt/httpie/pull/285
    https://github.com/jkbrzt/httpie/pull/398

There is an issue with specifying piped input for multipart form
data. There is no way currently to specify the data without specifying
a filename parameter in the Content-Disposition. For now, this is
ignored. See:

    https://github.com/jkbrzt/httpie/issues/342

See gh-207
2016-03-09 15:27:38 +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
26bae13b85 Merge branch '1.0.x' 2016-02-15 14:20:33 +00:00
Andy Wilkinson
4d44401efa Add a note in the documentation about use of the JVM's default charset
Closes gh-201
2016-02-15 12:43:32 +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
6578f42730 Allow custom templates to be provided for a specific template format
Previously, custom snippet templates were loaded from
org/springframework/restdocs/templates and the default templates were
loaded from org/springframework/restdocs/templates/{$formatId}.
Without relying on the ordering of the classpath, this made it
impossible to provide a custom template for a specific format.

This commit updates the locations that are checked for snippet
templates. The following locations are now checked in order:

1. org/springframework/restdocs/templates/${formatId}/${name}.snippet
2. org/springframework/restdocs/templates/${name}.snippet
3. org/springframework/restdocs/templates/${formatId}/default-${name}.snippet

The second location is provided largely for backwards compatibility
with 1.0. Users are expected to use the first location to provide
any custom templates, with Spring REST Docs provided templates for
all of the built-in snippets in the third location.

Closes gh-196
Closes gh-197
2016-02-08 13:41:24 +00:00
Andy Wilkinson
cb9e10bf5a Break the package cycle caused by the introduction of SnippetFormat 2016-02-08 11:41:47 +00:00
Andy Wilkinson
1131c9fa6e Polish pattern-based header removal contribution
Closes gh-191
2016-02-05 09:36:28 +00:00
Roland Huß
1897ec54f2 Add support for removing headers that match a Pattern
A new preprocessor method `removeMatchingHeaders` has been introduced
which takes one or more regular expression patterns (as Strings). Any
header that matches a pattern is removed.

Closes gh-195
2016-02-05 09:32:29 +00:00
Andy Wilkinson
4d37dea1d6 Add support for generating snippets in Markdown
This commit introduces support for generating snippets formatted
using Markdown. Asciidoctor remains the default.

A new SnippetFormat abstraction has been introduced with Asciidoctor
and Markdown implementations provided out of the box.
Markdown-formatted templates are also provided for all of the default
snippets.

Please refer to the updated reference documentation for further
details.

Closes gh-150
Closes gh-19
2016-02-02 12:55:58 +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
c7aaff7e7e Merge branch '1.0.x' 2016-01-27 17:19:19 +00:00
Grant Hutchins
d55b5b7738 Fix typo
Closes gh-188
2016-01-27 17:18:57 +00:00
Andy Wilkinson
5f4541bf69 Collapse Maven and Gradle setup into one section with switchable examples
This commit adds an Asciidoctor extension that post-processes code
blocks, collapsing any secondary blocks into the preceding primary
block. The primary block is then augmented with a switch. This switch
contains one item for each block. Clicking an item causes the associated
block’s content to be displayed. Each item is named using its block’s
title.

The getting started instructions have been updated to take advantage of
this new switching support, with the Maven and Gradle instructions
being collapsed into a single section.

Closes gh-189
2016-01-27 17:02:00 +00:00
Andy Wilkinson
d184425216 Polishing 2016-01-26 12:38:34 +00:00
Johnny Lim
a3c3bef093 Fix the link in the documentation to the default snippet templates
Closes gh-160
2015-12-03 17:54:43 +00:00
Andy Wilkinson
e8cf957f15 Update documentation to mention that you can write custom preprocessors
Closes gh-156
2015-12-03 17:50:34 +00:00
Andy Wilkinson
7a819b15b6 Make it clear that JSON array responses can be documented
Closes gh-163
2015-12-03 17:39:00 +00:00
Andy Wilkinson
c559efb81b Provide examples for JUnit rule configuration with both Maven and Gradle
Closes gh-162
2015-12-03 16:02:16 +00:00
Andy Wilkinson
69f6b40e28 Correct the links in the documentation to the samples on GitHub
Closes gh-147
2015-10-09 09:43:34 +01:00
Andy Wilkinson
a693d12ce0 Polish the documentation 2015-10-06 16:29:23 +01:00
Andy Wilkinson
ea8f736259 Polish contribution that added support for documenting HTTP headers
The main changes are:

- Update javadoc to align with changes made in 5a01016
- Update documentation with details of the new support for documenting
  HTTP headers
- Add tests to verify that HTTP headers are matched case-insensitively

Closes gh-71
2015-09-29 13:03:27 +01:00
Andy Wilkinson
535bea24f9 Improve handling of Host header so a preprocessor can remove it
Previously, the Host header was treated specially in the HTTP request
snippet. If no Host header was specified, one would always be added
prior to producing the snippet. This ensured that the snippet was
valid (an HTTP 1.1 request must include a Host header), but came at
the cost of some confusion about why a preprocessor could not remove
it.

This commit updates the special treatment of the Host header so that
it's now performed in a central location so that all of the snippets
can benefit from a Host header being added if one isn't provided.
The handling of the Content-Length header has also been reworked so
that it's performed in the same location. The curl request snippet
has been updated so that it doesn't include setting the Host header
on the command line; it's unnecessary as curl will automatically
include a Host header in the request. The documentation of the
Host header's special treatment (made in 2fc0420) that noted that it
was unaffected by preprocessing has been reverted.

Closes gh-134
2015-09-28 15:16:48 +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
2fc0420aef Document HTTP request snippet’s special treatment of the Host header
For an HTTP 1.1 request to be valid it must contain a Host header. To
ensure that the HTTP request snippet is a valid HTTP 1.1 request a
Host header will always be included. If one is not present in the
request that’s being documented, the snippet will generate one
automatically. A side-effect of this is that a preprocessor that removes
the Host header will have no effect on the HTTP request snippet. This
commit updates the documentation to describe this behaviour.

Closes gh-134
2015-09-23 10:06:13 +01:00
Andy Wilkinson
42aa996277 Polish JSON field path bracket notation contribution
Closes gh-131
2015-09-22 17:16:22 +01:00
“Jeremy
f3b83f977e Add basic support for using bracket notation in JSON field paths
Previously, only dot notation JSON field paths were supported. Using
dot notation, each key is separated by a '.'. This makes it impossible
to reference a field where the key itself contains a dot.

This commit adds basic bracket notation support to JsonFieldPath.
With this commit, existing functionality remains as is, but users can
now use a basic form of JsonPath bracket notation. This enables the
use of Json keys with embedded dots. i.e. something like :

{
	"a.b" : "one"
}

.andDo(document("example",responseFields(fieldWithPath("['a.b']")…

Closes gh-132
2015-09-22 16:59:15 +01:00
Andy Wilkinson
5cd25897ce Update references to RestDocumentationConfigurer in the documentation
Following the refactoring, the class is now named
RestDocumentationMockMvcConfigurer.
2015-09-22 15:50:56 +01:00
Andy Wilkinson
df40f63238 Add support for using the class name in parameterised operation name
This commit adds support for three new placeholders that can be used
when specifying the name of an operation: {ClassName}, {class-name},
and {class_name}. This allows the operation name to be configured once
in an abstract superclass and reused across multiple test classes.

Closes gh-116
2015-09-13 16:39:54 +01:00
Paul-Christian Volkmer
6dcfdf7206 Update getting started documentation to use new class names
Closes gh-118
2015-09-09 11:46:18 +01:00
Andy Wilkinson
fe84aef912 Polish the documentation 2015-09-08 15:48:11 +01:00
Andy Wilkinson
7b1d9e714c Allow preprocessing to be applied to every test
Following the reworking of the API, it was no longer possible to
apply preprocessing to every test and to still customize the snippets
used by that test.

This commit adds a new snippets() method to
RestDocumentationResultHandler that allows additional snippets to be
configured once the result handler has been created. The documentation
has been updated to describe how to apply preprocessing to every
test and Spring HATEOAS sample has been updated to illustrate the
approach.

Closes gh-88
2015-09-07 11:44:12 +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