Snippets for a multipart request documented with WebTestClient include both the raw body and the parts
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- documentation, testing
Hướng nghiên cứu
Start by comparing WebTestClientRequestConverter with MockMvcRequestConverter, which builds multipart requests with empty content, and reproduce the bad output with WebTestClientRestDocumentationIntegrationTests.multipart(). Check how CurlRequestSnippet, HttpieRequestSnippet and HttpRequestSnippet handle requests that have parts. Done means the curl, HTTPie and HTTP snippets are usable for WebTestClient multipart requests. The issue asks the maintainer to choose between the two fixes first, so confirm that choice before editing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
When a multipart request is documented with WebTestClient, the curl, HTTPie, and HTTP request snippets can't be used as they are. This can be reproduced with the existing WebTestClientRestDocumentationIntegrationTests.multipart() test, which only checks request-parts.adoc. On 4.0.x, it produces the following snippets (the boundary is shortened here):
curl-request.adoc
$ curl 'https://api.example.com/upload' -i -X POST \
-H 'Content-Type: multipart/form-data;boundary=abnXMtqL…' \
-F 'a=alpha;type=text/plain;charset=UTF-8' \
-F 'b=bravo;type=text/plain;charset=UTF-8' \
-d '--abnXMtqL…
Content-Disposition: form-data; name="a"
…
--abnXMtqL…--
'
curl refuses to run this command because it contains both -F and -d:
Warning: You can only select one HTTP request method! You asked for both POST
Warning: (-d, --data) and multipart formpost (-F, --form).
The boundary in the -H option also doesn't match the boundary that curl generates for the -F parts.
httpie-request.adoc
$ echo '--abnXMtqL…
…
--abnXMtqL…--
' | http --multipart POST 'https://api.example.com/upload' \
'a'='alpha' \
'b'='bravo'
HTTPie doesn't allow a request body from stdin to be combined with request items such as 'a'='alpha'.
http-request.adoc
POST /upload HTTP/1.1
Content-Type: multipart/form-data;boundary=abnXMtqL…; boundary=6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
…
--abnXMtqL…
The Content-Type header has two boundary parameters, and the second one, which is added by the snippet, doesn't match the body.
Cause
MockMvcRequestConverter creates a multipart OperationRequest with empty content and the parts, and the snippets are written with that in mind. WebTestClientRequestConverter creates it with both the raw multipart body (result.getRequestBodyContent()) and the parts that are parsed from it. As a result:
CurlRequestSnippetwrites-Ffor each part and also writes-dfor the content. It also keeps the request'smultipart/form-dataContent-Typeheader.HttpieRequestSnippetpipes the content to stdin and also writes each part as a request item.HttpRequestSnippetwrites the content instead of the parts. Because there are parts, it also appends its ownboundaryto theContent-Typeheader, even though there's already one.
In main, RestTestClientRequestConverter does the same as WebTestClientRequestConverter.
Possible fixes
I can see two ways to fix this, and I'd like to know which you'd prefer before opening a pull request:
- In the converters: when the parts are parsed successfully,
WebTestClientRequestConverter(andRestTestClientRequestConverterinmain) would create the request with empty content, which is whatMockMvcRequestConverterdoes. This is limited to the converters, and the snippets wouldn't need to change. However, it changes the request that's passed to user preprocessors and snippets. For example, therequest-bodysnippet for a multipart request would be empty, as it already is with MockMvc. - In the snippets: when a request has parts,
CurlRequestSnippetwould not write-dor themultipart/form-dataContent-Typeheader,HttpieRequestSnippetwould not use stdin, andHttpRequestSnippetwould write the parts and replace any existingboundaryinstead of appending another one. The converters wouldn't change, but there are more changes and they're spread across three snippets.
I think the first option is the more consistent one, but I may be missing a reason why the WebTestClient converter keeps the raw content. Please let me know if either of these looks right to you.
- Ngôn ngữ chính
- Java
- Star
- 1.2k
- Fork
- 733
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của spring-projects/spring-restdocs
-
Support extracting Bean Validation constraints from method parametersCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởstatus: waiting-for-triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 45/100
spring-projects/spring-restdocs#1026 · 2 bình luận ·
-
status: blocked status: waiting-for-triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
spring-projects/spring-restdocs#953 · 7 bình luận ·
-
Add support for modifying a URI's path during pre-processingCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởtype: enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
status: feedback-provided status: waiting-for-triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
spring-projects/spring-restdocs#937 · 4 bình luận ·
-
type: enhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
spring-projects/spring-restdocs#887 · 2 bình luận · 1 reaction ·
Tất cả issue của spring-projects/spring-restdocs
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Type/Improvement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ballerina-platform/static-code-analysis-tool#140 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ready-for-triage triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
RedHatInsights/notifications-backend#5080 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
protobuf
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
FasterXML/jackson-dataformats-binary#874 ·
Maintainer thường phản hồi trong vòng 1 ngày