Commit Graph

90 Commits

Author SHA1 Message Date
Andy Wilkinson
b3eee08b5d Add support for documenting a request’s query parameters
This commit adds support for documenting a request's query parameters.
For example:

mockMvc.perform(
        get("/issues").param("page", "2").param("limit", "20"))
                .andDo(documentQueryParameters("list-issues",
                        parameterWithName("page")
                                .description("Page number to return"),
                        parameterWithName("limit")
                                .description("Maximum page size")));

Closes gh-39
2015-04-29 10:31:04 +01:00
Andy Wilkinson
b362c493ff Use HttpHeaders to simplify HTTP request documentation 2015-04-29 10:21:41 +01:00
Andy Wilkinson
bff26b1cab Order documented links use the order of the provided descriptors 2015-04-29 10:18:29 +01:00
Andy Wilkinson
9749ec18eb Remove package tangle caused by RestDocumentationException 2015-04-29 10:09:21 +01:00
Andy Wilkinson
37f9f02580 Make the ordering of extracted links match the ordering in the payload
Closes gh-63
2015-04-29 10:05:42 +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
da7efa3e3a Improve testing of the generated documentation snippets 2015-04-28 18:17:39 +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
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
Esko Luontola
0e597e9498 Fix broken include in Spring HATEOAS sample's API guide
Closes gh-59
2015-04-21 11:17:31 +01:00
Andy Wilkinson
8e4e9385be Merge branch 'gh-57' 2015-04-21 11:04:07 +01:00
Andy Wilkinson
474796d15e Polish changes to Content-Type handling in LinkExtractors
- If the request has no Content-Type (null or an empty string), a
   null extractor is returned rather than an exception being thrown.
   This is consistent with the old behaviour.
 - Tests have been reworked a little bit to separate out the new normal
   unit tests from the existing parameterised tests.

Closes gh-56
2015-04-21 11:01:54 +01:00
Heiko Scherrer
d0f0de537c Ignore parameters when finding a LinkExtractor for a Content-Type
Closes gh-57
2015-04-21 11:01:17 +01:00
Andy Wilkinson
d8151e7b03 Add configuration for building on Travis CI
This commit adds the necessary configuration to build the project
on Travis CI. First, the main project is built using Java 7 then the
samples are built using Java 8.

Closes gh-58
2015-04-20 20:17:09 +01:00
Andy Wilkinson
d1f57f530b Add the files that were accidentally excluded by .gitignore 2015-04-20 20:05:15 +01:00
Andy Wilkinson
c496cfc699 Extract the logic for building the samples into a plugin 2015-04-20 19:48:35 +01:00
Dewet Diener
7a8dfeabd7 Improve and simplify quoting for cURL commands
Single quotes are generally safer to use since shells won't try to
interpolate any strings or do variable substitution inside it. This
could be refined to do a check for [&%$] inside the URI/query string
before just blindly surrounding with quotes, but this is safe as it is.

Also, don't escape POST paylods since they are quoted already – this
doesn't work correctly right now.

Closes gh-55
2015-04-20 10:08:13 +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
4cb5f228a9 Correct the javadoc on RestDocmentationConfigurer.withContextPath 2015-04-20 09:48:55 +01:00
Andy Wilkinson
9fe02fc62e Merge branch 'gh-49' 2015-04-20 09:38:45 +01:00
Andy Wilkinson
d686908b19 Ensure that a context path without a leading slash is handled correctly
A context path should either be an empty String, or a String that
begins with a slash. This commit updates both CurlDocumentation and
RestDocumentationConfigurer to prepend a / to the specified context
path when required.

See gh-49
2015-04-20 09:38:28 +01:00
Dmitriy Mayboroda
a5e26a57d8 Allow requests to be configured with a custom context path
Closes gh-49
Closes gh-27
2015-04-20 09:38:18 +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
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
976dd00365 Use TableWriter in LinkSnippetResultHandler
Closes gh-40
2015-03-24 17:31:04 +00:00
Andy Wilkinson
0d2d9cce73 Polishing 2015-03-24 17:06:36 +00: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
Andreas Evers
ecfc7abd92 Initial support for documenting fields in requests and responses
This commit introduces support for documenting the fields in a request
and response, modelled on the existing support for documenting links.
A test with field documentation enabled will fail if a documented
field is missing from the request or response, or if a field present
in the request or response has not been documented.

See gh-24
Closes gh-25
2015-03-23 18:04:36 +00:00
Yann Le Guern
cc54e5d7b0 Consider parameters when performing a POST request
Previously, when producing the curl snippet for a POST request, the
request's parameter map was ignored. This commit updates the snippet
generation to look at the parameter map and POST it to the server
as application/x-www-form-urlencoded data using -d

Closes gh-38
2015-03-23 12:27:56 +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
23a6388177 Escape & characaters in curl request URLs
Without escaping, the & will cause bash to truncate the URL and
background the curl process.

Closes gh-35
2015-03-16 14:45:54 +00:00
Yann Le Guern
c3efc4128f Use request parameters to create query string for GET requests
Previously, only the request's query string was considered when
creating the curl command's request URI. This meant that query
parameters configured via request.addParameter where not included in
the URI.

This commit enhances CurlRequestDocumentationAction so that, in the
absence of a query string, it will use a GET request's parameters to
produce the query string include in the curl command's URI.

Closes gh-26
Closes gh-30
2015-03-16 14:31:36 +00:00
Andy Wilkinson
f649e1a170 Add support to DocumentationWriter for producing tables
This commit adds an API to DocumentationWriter for producing
documentation snippets containing tables. The API is intended to be
fairly simple such that it can be implemented for a variety of
different output formats, and not just for Asciidoctor (the only
currently supported format).

Closes gh-34
2015-03-16 13:52:00 +00:00
Yann Le Guern
d6bd4870fd Fix AsciidoctorWriterTests on Windows
Use String.format and %n so that the test's expectations are correct
on Windows and Unix-like platforms.

Fixes gh-29
2015-03-16 11:13:09 +00:00
Andy Wilkinson
7041c2b202 Polish: add missing copyright header 2015-02-25 12:30:17 +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
Ronald Kurr
289ba57159 Update README to recommend that pretty printing of JSON is enabled
Closes gh-16
2015-02-24 11:54:33 +00:00
Andy Wilkinson
565a57e5da Update the README following rename of RestDocumentationConfiguration 2015-02-24 11:32:22 +00:00
Andy Wilkinson
ea77bd530a Document Spring Framework 4.1 as a requirement
Closes gh-20
2015-02-24 11:30:22 +00:00
Andy Wilkinson
c41542f464 Omit port in curl request snippet if it’s the default for the scheme
Previously an HTTP request to localhost on port 80 or an HTTPS request
to localhost on 443 would generate curl request snippets with the
uris http://localhost:80 and https://localhost:443 respectively. While
specifying the port does no harm, it is unnecessary.

This commit updates CurlDocumentation so that the uri in the request
snippet does not include the port when the port is the default for the
uri’s scheme.

Closes gh-17
2015-02-23 14:25:50 +00:00
andrey
6bdd60cda6 Include query string in curl request snippets 2015-02-23 10:01:53 +00:00
Andreas Evers
35d4bc4d4f Update README after rename of spring-restdocs-core to spring-restdocs
Closes gh-22
2015-02-23 09:46:05 +00:00
Andy Wilkinson
577e59de8f Polishing: remove duplicate call to mkdirs() 2015-02-18 13:33:24 +00:00
Andy Wilkinson
e8243457d0 Improve testing of CurlDocumentation 2015-02-18 13:11:07 +00:00
Andy Wilkinson
3311121f33 Polishing - move test classes into the appropriate packages 2015-02-18 10:16:40 +00:00
Andy Wilkinson
d918304491 Polishing 2015-02-16 20:12:31 +00:00
Andy Wilkinson
81c6e88060 Declare IterableEnumeration final as it only has private constructors 2015-02-16 19:53:47 +00:00