Closed
Description
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 Clinic
s.
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.