You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, form and query parameters were handled together as
request parameters. Howeer, request parameters are a server-side
construct that's specific to the servlet specification. As such
they're not appropriate for the client-side documentation that
Spring REST Docs aims to produce.
This commit replaces support for documenting request parameters
with support for documenting query paramters found in the query
string of the request's URI and for documenting form parameters
found in the form URL encoded body of the request.
Closesgh-832
<1> Configure Spring REST Docs to produce a snippet describing the request's parameters.
689
-
Uses the static `requestParameters` method on `org.springframework.restdocs.request.RequestDocumentation`.
687
+
<1> Configure Spring REST Docs to produce a snippet describing the request's query parameters.
688
+
Uses the static `queryParameters` method on `org.springframework.restdocs.request.RequestDocumentation`.
690
689
<2> Document the `page` parameter.
691
690
Uses the static `parameterWithName` method on `org.springframework.restdocs.request.RequestDocumentation`.
692
691
<3> Document the `per_page` parameter.
693
692
<4> Perform a `GET` request with two parameters, `page` and `per_page`, in the query string.
694
693
695
-
You can also include request parameters as form data in the body of a POST request.
694
+
When documenting query parameters, the test fails if an undocumented query parameter is used in the request's query string.
695
+
Similarly, the test also fails if a documented query parameter is not found in the request's query string and the parameter has not been marked as optional.
696
+
697
+
If you do not want to document a query parameter, you can mark it as ignored.
698
+
This prevents it from appearing in the generated snippet while avoiding the failure described above.
699
+
700
+
You can also document query parameters in a relaxed mode where any undocumented parameters do not cause a test failure.
701
+
To do so, use the `relaxedQueryParameters` method on `org.springframework.restdocs.request.RequestDocumentation`.
702
+
This can be useful when documenting a particular scenario where you only want to focus on a subset of the query parameters.
703
+
704
+
705
+
706
+
[[documenting-your-api-form-parameters]]
707
+
=== Form Parameters
708
+
709
+
You can document a request's form parameters by using `formParameters`.
<1> Configure Spring REST Docs to produce a snippet describing the request's form parameters.
740
+
Uses the static `formParameters` method on `org.springframework.restdocs.request.RequestDocumentation`.
741
+
<2> Document the `username` parameter.
742
+
Uses the static `parameterWithName` method on `org.springframework.restdocs.request.RequestDocumentation`.
743
+
<3> Perform a `POST` request with a single form parameter, `username`.
719
744
720
-
In all cases, the result is a snippet named `request-parameters.adoc` that contains a table describing the parameters that are supported by the resource.
745
+
In all cases, the result is a snippet named `form-parameters.adoc` that contains a table describing the form parameters that are supported by the resource.
721
746
722
-
When documenting request parameters, the test fails if an undocumented request parameter is used in the request.
723
-
Similarly, the test also fails if a documented request parameter is not found in the request and the request parameter has not been marked as optional.
747
+
When documenting form parameters, the test fails if an undocumented form parameter is used in the request body.
748
+
Similarly, the test also fails if a documented form parameter is not found in the request body and the form parameter has not been marked as optional.
724
749
725
-
If you do not want to document a request parameter, you can mark it as ignored.
750
+
If you do not want to document a form parameter, you can mark it as ignored.
726
751
This prevents it from appearing in the generated snippet while avoiding the failure described above.
727
752
728
-
You can also document request parameters in a relaxed mode where any undocumented parameters do not cause a test failure.
729
-
To do so, use the `relaxedRequestParameters` method on `org.springframework.restdocs.request.RequestDocumentation`.
730
-
This can be useful when documenting a particular scenario where you only want to focus on a subset of the request parameters.
753
+
You can also document form parameters in a relaxed mode where any undocumented parameters do not cause a test failure.
754
+
To do so, use the `relaxedFormParameters` method on `org.springframework.restdocs.request.RequestDocumentation`.
755
+
This can be useful when documenting a particular scenario where you only want to focus on a subset of the form parameters.
0 commit comments