#3314 fix has no effect if swagger-core resolved a schema before `ObjectMapperProvider` was created
維護者通常 14 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 45/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- java, spring-boot
- 領域
- backend
研究方向
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.
由索引模型根據 Issue 內容生成。
描述
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.
- 主要語言
- Java
- 星號
- 3.7k
- 分支
- 605
- 平均合併
- 12 天 22 小時
- 30 天內合併 PR
- 10
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
springdoc/springdoc-openapi 的其他 Issue
-
`ConcurrentModificationException` in `SchemaPropertyDeprecatingConverter.isDeprecated`, and `DEPRECATED_ANNOTATIONS` gains a duplicate on every context start可能已有人在做 @awinishere 於 3 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 85/100
springdoc/springdoc-openapi#3400 ·
維護者通常 14 天內回覆
-
難度 3/5 1-2 天 新手友好度 66/100
springdoc/springdoc-openapi#3399 · 1 則留言 ·
維護者通常 14 天內回覆
-
難度 4/5 3-5 天 新手友好度 57/100
springdoc/springdoc-openapi#3398 ·
維護者通常 14 天內回覆
-
Subtype loses allOf reference to its polymorphic parent since 3.2.0 when a controller repeats the interface's @Valid on a @RequestBody可能已有人在做 @jochenberger 於 8 天前認領。 未關閉
難度 4/5 3-5 天 新手友好度 30/100
springdoc/springdoc-openapi#3393 ·
維護者通常 14 天內回覆
-
難度 3/5 1-2 天 新手友好度 54/100
springdoc/springdoc-openapi#3374 · 2 則留言 ·
維護者通常 14 天內回覆
查看 springdoc/springdoc-openapi 的全部 Issue
相似的 Issue
-
bug
難度 2/5 1-3 小時 新手友好度 78/100
apache/maven-enforcer#1074 ·
維護者通常 1 天內回覆
-
Gradle liquibaseDiffChangelog drops jhi_date_time_wrapper可能已有人在做 @mraible 今天認領。 未關閉area: triage theme: undefined
難度 2/5 1-3 小時 新手友好度 88/100
jhipster/generator-jhipster#35998 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
openai/openai-java#1337 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 75/100
checkstyle/checkstyle#22447 ·
維護者通常 1 天內回覆