Commit Graph

52 Commits

Author SHA1 Message Date
Andy Wilkinson
22dd1e75a4 Apply default scheme, host, and port to WebTestClient URIs
Closes gh-461
2017-11-20 09:50:49 +00:00
Roman Zaynetdinov
2dc48590dd Remove unused custom URI configuration documentation example
Closes gh-457
2017-11-12 15:16:15 +00:00
Andy Wilkinson
ac1d8ec4ac Merge branch '1.2.x' 2017-11-11 18:58:27 +00:00
Michael J. Simons
92b6268da4 Fix name of self rel in reference documentation
Closes gh-449
2017-11-11 18:57:42 +00:00
Andy Wilkinson
1a858a2e1f Build and test against Spring Framework 5.0.1.RELEASE
Closes gh-443
2017-10-30 10:20:25 +00:00
Andy Wilkinson
cfb1fbc85d Add support for using WebFlux's WebTestClient to document an API
Closes gh-384
2017-10-30 09:58:07 +00:00
Andy Wilkinson
eed90c0b9a Polish "Add support for configuring default request and response preprocessors"
Closes gh-424
2017-10-27 12:09:56 +01:00
Filip Hrisafov
4f8b173836 Add support for configuring default request and response preprocessors
See gh-424
2017-10-27 12:09:56 +01:00
Andy Wilkinson
f0c69ade5e Merge branch '1.2.x' 2017-10-23 15:48:32 +01:00
Andy Wilkinson
473e3e1a7b Correct end tag in included source so that it matches opening tag
Closes gh-441
2017-10-23 15:47:42 +01:00
Andy Wilkinson
0e6e785fb0 Add support for JUnit 5
This commit adds support for JUnit 5 and its Jupiter programming
model. A new Jupiter Extension implementation,
RestDocumentationExtension, is provided. This extension can be applied
to a test class to allow it to use Spring REST Docs to document a
RESTful API.

Closes gh-296
2017-05-19 17:29:12 +02:00
Andy Wilkinson
41d537d06a Raise the minimum supported version of Spring Framework to 5.0
This commit upgrades to Spring Framework 5.0.0.RC1. It also upgrades
the Spring Boot-based samples to use Spring Boot 2.0.0.M1 which
supports Spring Framework 5. Lastly, it upgrades a number of
third-party dependencies to align with Spring Framework 5 and Spring
Boot 2.

Closes gh-386
2017-05-18 16:46:03 +02:00
Andy Wilkinson
78982cf515 Add support for REST Assured 3
Closes gh-262
2017-03-20 21:39:25 +00:00
Andy Wilkinson
dec3727da1 Add support for documenting body of a request, response or request part
Closes gh-318
Closes gh-319
2016-10-31 16:34:08 +00:00
Andy Wilkinson
88d5e9192e Merge branch '1.1.x' 2016-10-28 16:20:01 +01:00
Andy Wilkinson
7ff45d273e Call the right endpoint in REST Assured field reuse example
Closes gh-324
2016-10-28 16:19:19 +01:00
Andy Wilkinson
cbd96f301d Update field snippets to no longer document whole subsection by default
Previously, when a field was documented it would implicitly document
the whole subsection of the payload identified by that field. This
could lead to users inadvertently failing to document part of the
payload. Arguably, this was a bug as it violated REST Docs' principle
of producing accurate, detail documentation. However, fixing it
requires a breaking change as people may also be relying on this
behaviour. A balance needed to be struck so the fix is being made in
a minor release.

This commit introduces a new subsectionWithPath method which returns a
SubsectionDescriptor; a specialisation of FieldDescriptor. Users
that were intentionally relying on the old behaviour will have to
replace some usage of fieldWithPath with subsectionWithPath instead.
Users who were unintentionally relying on the old behaviour will have
to add some additional descriptors produced using fieldWithPath and
will receive more accurate documentation in return.

Closes gh-274
2016-10-28 16:12:07 +01:00
Andy Wilkinson
7bcfbd9e35 Add support for documenting a portion of a request or response payload
Closes gh-312
2016-10-27 10:26:46 +01:00
Andy Wilkinson
d2a5b38c83 Polish "Add support for documenting request part payload fields"
- Rebase on latest code, and make use of new support for the same
  TemplatedSnippet producing multiple snippets with different names
  from the same template
- Expand the documentation
- Apply code formatting
- Add support for relaxed documentation of a request part's fields

Closes gh-270
2016-10-25 15:56:47 +01:00
Gerrit Meier
3ac4a1acad Provide a default output directory for snippets based on build tool
Rather than requiring an output directory to be explcitly configured,
a default is now automatically configured based on the build tool
that's being used. When using Gradle, snippets will be generated in
build/generated-snippets. When using Maven, snippets will be
generated in target/generated-snippets.

See gh-297
2016-10-21 22:26:58 +01:00
Andy Wilkinson
0446c99a10 Polishing
- Correct copyright years
- Add `@since` to javadoc of new public classes
- Make new classes final where appropriate
2016-05-25 11:26:02 +01:00
Andy Wilkinson
42353a0b5f Improve the API for generating additional snippets
Previously, if alwaysDo was used and the user wanted to generate
one or more additional snippets when calling perform a separate call
to `snippets` was made prior to calling `perform`. This had two
problems:

 - it required the result handler to be stateful (see gh-243)
 - it wasn't clear that the additional snippets would be produced when
   a subsequent call to perform was made

This commit introduces a new API that allows the additional snippets
to be specified within the MockMvc call. The old API has been
deprecated and will be removed in 2.0.

Closes gh-249
2016-05-25 11:01:48 +01:00
Johnny Lim
09c9cac857 Polish 2016-05-24 13:23:14 +01:00
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
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
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
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
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
cb9e10bf5a Break the package cycle caused by the introduction of SnippetFormat 2016-02-08 11:41:47 +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
d184425216 Polishing 2016-01-26 12:38:34 +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
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
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
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
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
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
3fd65791d1 Add support for documenting fields in XML payloads
Closes gh-46
2015-08-19 17:08:34 +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
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
1175ca91e2 Fix package tangles 2015-07-28 16:16:46 +01:00
Andy Wilkinson
02c6c89172 Allow documentation of extra attributes that apply to the whole snippet
This commit adds support for associating custom attributes with the
generation of a particular snippet. The attributes are included in
the model during snippet rendering allowing them to be referenced from
a custom snippet template. Among other things, this makes it possible
to provide a configurable title for snippets that produce a code
block.

Closes gh-77
2015-07-28 11:05:28 +01:00
Andy Wilkinson
70824aa509 Allow documentation of extra attributes on fields, links, and query parameters
This commit adds support for associating custom attributes with field,
link, and query parameter descriptors. These attributes are then
included in the model during snippet rendering. Coupled with a custom
snippet template, this enables the inclusion of extra column(s) in the
generated tables.

Closes gh-70
2015-07-28 11:05:22 +01:00