Commit Graph

95 Commits

Author SHA1 Message Date
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
984f90fa7b Merge branch '1.0.x' 2016-04-13 14:15:04 +01:00
Andy Wilkinson
032b7b59dc Fix HalLinkExtractor's extraction of link hrefs
Closes gh-220
2016-04-13 14:09:08 +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
e5aa5ba728 Make it easier to write a preprocessor that only changes req or resp
The commit introduces OperationPreprocessorAdapter, an abstract
implementation of OperationProcessor that returns to request and
response as-is. OperationPreprocessorAdapter is intended to be
subclassed by OperationProcessor implementations that only modify
the request or the response. Implementations the modify both should
continue to implement OperationPreprocess directly.

Closes gh-154
2016-04-13 10:07:41 +01:00
Andy Wilkinson
2da1a0a979 Update tests following nowrap changes made in bab779a
Closes gh-204
2016-04-12 19:36:34 +01:00
Andy Wilkinson
bab779ac91 Disable wrapping in Asciidoctor HTTP request and response snippets
The HTTP request and response snippets are intended to be an exact
representation of the HTTP request or response which would not wrap.
This commit disables wrapping by adding the nowrap option to the
default templates for these two snippets.

Closes gh-204
2016-04-12 17:50: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
Johnny Lim
05f738d12c Fix typo 2016-04-04 11:17:17 +01:00
Andy Wilkinson
cb39af5163 Improve the formatting of the default Markdown path parameters snippet
Add the required blank line between the table "title" and the
table itself. Without this blank line the table wasn't not formatted
correctly. The "title" has also been wrapped in back ticks to improve
its formatting in the generated HTML.

Closes gh-212
2016-04-04 11:12:15 +01:00
Andy Wilkinson
6ea6dcf996 Fix test failures on Windows caused by different new line characters 2016-03-09 17:51:48 +00: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
7e2a3dcd18 Fix faulty forward merge 2016-02-15 16:04:42 +00:00
Andy Wilkinson
228424e497 Merge branch '1.0.x' 2016-02-15 15:50:08 +00:00
Andy Wilkinson
40201e2e99 Improve handling of empty parameters in curl and HTTP request snippets
Previously, both the curl and HTTP request snippets would ignore
a parameter with no value, for example from the query string of the
url http://localhost:8080/foo?bar.

This commit updates both snippets so that such parameters are
included in the generated snippet, including a multi-part request
that is uploading form data and a field in the form has no value.
Additions have been made to the tests for both snippets.

While the request parameters snippet correctly handled parameters with
no value, there was no test verifying that this was the case. One
has been added in this commit.

Closes gh-200
2016-02-15 15:41:09 +00:00
Andy Wilkinson
7fc5ac10d0 Merge branch '1.0.x' 2016-02-15 12:30:42 +00:00
Andy Wilkinson
cfc413f7ed Avoid byte[] to String to byte[] conversion when pretty printing
Previously, PrettyPrintingContentModifier would convert the byte[]
content into a String and then back into a byte[]. It did so without
consideration for the content’s character set. As a result, it could
fail to preserve the correct character encoding.

This commit updates PrettyPrintingContentModifier to avoid converting
the content into a String and back into a byte[] and to work entirely
with byte arrays instead. Removing the intermediate String from the
process removes the possibility of the content becoming corrupted.

Closes gh-202
2016-02-15 12:28:07 +00:00
Andy Wilkinson
4e996e2cdb Merge branch '1.0.x' 2016-02-15 12:25:49 +00:00
Andy Wilkinson
74f9e272fd Apply Eclipse Mars' code formatting 2016-02-15 12:15:40 +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
83b72f7962 Introduce constants for common attribute names
Closes gh-193
2016-02-08 12:21:25 +00:00
Andy Wilkinson
6df01419cd Merge branch '1.0.x' 2016-02-08 11:49:09 +00:00
Andy Wilkinson
811e7adf70 Add missing package-info.java for config package 2016-02-08 11:49:04 +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
c0fac14fdf Break cycle caused by introduction of RestDocumentationHandler 2016-02-06 10:17:27 +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
a9c9bad15e Reduce duplication by introducing RestDocumentationHandler
Previously, logic for creating an Operation, determining the snippets
to call, and calling them was duplicated in both the MockMvc and
REST Assured modules. This commit introduces a new core class,
RestDocumentationHandler, that now does the bulk of the work in a
reusable manner. The MockMvc and REST Assured modules have been
updated to delegate to RestDocumentationHandler.

Closes gh-194
2016-02-04 11:33:40 +00:00
Andy Wilkinson
28476c2d08 Polish RestDocumentationConfigurer and improve its test coverage 2016-02-02 14:09:20 +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
91d6e2f8ec Improve extensibility and reusability of MustacheTemplateEngine
Previously, MustacheTemplateEngine hard coded the configuration of
its Mustache Compiler. This commit adds an overloaded constructor that
allows a custom Compiler to be used. It also adds protected accessors
for the compiler and the template resource resolver so that they
can be easily accessed by subclasses.

Closes gh-149
2016-02-01 12:37:23 +00:00
Andy Wilkinson
2410f06ff5 Merge branch '1.0.x' 2016-01-29 13:56:48 +00:00
mnhock
5dbb31f38a Fix String comparison in HttpRequestSnippet
Closes gh-186
2016-01-29 13:54:16 +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
9dfa0b5385 Polish PatternReplacingContentModifier 2016-01-29 11:15:45 +00:00
Andy Wilkinson
97ae7a9ce9 Fix javadoc problem with use of em dash 2016-01-26 12:51:37 +00:00
Andy Wilkinson
d184425216 Polishing 2016-01-26 12:38:34 +00:00
Andy Wilkinson
02fa42445f Make consistent use of the diamond operator with generic types 2016-01-26 11:14:29 +00:00
Andy Wilkinson
acb87b98b8 Improve testing of XML attribute handling
Closes gh-166
2015-11-16 17:47:07 +00:00
cschaetzlein
58b992d99e Allow individual attributes in an XML element to be documented
Documenting an XML attribute in the XML payload leads to a
NullPointerException since no parent nodes exists for an XML
attribute. Rather than always trying to remove a node from its parent,
this commit changes the logic to apply special treament to nodes that
are attributes and remove the attribute from its owning element
instead.

Closes gh-167
2015-11-16 17:46:22 +00:00
Andy Wilkinson
75085477b6 Suppress unwanted output to System.err when pretty printing content
Previously, when the XML pretty printer attempted to pretty print
the content of a request or response it would output an error to
System.err if the content was not valid XML. While, benign, this
output was distracting.

This commit updates the XML pretty printer to suppress its output to
System.err by configuring it with an ErrorHandler and an ErrorListener
that swallow any errors of which they are notified.

Closes gh-153
2015-10-22 10:04:56 +01:00
Andy Wilkinson
2730a7ceef Polishing 2015-09-30 19:28:43 +01:00
Andy Wilkinson
fb01a26a16 Allow an item to be undocumented without it causing a test failure
Previously, it was necessary to document every payload field, link,
path parameter, or request. If an item was not documented a failure
would occur. This has proven to be too restrictive for some use cases,
for example splitting up the documentation of a payload’s fields. While
it was possible to use a preprocessor to modify the operation prior to
documentation to remove the items that should not be documented, this
was more difficult than it needed to be.

This commit adds support for marking a descriptor as ignored. Ignored
descriptors count when checking that everything has been documented but
do not actually appear in the generated documentation.

Closes gh-143
2015-09-30 17:53:57 +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