#3314 fix has no effect if swagger-core resolved a schema before `ObjectMapperProvider` was created
Maintainer thường phản hồi trong vòng 14 ngà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
- 45/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, spring-boot
- Lĩnh vực
- backend
Hướng nghiên cứu
Start in ObjectMapperProvider, where the constructor registers SchemaTypeMixin on the shared Json31.mapper(), then follow SpringDocUtils.cloneViaJson and the fallback in AbstractRequestService.applyBeanValidatorAnnotations. Reproduce by creating a bean that calls AnnotationsUtils.resolveSchemaFromType before springdoc auto-configuration, then requesting /v3/api-docs for a constrained parameter. Done when cloning a JsonSchema with types no longer depends on mapper initialization order; run the relevant springdoc tests for OpenAPI 3.1 schema cloning.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
With OpenAPI 3.1, Json Processing Exception occurred: Cannot construct instance of java.util.HashSet … from String value ('string') (through reference chain: io.swagger.v3.oas.models.media.JsonSchema["type"]) is still logged for every parameter with a validation constraint (@Min, @Pattern, @Size, …), although #3314 should have fixed this in 3.1.1. As a consequence, AbstractRequestService.applyBeanValidatorAnnotations falls back to modifying the original, possibly shared schema, which is the case #3270 meant to avoid.
Cause
ObjectMapperProvider registers SchemaTypeMixin on the JVM-wide Json31.mapper() in its constructor. Jackson only applies mixins to deserializers built afterwards, and caches those deserializers.
swagger-core uses the same mapper: ModelResolver copies property schemas via AnnotationsUtils.clone, which reads them back through ModelDeserializer, which in turn calls Json31.mapper().convertValue(node, JsonSchema.class) after removing type from the node. If that happens before ObjectMapperProvider is created, the cached JsonSchema deserializer lacks the TypeSetDeserializer. Every later SpringDocUtils.cloneViaJson fails, because it does not remove type first.
This happens in any application whose own configuration resolves a schema while it is being created. User configuration beans are instantiated before springdoc's auto-configuration. In our case it was an OperationCustomizer bean:
@Bean
public OperationCustomizer errorResponseSchemas(SpringDocConfigProperties properties) {
Schema schema = AnnotationsUtils.resolveSchemaFromType(ApiResponseBody.class, null, null, properties.isOpenapi31());
// …
}
To Reproduce
- Spring Boot: 4.1.1
- springdoc-openapi: 3.1.1 and 3.2.0
- swagger-core: 2.2.55
springdoc.api-docs.version=OPENAPI_3_1(the default)
- A bean in the application's own configuration that calls
AnnotationsUtils.resolveSchemaFromType(SomeDto.class, null, null, true)for a class with properties. - A controller method with a constrained parameter, e.g.
@RequestParam @Min(1) Integer pageSize. - Request
/v3/api-docs: the warning is logged for that parameter.
At that point, objectMapperProvider.jsonMapper() is Json31.mapper() and findMixInClassFor(Schema.class) returns SchemaTypeMixin, yet SpringDocUtils.cloneViaJson of a JsonSchema with types = [integer] falls back to returning the original object. The same clone succeeds in a fresh JVM without the early bean.
Expected behavior
The schema is copied regardless of what used Json31.mapper() before springdoc was initialized.
Workaround
Inject ObjectMapperProvider into the bean that resolves schemas early, so that springdoc configures the mapper first. This makes the warnings disappear in our application.
Possible fix
Don't change the shared Json31.mapper(). Let ObjectMapperProvider configure its own instance instead, e.g. ObjectMapperFactory.createJson31() with SchemaTypeMixin, as createJson already does for the standalone mappers. Alternatively, swagger-core could make the 3.1 type property readable back in the form it writes it (swagger-api/swagger-core#5264), which would make the mixin unnecessary.
- Ngôn ngữ chính
- Java
- Star
- 3.7k
- Fork
- 605
- Merge trung bình
- 12 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 10
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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 springdoc/springdoc-openapi
-
`ConcurrentModificationException` in `SchemaPropertyDeprecatingConverter.isDeprecated`, and `DEPRECATED_ANNOTATIONS` gains a duplicate on every context startCó thể đã có người làm @awinishere đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
springdoc/springdoc-openapi#3400 ·
Maintainer thường phản hồi trong vòng 14 ngày
-
Property type "null" is missing if Kotlin property name does not equal OpenAPI property nameĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
springdoc/springdoc-openapi#3399 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 14 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 57/100
springdoc/springdoc-openapi#3398 ·
Maintainer thường phản hồi trong vòng 14 ngày
-
Subtype loses allOf reference to its polymorphic parent since 3.2.0 when a controller repeats the interface's @Valid on a @RequestBodyCó thể đã có người làm @jochenberger đã nhận 8 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
springdoc/springdoc-openapi#3393 ·
Maintainer thường phản hồi trong vòng 14 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 54/100
springdoc/springdoc-openapi#3374 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 14 ngày
Tất cả issue của springdoc/springdoc-openapi
Issue tương tự
-
needs-area-label
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
Maintainer thường phản hồi trong vòng 2 ngày
-
enhancement Java macOS
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
freerouting/freerouting#1079 ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
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 78/100
apache/maven-enforcer#1074 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Gradle liquibaseDiffChangelog drops jhi_date_time_wrapperCó thể đã có người làm @mraible đã nhận hôm nay. Đang mởarea: triage theme: undefined
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
jhipster/generator-jhipster#35998 ·
Maintainer thường phản hồi trong vòng 1 ngày