Skip to content

Spring Data Rest: Wrong response schema for collection relations #1069

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

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

Comments

@mathias-ewald
Copy link

Describe the bug
Schema for collection relations are wrongly detected. In the example of a Doctor entity holding a relation to a set of Clinics the api-doc returns RepresentationModelDoctor for /doctors/{id}/clinics instead of a collection model holding Clinics.

To Reproduce

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

Doctor Entity

@Data
@Entity
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
@Builder
public class Doctor extends BaseEntity {
	...
	@ManyToMany
	@Size(min = 1)
	@ArraySchema(
		schema = @Schema(
			implementation = String.class,
			accessMode = AccessMode.WRITE_ONLY
	))
	private Set<Clinic> clinics;
}

Clinic 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;
}

Doctor repository:

@CrossOrigin
public interface DoctorRepo extends CrudRepository<Doctor, UUID> {
}

Clinic Repository:

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

Generated api-doc for access to the relation:

  /doctors/{id}/clinics:
    get:
      tags:
      - doctor
      description: get-doctor
      operationId: followPropertyReference-doctor-get_1
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            application/hal+json:
              schema:
                $ref: '#/components/schemas/RepresentationModelDoctor'
            text/uri-list:
              schema:
                $ref: '#/components/schemas/RepresentationModelDoctor'
        "404":
          description: Not Found
...
components:
  schemas:
    RepresentationModelDoctor:
      type: object
      properties:
        _links:
          $ref: '#/components/schemas/Links'

Expected behavior

  • A clear and concise description of what you expected to happen.
  • What is the expected result using OpenAPI Description (yml or json)?

The response schema should be generated as a CollectionModel of the Clinic type.

@bnasslahsen
Copy link
Collaborator

Thank you for your clear description @mathias-ewald.
The fix is now available within the latest snapshot.

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