Skip to content

Spring Data Rest: Collection models generated with non-HAL content #1070

Closed
@mathias-ewald

Description

@mathias-ewald

Describe the bug
The the api-docs CollectionModels are generally rendered as containing non-HAL enities while Spring Data Rest returns entities in HAL format.

To Reproduce

  • Spring Boot 2.4.3
  • Springdocs 1.5.4 (springdoc-openapi-ui, springdoc-openapi-data-rest)

Example Entity

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Builder
public class Clinic extends BaseEntity {
	@NotNull
	@NotBlank
	private String name;

	@ElementCollection
	@Size(min = 1)
	private Set<Address> addresses;
}

Example Repo

public interface ClinicRepo extends CrudRepository<Clinic, UUID> {
}

Generated api-doc for GET /clinics:

...
paths:
  /clinics:
    get:
      tags:
      - clinic
      description: get-clinic
      operationId: getCollectionResource-clinic-get_1
      responses:
        "200":
          description: OK
          content:
            application/hal+json:
              schema:
                $ref: '#/components/schemas/CollectionModelClinic'
            application/x-spring-data-compact+json:
              schema:
                $ref: '#/components/schemas/CollectionModelClinic'
            text/uri-list:
              schema:
                $ref: '#/components/schemas/CollectionModelClinic'
...
components:
  schemas:
    CollectionModelClinic:
      type: object
      properties:
        _embedded:
          type: object
          properties:
            clinics:
              type: array
              items:
                $ref: '#/components/schemas/Clinic'
        _links:
          $ref: '#/components/schemas/Links'
    Clinic:
      required:
      - name
      type: object
      properties:
        name:
          type: string
        addresses:
          maxItems: 2147483647
          minItems: 1
          uniqueItems: true
          type: array
          items:
            $ref: '#/components/schemas/Address'

CollectionModelClinic has an array of Clinic (which mentions to _links property, for example) but Spring Data Rest returns:

{
  "_embedded" : {
    "clinics" : [ {
      "name" : "Animal Hospital Vienna Meidling",
      "addresses" : [ {
        "street" : "Längenfeldgasse",
        "number" : "16",
        "zipcode" : "1120",
        "city" : "Wien",
        "country" : "Austria"
      } ],
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/clinics/b98089ac-769f-42fa-84c1-a2106fa6cf3a"
        },
        "clinic" : {
          "href" : "http://localhost:8081/clinics/b98089ac-769f-42fa-84c1-a2106fa6cf3a"
        }
      }
    }, {
      "name" : "Animal Clinic & Animal Healing Center Aspern",
      "addresses" : [ {
        "street" : "Aspernstraße",
        "number" : "130",
        "zipcode" : "1120",
        "city" : "Wien",
        "country" : "Austria"
      } ],
      "_links" : {
        "self" : {
          "href" : "http://localhost:8081/clinics/b2bdd818-8758-4b42-8537-5bc2108e2027"
        },
        "clinic" : {
          "href" : "http://localhost:8081/clinics/b2bdd818-8758-4b42-8537-5bc2108e2027"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8081/clinics"
    },
    "profile" : {
      "href" : "http://localhost:8081/profile/clinics"
    }
  }
}

Expected behavior
I would expect the api-doc to generate a response schema that matches the response returned by Spring Data Rest including the _links property.

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