Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mathias-ewald opened this issue Feb 19, 2021 · 0 comments
Closed
Labels
bug Something isn't working

Comments

@mathias-ewald
Copy link

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.

This was referenced Mar 16, 2021
@bnasslahsen bnasslahsen added the bug Something isn't working label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants