Commit Graph

139 Commits

Author SHA1 Message Date
Andy Wilkinson
0f1f84e6a6 Fix JSON field type resolution for top-level and nested array fields
Previously, the logic that determined the field’s type would incorrectly
look at the contents of the array. For example, if the array contained
one or more objects, the field’s type would be resolved as Object rather
than Array.

This commit updates JsonFieldPath to record when a path explicitly
identifies an array so that the array itself is used to determine the
field’s type rather than its contents.

Closes gh-292
2016-08-24 13:02:21 +01:00
Andy Wilkinson
4e4d01a459 Consolidate logic in test rules for getting output dir and operation name 2016-08-24 12:49:51 +01:00
Andy Wilkinson
21567e0ffa Simply dealing with operation names in REST Docs' own tests 2016-08-24 10:05:17 +01:00
Andy Wilkinson
14dcdb61d0 Fix package tangle between cli and operation packages
QueryStringParser has been moved into the operation page. In the
unlikely event that there were any external users of the class, a
deprecated version remains in the cli package for backwards
compatibility. It will be removed in 1.2.

Closes gh-286
2016-08-19 20:14:20 +01:00
Andy Wilkinson
5c6cf7f12f Polishing 2016-08-19 19:52:25 +01:00
Andy Wilkinson
a0faebdb0a Ignore query string when extracting path parameters
Closes gh-285
2016-08-19 19:52:23 +01:00
Andy Wilkinson
9ba0a9b6be Stop field snippets requiring a type for missing, optional, ignored field
Missing optional fields require a type to be explicitly provided as
it cannot be inferred from the payload. Ignored fields are not
included in the documentation, yet, previously, a field that was
missing, optional, and ignored would still require a type to be
provided otherwise the test would fail. This was pointless as the
field wasn't going to appear in the documentation.

This commit updates the fields snippets so that a type is no longer
required for a field that is missing, optional and ignored.

Closes gh-289
2016-08-19 19:52:14 +01:00
Andy Wilkinson
ec3a05926e Merge branch '1.0.x' into 1.1.x 2016-08-10 17:22:58 +01:00
Andy Wilkinson
b430a88796 Polishing 2016-08-10 17:08:18 +01:00
Andy Wilkinson
bf9b0f2d64 Ensure that query string is not duplicated when parameters overlap
Closes gh-286
2016-07-29 21:10:21 +01:00
Andy Wilkinson
78318775e0 Cause a failure when field's documented and actual types do not match
Closes gh-276
2016-07-22 13:20:44 +01:00
Andy Wilkinson
86c2310b90 Improve message when fields cannot be documented due to empty body
Closes gh-278
2016-07-22 11:44:43 +01:00
Andy Wilkinson
0a0136ca58 Move spring-webmvc dependency to where it's needed
Previously, spring-restdocs-core had a dependency on spring-webmvc
however it only used classes from spring-web. This commit moves
the spring-webmvc dependency from spring-restdocs-core to
spring-restdocs-mockmvc where it's needed. It's now in the runtime
scope (rather than compile) as it's not needed at compile time but
is needed at runtime by the MockMvc support in spring-test.

Closes gh-273
2016-07-05 12:49:17 +01:00
Johnny Lim
c6f20f2138 Correct javadoc in LinksSnippet
Closes gh-271
2016-06-24 09:30:31 +01:00
Andy Wilkinson
8ca1dfa1ad Improve handling of requests with both parameters and content
Previously, if a MockMvc request was made with parameters and body
content, the parameters were omitted from the resulting curl, HTTPie
and HTTP request snippets.

This commit updates the affected snippets to ensure that the
parameters are included. The user-provided content is interpreted
as indicating that the parameters should be sent in the query string
rather than as form-encoded content.

Closes gh-239
2016-06-23 17:53:32 +01:00
Andy Wilkinson
37519398c7 Include customized Host header in curl and HTTPie request snippets
Previously, the curl and HTTPie request snippets always excluded the
Host header, relying on the Host header that’s auto-generated by curl
and HTTPie instead. This worked well for the most part, but meant that
incorrect snippets were generated when the request was being sent with
a custom host header that did not match the header that would be
auto-generated.

This commit updates CliOperationRequest to only filter out the Host
header if it’s the same as the header that would be auto-generated
by curl or HTTPie.

Closes gh-258
2016-06-23 15:52:30 +01:00
Andy Wilkinson
a4298b29e7 Include request URI’s port, if any, in default Host header
Previously, OperationRequestFactory would add a Host header if one did
not already exist in the request’s headers, however it did not include
the port. This meant that when the request was being made to a
non-standard port (a port other than 80 for an HTTP request and 443 for
an HTTPS request) the Host header was incorrect.

This commit updates OperationRequestFactory to check the URI for a port
and, if it has one, include it in the Host header.
UriModifyingOperationPreprocessor has also been updated to correctly
include the port in the Host header.

Closes gh-269
2016-06-23 15:45:11 +01:00
Andy Wilkinson
251d93ddc8 Correct ordering of Javadoc tags 2016-05-25 11:34:57 +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
Andy Wilkinson
cb1f98c601 Improve handling of parameters with null values
Closes gh-199
2016-05-24 16:39:57 +01:00
Andy Wilkinson
6935f603f2 Polish ResourceBundleConstraintDescriptionResolver and related tests
Closes gh-234
2016-05-24 16:27:37 +01:00
Andy Wilkinson
4715351cce Make it easier to provide a placeholder resolver that uses the context
Closes gh-235
2016-05-24 15:42:22 +01:00
Andy Wilkinson
81b2f11ebf Polish "Allow descriptors to be provided as a List as well as via varags"
See gh-247
2016-05-24 13:54:17 +01:00
Marcel Overdijk
5edc27fc99 Allow descriptors to be provided as a List as well as via varags
Closes gh-247
2016-05-24 13:34:30 +01:00
Marcel Overdijk
d58f69175f Provide utility method for applying a path prefix to field descriptors
applyPathPrefix is generally useful but, previously, it was only
available as a protected method on AbstractFieldsSnippet.

This commit moves the method from AbstractFieldsSnippet to
PayloadDocumentation where it's now public and static.

Closes gh-245
2016-05-24 13:27:30 +01:00
Johnny Lim
09c9cac857 Polish 2016-05-24 13:23:14 +01:00
Andy Wilkinson
3c80176e66 Merge branch '1.0.x' 2016-05-24 11:42:31 +01:00
Andy Wilkinson
404b99b0a4 Avoid problems caused by | characters in table cell content
Previously, a | character in a cell of an Asciidoctor table would
break that table's formatting as it would be interpretted as a
delimiter for the cell. The problem also affects Markdown tables where
the | character is not within backticks.

This commit addresses the problem with Asciidoctor tables by
introducing a JMustache Lambda that escapes | characters by prefixing
them with a backslash.

Unfortunately, a complete solution to the problem when using Markdown
is not as straightforward. Markdown only requires a | character to be
espaced when it is not within backticks. Determing this isn't
straightforward as the text would have to be parsed, taking into
account the possibility of backticks themselves being escaped.
Instead, this commit attempts to avoid the problem in a different way.

The most likely source of a | character is when documenting a
`@Pattern` constraint that uses a | character in its regular
expression. To improve the readability of the regular expression this
commit wraps it in backticks, thereby formatting it in a monospaced
font in both Asciidoctor and Markdown and also avoiding any escaping
problems with the latter.

Closes gh-232
See gh-230
2016-05-24 10:50:32 +01:00
Andy Wilkinson
65e55ac15c Allow descriptors to be added using a List in addition to varags
Closes gh-242
2016-05-23 16:11:32 +01:00
Andy Wilkinson
117e8ec096 Provide an API for configuring additional default snippets
Previously, the default snippets could only be configured by
replacing those that are configured out of the box. This commit adds
a method, withAdditionalDefaults, that can be used to add one or more
snippets to those that are configured out of the box.

Closes gh-237
2016-05-23 15:51:17 +01:00
Andy Wilkinson
950f889a7e Merge branch '1.0.x' 2016-05-17 17:15:19 +01:00
Andy Wilkinson
b81c03646f Polish MustacheTemplate's javadoc 2016-05-17 17:15:01 +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
63a6ad2c91 Improve readability by using monospaced font in various snippets
This commit updates a number of the snippets to use a monospaced font
for parts of their output. The changes are:

- Links snippet: rel
- Path parameters: name
- Request fields: path and type
- Request headers: name
- Request parameters: name
- Response fields: path and type
- Response headers: name

Closes gh-230
2016-05-11 14:50:39 +01:00
Andy Wilkinson
1c95232e67 Include optional attribute in model for path and req param descriptors 2016-05-05 10:37:19 +01:00
Andy Wilkinson
5b32a3aa98 Optional path and req param descriptors should count as documented
Previously, optional path and request parameter descriptors were
ignored when checking that all of the parameters that are present
had been documented. This lead to a false negative if a request
or path parameter was present and was documented with an optional
descriptor.

This commit uses all of the descriptors, not just those that are not
optional, when checking for undocumented parameters.

Closes gh-228
2016-05-05 10:34:02 +01:00
Andy Wilkinson
b15ee5918d Merge branch '1.0.x' 2016-05-05 10:24:36 +01:00
Andy Wilkinson
96330b2e30 Improve testing of optional links and request and response fields 2016-05-05 10:05:20 +01:00
Andy Wilkinson
130ea784f7 Merge branch '1.0.x' 2016-05-05 09:53:30 +01:00
Andy Wilkinson
a3e6883524 Apply Eclipse Mars (4.5.2) code formatting 2016-05-05 09:50:01 +01:00
Andy Wilkinson
043e796502 Introduce relaxed snippets that don’t fail when item is not documented
Previously, many of the snippets would fail when something wasn’t
documented. This worked well when writing exhaustive API documentation,
but was cumbersome when trying to document a scenario that might only
being interested in a subset of the links, response fields, etc. It was
necessary to mark things that were not of interest as being ignored.

This commit introduces a relaxed variant of several snippets. A relaxed
snippet will not fail if something has not been documented. Instead,
the undocumented thing will be ignored. If something has been documented
but it does not exist a failure will still occur.

Closes gh-175
2016-04-22 12:41:05 +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
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