Skip to content

Spring Data Rest: No model for Paged Collection #1083

Closed
@mathias-ewald

Description

@mathias-ewald

Describe the bug
When I extend JpaRepository or PagingAndSortingRepository, the collection model returned in a GET to the endpoint contains pagination data in addition to the collection of entity models. Instead a CollectionModelEntityModel* is referenced as the schema which does not include the pagination data.

To Reproduce
Spring Boot: 2.4.3
Springdoc: 1.5.5

@Entity
@Data
...
public class Pet extends BaseEntity {
	...
}

public interface PetRepo extends JpaRepository<Pet, UUID> {}
  /pets:
    get:
      ...
      responses:
        "200":
          description: OK
          content:
            application/hal+json:
              schema:
                $ref: '#/components/schemas/CollectionModelEntityModelPet'
            application/x-spring-data-compact+json:
              schema:
                $ref: '#/components/schemas/CollectionModelEntityModelPet'
            text/uri-list:
              schema:
                $ref: '#/components/schemas/CollectionModelEntityModelPet'
...
    CollectionModelEntityModelPet:
      type: object
      properties:
        _embedded:
          type: object
          properties:
            pets:
              type: array
              items:
                $ref: '#/components/schemas/EntityModelPet'
        _links:
          $ref: '#/components/schemas/Links'

Expected behavior
A PagedCollectionModelEntityModelPet should be generated that matches the following schema

{
  "_embedded" : {
    "pets" : [ ... ]
  },
  "_links" : {
    ...
  },
  "page" : {
    "size" : 20,
    "totalElements" : 8,
    "totalPages" : 1,
    "number" : 0
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions