Commit Graph

186 Commits

Author SHA1 Message Date
Andy Wilkinson
90c3549f55 Refine ordering of default, operation, and additional snippets
Previously, the ordering was:

1. Operation snippets
2. Default snippets
3. Additional snippets

This meant that any operation snippets (those specifically configured
for the documentation of the particular operation) would be
overwritten by the output of the default snippets.

This commit updates the ordering to the following:

1. Default snippets
2. Operation snippets
3. Additional snippets

Closes gh-453
2017-11-07 17:52:02 +00:00
Andy Wilkinson
07bca1875f Replace placeholders in snippet name as well as the operation name
Previously, StandardWriterResolver only replaced placeholders in the
operation name. This meant that the name and location of generated
snippets was unnecessarily limited.

This commit makes things more flexible by updating
StandardWriterResolver to replace placeholders in the snippet name
as well.

Closes gh-403
2017-10-20 10:56:07 +01:00
Andy Wilkinson
f62b0f3ce7 Support documentation of a required field beneath an optional field
Previously, if a field nested beneath an optional field was documented
and was required, it would be identified as missing even if its
optional ancestor was missing. This made it impossible to document
required fields of an optional subsection of a payload.

This commit updates JsonContentHandler to consider a field’s ancestors
when determining if it should be reported as missing. If the field
field has an optional ancestor that is not present, the field is not
considered to be missing if it too is not present. If the field has
an optional ancestor that is present then the field is considered to
be missing if it is not present.

Closes gh-429
2017-10-20 10:05:26 +01:00
Johnny Lim
aeb12673ae Polish tests
Closes gh-436
2017-10-20 09:39:59 +01:00
Andy Wilkinson
caf01d1f21 Revert "Make sure that spring-aop is available at test runtime"
This reverts commit 26707cd7ac.

See gh-411
2017-10-13 11:42:33 +01:00
Andy Wilkinson
0c8ec11c9c Polish “Reuse ObjectMapper in FieldPathPayloadSubsectionExtractor” 2017-10-12 10:36:23 +01:00
Johnny Lim
9bd9fa31dc Reuse ObjectMapper in FieldPathPayloadSubsectionExtractor
Closes gh-431
2017-10-12 10:33:40 +01:00
Andy Wilkinson
47bcc45e45 Upgrade dependencies 2017-09-23 18:00:17 +01:00
Andy Wilkinson
d22dc1e211 Include filename in Content-Disposition header when available
Closes gh-425
2017-09-23 17:40:22 +01:00
Andy Wilkinson
7c6c2e7523 Polish 2017-09-23 17:20:03 +01:00
Andy Wilkinson
a084175afd Fix field extraction and type resolution beneath arrays and wildcards
Fixes gh-422
Fixes gh-423
2017-09-23 16:40:12 +01:00
Andy Wilkinson
4854bc949f Fix type resolution for fields with null and non-null values
Closes gh-398
2017-09-23 16:40:07 +01:00
Andy Wilkinson
26707cd7ac Make sure that spring-aop is available at test runtime
Closes gh-411
2017-07-09 11:08:15 +01:00
Andy Wilkinson
a38a512033 Require occasionally null or absent field in array to be marked optional
Closes gh-402
2017-07-02 10:29:27 +01:00
Andy Wilkinson
a84bb0c569 Make new snippet relaxed when adding descriptors to relaxed snippet
Closes gh-400
2017-07-01 16:27:40 +01:00
Andy Wilkinson
6bf1edcd09 Improve handling of null fields beneath an array
Previously, if an array contained objects where a field was sometimes
null and sometimes had a value of a consistent type, the type inferred
type was varies. Furthermore, it was not possible for the user to
specify a type other than varies as a mismatch would be detected.

This commit updates JsonFieldTypeResolver so that, when dealing with
an imprecise field path (i.e. a path for a field within an array),
null values that don't match the common type for the field are
ignored. This produces the following behavior when nulls are involved:

- All null fields results in the null type
- A mixture of nulls and a particular type results in the particular
  type
- A mixture of nulls and two or more other types results in the varies
  type

Closes gh-398
2017-07-01 11:07:38 +01:00
Andy Wilkinson
5cef4745f7 Polish new response fields test and add equivalent for request fields
See gh-399
2017-07-01 10:57:26 +01:00
Nakul Chaudhari
288ebf771a Add a test that shows problem with sometimes null field within an array
Closes gh-399
2017-07-01 10:52:26 +01:00
Andy Wilkinson
113976f2d9 Support documenting fields in XML payloads with any content type
Previously, the document fields in an XML payload, the request or
response had to have an application/xml content type. This prevented
documenting standard XML content types such as text/xml and
application/rss+xml as well as payloads with custom XML content types.

This commit updates the logic that sets up the ContentHandler to
first attempt to parse the content as JSON. If that fails it then
parses it as XML. If that fails an exception is thrown. This allows
any JSON or XML content, irrespective of the actual content type, to
be documented.

Closes gh-393
2017-05-12 12:35:15 +01:00
Johnny Lim
4a1facd1e6 Fix typo in name of local variable in CurlRequestSnippet
Closes gh-375
2017-03-28 09:22:37 +01:00
Andy Wilkinson
ab1613ed63 Add support for using a wildcard when documenting a payload field
Closes gh-265
2017-03-23 11:05:48 +00:00
Andy Wilkinson
a6d322007b Polish "Provide more control of formatting of curl and HTTPie commands"
See gh-348
Closes gh-260
2017-03-20 20:11:31 +00:00
Tomasz Kopczynski
2cb9d36ef1 Line breaks in cURL and HTTPie snippets
Closes gh-260
2017-03-20 20:11:31 +00:00
Andy Wilkinson
539cc1756e Merge branch '1.1.x' 2017-03-08 12:38:11 +00:00
Andy Wilkinson
81c2816693 Relax field type validation when marked as optional and value is null
Previously, if a field was marked as optional and it appeared in a
payload with a null value a failure would occur if the field's type
was configured to be a JsonFieldType other than NULL.

This commit relaxes this restriction so that a null value is tolerated
when a field has been marked as optional.

Closes gh-365
2017-03-08 12:38:03 +00:00
Andy Wilkinson
722048e20f Introduce RequestCookie to avoid core depending on the Servlet API
Closes gh-345
2017-02-03 14:55:18 +00:00
Andy Wilkinson
a9c1e04081 Polish "Include cookies in request snippets"
See gh-336

Closes gh-302
Closes gh-303
Closes gh-304
2017-02-02 14:50:22 +00:00
Tomasz Kopczynski
25bc6c37da Include cookies in request snippets
Closes gh-336
See gh-302, gh-303, gh-304
2017-02-02 14:49:45 +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
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
60211dab86 Polishing
- Pass attributes into RequestPartFieldsSnippet
 - Add missing package.info.java for new asciidoctor package
2016-10-25 16:10:58 +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
Mathieu POUSSE
13e745a9a9 Add support for documenting request part payload fields
See gh-270
2016-10-25 15:56:43 +01:00
Andy Wilkinson
4f19294220 Allow a TemplatedSnippet to produce multiple snippets from same template
Previously a TemplatedSnippet could only write snippets with the
same name as its template. This meant that the same template could
not be used to produce multiple snippets with different names.

This commit separates the snippet name from the template name, thereby
allowing the snippet name to vary while the template name remains the
same. For backwards compatibility, the default behaviour is for the
template name and snippet name to remain the same. The new overloaded
constructor can be used when the names need to differ.

Closes gh-320
2016-10-25 15:35:20 +01:00
Andy Wilkinson
a603b9481e Merge branch '1.1.x' 2016-10-25 11:36:03 +01:00
Andy Wilkinson
7487f41363 Polish "Copy attributes when applying path prefix to field descriptors"
- Apply code formatting
 - Test copying of attributes (and other parts of a field descriptor)
   in new PayloadDocumentationTests

Closes gh-314
2016-10-25 11:34:09 +01:00
Luis del Toro
27b7553812 Copy attributes when applying path prefix to field descriptors
See gh-314
2016-10-25 11:34:09 +01:00
Andy Wilkinson
319bd139fc Polish contribution and rework to use default attribute rather than macro
Rather than introducing a custom macro, this commit opts to implicitly
configure the snippets attribute instead. The attribute is configured
will the path into which snippets are generated, relative to the
directory that contains the Asciidoctor document that is being
rendered.

The samples and documentation have been updated to use the new
spring-restdocs-asciidoctor module and the implicitly configured
snippets attribute.

Closes gh-297
2016-10-21 22:42:11 +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
c1540838a3 Merge branch '1.1.x' 2016-08-24 13:02:44 +01:00
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
5913eb0c70 Merge branch '1.1.x' 2016-08-24 10:05:58 +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
523e3208c2 Merge branch '1.1.x' 2016-08-19 20:16:09 +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
2e9152ae92 Merge branch '1.1.x' 2016-08-19 19:53:06 +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