[BUG][JAVA][SPRING] Collection request-body validation skipped with useSpringBuiltInValidation=true after 7.25.0
Maintainer thường phản hồi trong vòng 1 ngà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
- 35/100
Hướng nghiên cứu
Start with modules/openapi-generator/src/main/resources/JavaSpring/bodyParams.mustache and compare the v7.25.0 and v7.26.0 versions linked in the issue. Then inspect the Spring generator tests that cover request body validation and reproduce the described collection request with useSpringBuiltInValidation=true. Done means the generated interface preserves validation and the invalid item returns HTTP 400 before the controller runs; coordinate with the already open PR #25741.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
After upgrading openapi-generator-maven-plugin from 7.25.0 to 7.27.0, an existing Spring MVC endpoint accepting a list of DTOs accepts invalid collection elements instead of returning HTTP 400.
We use useSpringBuiltInValidation=true, so the generated interface does not have class-level @Validated.
The generated request parameter changes from:
@Valid @RequestBody List<@Valid Item> items
to:
@RequestBody List<@Valid Item> items
The DTO constraints are unchanged.
Expected: Invalid collection elements are rejected with HTTP 400 before the controller implementation executes.
Actual: Invalid collection elements reach the controller, and the endpoint returns HTTP 204.
With 7.25.0, the request is rejected with HandlerMethodValidationException.
Versions
- Previously working: 7.25.0
- Runtime failure observed: 7.27.0
- The relevant template change is already present in 7.26.0, but that version has not been separately runtime-tested.
- Spring Boot: 3.5.16
- Java: 21
Template comparison:
Generator configuration
<generatorName>spring</generatorName>
<library>spring-boot</library>
<generateApis>true</generateApis>
<configOptions>
<useSpringBoot3>true</useSpringBoot3>
<useJakartaEe>true</useJakartaEe>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<useResponseEntity>false</useResponseEntity>
<useSpringBuiltInValidation>true</useSpringBuiltInValidation>
</configOptions>
Illustrative OpenAPI specification
The regression was observed in an existing application. This generic specification illustrates the affected request shape; this standalone example has not yet been executed.
openapi: 3.0.3
info:
title: Collection validation example
version: 1.0.0
paths:
/items:
post:
operationId: updateItems
requestBody:
required: true
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Item'
responses:
'204':
description: Accepted
components:
schemas:
Item:
type: object
properties:
name:
type: string
maxLength: 3
Implement the generated interface in a @RestController, without adding class-level @Validated, and submit:
POST /items
Content-Type: application/json
[{"name":"too long"}]
The invalid name should cause HTTP 400 rather than reaching the controller.
Related upstream change
This appears related to the removal of container-level @Valid in:
https://github.com/OpenAPITools/openapi-generator/pull/24176
The author's runtime verification uses a controller annotated with class-level @Validated:
https://github.com/OpenAPITools/openapi-generator/pull/24176#issuecomment-4859610681
However, useSpringBuiltInValidation=true intentionally suppresses that annotation and uses Spring MVC's built-in validation. Therefore, that verification does not cover this configuration.
Could the generator preserve collection request-body validation with useSpringBuiltInValidation=true, or document a supported migration for this configuration?
- Ngôn ngữ chính
- Java
- Star
- 26.9k
- Fork
- 7.8k
- Merge trung bình
- 2 ngày 23 phút
- Pull request đã merge (30 ngày)
- 177
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Có Dockerfile hoặc 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 OpenAPITools/openapi-generator
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OpenAPITools/openapi-generator#25768 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Enhancement: Feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
OpenAPITools/openapi-generator#25753 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUBY-NEXTGEN] A non-String value in a pattern-constrained attribute raises NoMethodErrorCó thể đã có người làm @Inf1mum đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
OpenAPITools/openapi-generator#25724 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUBY-NEXTGEN] Response#to_hash is advertised and raises when the data is an ArrayCó thể đã có người làm @Inf1mum đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
OpenAPITools/openapi-generator#25723 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG][RUBY-NEXTGEN] A JSON string response raises ApiError because the body is parsed twiceCó thể đã có người làm @Inf1mum đã nhận 2 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
OpenAPITools/openapi-generator#25719 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của OpenAPITools/openapi-generator
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
eclipse-tradista/tradista#371 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Failed to start Rescue missionĐang mởcritical
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
mars-sim/mars-sim#2199 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG-02] Endpoints /assistente/relatorio/*/preview retornam 404 ("Ver na tela" dos relatórios)Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
projeto-ong-amar/projeto-ong-amar-backend#26 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
primefaces/primefaces#15568 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
崩溃日志只按 CRLF 分行Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
PCL-Community/PCL-CE#3872 ·
Maintainer thường phản hồi trong vòng 1 ngày