Replace nested Page with PagedModel when serialization mode is VIA_DTO - #3335
Open
jjh75607 wants to merge 1 commit into
Open
Replace nested Page with PagedModel when serialization mode is VIA_DTO#3335jjh75607 wants to merge 1 commit into
jjh75607 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3319.
Summary
With
spring.data.web.pageable.serialization-mode=VIA_DTO, aPage<T>returned directly (or insideResponseEntity) is documented asPagedModel<T>, but aPage<T>nested in another type is not:The response is
{"data": {"content": [...], "page": {...}}, ...}, while the spec documentsdataas the rawPageshape (pageable,sort,first,last, ...). The generated schema is also always namedPageObject, so two wrappers with different element types share one schema and the second element type is missing fromcomponents.schemas.PageOpenAPIConverter.resolveonly swapsPageforPagedModelwhen the type is not a schema property. For a property it keepsPageand sets a name viagetParentTypeName, which appends the parent's OpenAPI type ("object") rather than the parent class.Change
AnnotatedType'stypeto the matchingPagedModel<T>in place. The instance is kept, soctxAnnotations,jsonViewAnnotation,parentandpropertyNamestay as they were (creating a newAnnotatedTypehere drops the@JsonViewcontext from fix: propagate JsonView context when resolving Page<T> schema #3226).PagedModel<T>type computation intopagedModelType(JavaType)so both branches share it.Page<T>as response body, or insideResponseEntityPagedModelTDIRECTmode or property not setPagePage<T>as a property of another type,VIA_DTOPageObject(rawPageshape, shared name)PagedModelTOnly the last row changes.
PageObject,PageableObjectandSortObjectdisappear from such specs andPagedModelXxxtakes their place. A rawPagein that position becomesPagedModel, the same as a rawPagereturned directly.Test plan
Dummy<Page<String>>andDummy<Page<Dummy<List<String>>>>endpoints to theapp10hateoas test (v30andv31) and updated the four expected files. Without the fix theVIA_DTOvariants fail withUnexpected: PageObject, PageableObject, SortObject; theDIRECTand not-specified variants pass before and after.mvn testonspringdoc-openapi-starter-common,-webmvc-api,-webflux-api,hateoas-tests,data-rest-tests,groovy-tests— all green.Result<Page<UserInfo>>and a secondResult<Page<OtherInfo>>now getPagedModelUserInfoandPagedModelOtherInforespectively, and the documented field set matches the actual response for every endpoint.DIRECTmode produces an identical document before and after.