[Spring]: RequestBody required-handling
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 62/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- java, openapi, spring
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
The bug is that the spring generator ignores requestBody.required: false and always emits @RequestBody with its default required=true. Start in the Spring server templates and find where the @RequestBody annotation is written for request bodies. Make it pass required from the spec, then check that a POST to /search with no body and no query parameter is accepted. Done when the generated controller compiles and both curl cases from the issue succeed.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
My goal is to have an endpoint to enable a quick search and an extended search. Using the quick search the endpoint only needs a query-param. Using the extended search a full search-body is required.
I was defining my openapi as follows:
/search:
post:
requestBody:
required: false
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchCriterion"
parameters:
- in: query
name: value
required: false
schema:
type: string
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchResult"
I was expecting to be able to send curl requests like:
- curl -X POST
'http://localhost/search'
-H 'Content-Type: application/json'
-d '[{"type":"NAME","value":"Dummy"}]' - curl -i -X POST
'http://localhost/search?value=something'
-H 'Content-Type: application/json'
But only the first request returned any data. The second request only resulted in a 404.
After shortly analysing the problem I found that the required-property is not handed to the @RequestBody Spring annotation. As the annotation uses true as default for the required attribute, I need to hand the body for every request.
This behaviour should be altered to correctly pass the required-property to the code.
Version
We are using [email protected] (which uses [email protected]) but the current main is also not passing the required-property.
Language / Generator Affected
- spring (i haven't checked any other generators as this should be specific for this generator)
OpenAPI/Swagger Spec
/search:
post:
requestBody:
required: false
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchCriterion"
parameters:
- in: query
name: value
required: false
schema:
type: string
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: "#/components/schemas/SearchResult"
Environment
OS: Windows 11
Java Version: temurin-21.0.6+7.0.LTS
Build Tool: Maven
swagger-codegen-generators Version: 1.0.54
Checklist
- [/] I have searched the existing issues to avoid duplicates.
- [/] I have included a minimal reproducible spec or configuration.
- [/] I have clearly described the steps to reproduce the issue.
- [/] I have specified which generator or template is affected.
- Ngôn ngữ chính
- Mustache
- Star
- 299
- Fork
- 439
- 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
- 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 swagger-api/swagger-codegen-generators
-
[Bug]: Python/pythonFlaskConnexion generators validate map keys instead of values for additionalProperties.enumCó thể đã có người làm @pvillard31 đã nhận 190 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Python generated code: Delete API Requests can be blocked in API Gateways when sends empty bodyĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
[Bug]: Bean validation doesn't work for numbers larger than Integer.MAX_VALUECó thể đã có người làm @apupier đã nhận 278 ngày trước. Đang mởBug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
swagger-api/swagger-codegen-generators#1370 · 3 bình luận · 1 reaction ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
Tất cả issue của swagger-api/swagger-codegen-generators
Issue tương tự
-
beginner good first issue growth
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
BistaDinesh03/critique#161 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug help wanted low priority
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
eugenioenko/ttt#1205 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug IO
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
MrNeRF/LichtFeld-Studio#3824 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
UEFI: File::read/File::write report success on firmware error status when byte count is non-zeroĐang mởC-bug needs-triage O-UEFI T-libs
Độ 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
-
t:urlDecodeUni does not map U+3002 and U+FF61 to a dot, unlike ModSecurityCó thể đã có người làm @fzipi đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày