Commit Graph

183 Commits

Author SHA1 Message Date
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
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
50514293a8 Add an integration test for custom context path configuration
Closes gh-135
2015-09-22 17:45:34 +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
Oliver Trosien
387257ba6f Fix typos in sample asciidoc
Closes gh-129
2015-09-18 21:21:12 -04:00
izeye
9fe4442fcd Fix typo in ConstraintDescriptions' javadoc
Closes gh-127
2015-09-17 09:15:25 -04:00
Andy Wilkinson
7d532aa7bc Merge branch 'gh-120' 2015-09-16 17:45:15 -04: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
Paul-Christian Volkmer
d329e2da5d Use -u 'username:password' for basic auth in the curl request snippet
Previously, when a request was made that used basic auth, the curl
snippet would configure the authentication header with the
Base64-encoded header. This commit updates the snippet to use the
more human-friendly -u option to provide the username and password
in place of the authentication header.

Closes gh-122
2015-09-16 15:44:31 -04:00
Andy Wilkinson
26adbb10ae Add missing copyright header 2015-09-13 12:01:41 -04:00
Andy Wilkinson
14ad59d434 Make descriptions more flexible
Previously, the description of a link, parameter, or field had to be a
String. Given the use of Mustache templates, this was unnecessarily
restrictive. It prevented the use of a richer object, the components of
which could then be accessed in a template.

This commit changes the description of links, parameters, and fields to
be an Object, thereby allowing richer objects to be used. The default
template will call toString on the description during rendering. Custom
templates can be used to make more sophisticated use of the description.

To ensure that the description is consistent across all descriptor
types, it has been moved up onto the AbstractDescriptor superclass.

Closes gh-123
2015-09-13 11:58:22 -04: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
Andy Wilkinson
ebab967e43 Make ContentModifier part of the public API
Previously, ContentModifier and ContentModifyingOperationPreprocessor
were package-private. This meant that anyone wishing to perform content
modification during preprocessing had to reimplement much of the
existing content modifying preprocessor, that than just having to
implement ContentModifier.

This commits make both ContentModifier and
ContentModifyingOperationPreprocessor public so that all custom
content modification is now a matter of implementing a custom
ContentModifier and creating an instance of
ContentModifyingOperationPreprocessor.

Closes gh-121
2015-09-13 16:02:19 +01: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
11c0945d10 Polish the documentation produced by the samples
- Correct the location of the Git repository
- Correct the location of the sample within the repository
- Update the build instructions for the Data REST sample to use Maven
- Move the table of contents to the left
- Add section links

Closes gh-113
2015-09-10 10:00:18 +01:00
Andy Wilkinson
ed3d5f0a59 Add javadoc to protected methods added in 5dc28b9 2015-09-09 11:47:19 +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
5dc28b9bb0 Improve extensibility of RestDocumentationContextPlaceholderResolver
Previously, RestDocumentationContextPlaceholderResolver could be
subclassed, but it didn’t provide access to its state (the
RestDocumentationContext).

This commit opens up RestDocumentationContextPlaceholderResolver by
adding a getter method for its RestDocumentationContext. It also makes
the kebab-base and snake_case conversion methods protected (rather than
private) so that they can be used by subclasses.

See gh-116
2015-09-09 10:08:28 +01:00
Andy Wilkinson
1e53502958 Make milestone builds are available to the samples 2015-09-08 16:07:15 +01:00
Andy Wilkinson
fe84aef912 Polish the documentation 2015-09-08 15:48:11 +01:00
Andy Wilkinson
63e7466304 Fix javadoc in AbstractParametersSnippet 2015-09-08 15:01:32 +01:00
Andy Wilkinson
94d5e2d94f Improve the extensibility of the descriptor classes
This commit improves the extensibility of the various descriptor
classes. The following changes have been made:

 - Constructors have been made protected to allow them to be called by
   subclasses in a different package
 - Model creation has been moved to the relevant snippet class. This
   improves the separation of concerns as a descriptor should not be
   aware of template-based rendering and the need for a model. The
   method is protected to allow it to be overridden by a custom subclass
   that uses a custom descriptor subclass.
 - Methods that should not be overridden have been made final.

See gh-73
2015-09-08 14:52:07 +01:00
Andy Wilkinson
cbbdbcb201 Allow subclasses to access a snippet’s state
This commit updates each of the built-in snippet implementations to
provide protected getter methods for their fields. This allows
subclasses to access and work with the snippet’s state.

See gh-73
2015-09-08 13:51:13 +01:00
Andy Wilkinson
36dfaecffe Improve unit testing of StandardTemplateResourceResolver 2015-09-08 12:54:30 +01:00
Andy Wilkinson
d09950ecaa Polish MockMvcOperationRequestFactory 2015-09-08 12:29:36 +01:00
Andy Wilkinson
875dde3b6f Polish exception handling in snippet implementations 2015-09-08 11:40:57 +01:00
Andy Wilkinson
fece9547ea Automatically align version of samples' dependency with main version
This commit enhances the tasks that build the samples to
automatically update the version of their spring-restdocs dependency
to match the version of the main project.
2015-09-08 11:25:06 +01:00
Andy Wilkinson
c2da4c912a Make the built-in snippets more extensible
The commit opens up all of the default snippets so that it's easier
to extend them and modify their behaviour. All of the built-in
snippets are now public with protected constructors. Also, where
appropriate the models used by the snippets have been made more
fine-grained.

Closes gh-73
2015-09-08 10:30:50 +01:00
Andy Wilkinson
de095eb9fe Add package-info.java to each package
Closes gh-109
2015-09-07 13:20:03 +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
570781832e Eclipse metadata for new spring-restdocs-mockmvc project 2015-09-07 10:35:09 +01:00
Andy Wilkinson
d80c0f751a Cope with different content length due to Windows line endings
Windows uses \r\n for line endings whereas Unix-like platforms us
\n. This causes the content length of a pretty-printed response to
be longer on Windows.
2015-09-03 15:15:38 +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
7235a49dbc Update sample verification to look for snippets in correct location
Previously each sample was built with both Maven and Gradle and the
snippets produced by each build were verified. Now each sample is only
built with either Maven or Gradle. This commit updates the snippet
verification process to look for snippets in the location that’s
appropriate for the sample’s build system.
2015-09-03 15:05:45 +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
9d8bbf0558 Add support for modifying a request prior to it being documented
Prior to this commit it was not possible to modify a request prior to
it being documented, only a response. This commit builds on the new
Operation abstraction to simplify the existing response modification
support and to add support for request modification.

Closes gh-84
2015-09-02 13:05:12 +01:00
Andy Wilkinson
3579b34a77 Introduce a new operation abstraction to reduce coupling with MockMvc
Prior to this commit, MockMvc-classes were used throughout Spring REST
Docs. For example, each Snippet was called with an MvcResult. This
has proven problematic for a few reasons:

1. The MockMvc APIs aren't very amenable to modifying a request or
   response before it's documented. This caused the existing support
   for response modification to rely on CGLib proxies and method
   interceptors. A similary complex solution for request modifiction
   would also have been necessary.
2. Things are harder to reason about than they need to be as the
   MockHttpServletRequest and MockHttpServletResponse classes
   expose more than is required when generating API documentation.
3. Supporting other test frameworks, such as Rest Assured, is hard

This commit introduces a new Operation abstract that encapsulates
all of the information required to document the request that was sent
and the response that was received when performing an operation on a
RESTful service. The new abstraction uses types from Spring's Web
support, such as HttpHeaders, RequestMethod, and MediaType, but does
not rely on MockMvc.

Closes gh-108
2015-09-02 12:47:19 +01:00
Andy Wilkinson
65e37a6276 Update tests to cope with constraint ordering being unspecified 2015-08-25 15:28:17 +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
bc5a9c3714 Update the samples to use Spring Boot 1.2.5 2015-08-19 18:01:25 +01:00
Andy Wilkinson
2842d5f75f Update Travis CI configuration to run on new infrastructure 2015-08-19 17:43:31 +01:00
Andy Wilkinson
32bb724a3d Update the samples to align with recent API changes 2015-08-19 17:25:56 +01:00
Andy Wilkinson
4199a21bfd Documentation polishing 2015-08-19 17:15:36 +01:00
Andy Wilkinson
3fd65791d1 Add support for documenting fields in XML payloads
Closes gh-46
2015-08-19 17:08:34 +01:00
Andy Wilkinson
76dd0cc579 Include request’s path (without query string) in path parameters snippet
The ordering of parameters in the path is important so, without seeing
the path and the order in which the parameters appear, documentation for
the individual parameters is of limited use.

This commit enhances the path parameters snippet to include the
request’s path, minus any query string, in the snippet. By default,
the path is rendered as the title of the parameters table. As with
other snippets, this can be customized by providing a custom template
for the snippet.

Closes gh-103
2015-08-18 11:33:42 +01:00
Andy Wilkinson
d3e1a0d1b6 Provide obvious support for documenting all request parameters
Previously, the snippet for documenting a request’s parameters was
referred to as the query parameters snippet. This was misleading as the
snippet would actually document anything in the request’s parameters
map, not just parameters from the request’s query string.

This commit renames the snippet and the associated templates, etc so
that it is now known as the request parameters snippet. This provides
a more accurate reflection of it being able to document all of a
request’s parameters, not just those from its query string.

Closes gh-104
2015-08-18 10:11:03 +01:00
Andy Wilkinson
dfd65f9f10 Polishing: rename test classes following refactoring in 0c8a7137 2015-08-18 09:15:50 +01:00