Closed
Description
Describe the bug
For POST,PUT,PATCH operations, Spring Data Rest returns the entity in the response body. For a given entity A, the generated api-doc specifies RepresentationModelA
rather than EntityModelA
as the returned schema. While EntityModelA contains all properties of the entity, RepresentationModelA defines only the _links
, hence does not represent what Spring Data Rest returns.
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 {
@Id
@Type(type = "uuid-char")
@Schema(hidden = true)
private UUID id;
@NotNull
@NotBlank
private String name;
@PrePersist
private void generateId() {
if (id == null)
id = UUID.randomUUID();
}
}
Example Repository:
@CrossOrigin
public interface ClinicRepo extends CrudRepository<Clinic, UUID> {
}
Excerpt from api-docs:
...
paths:
/clinics:
...
post:
...
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Clinic'
responses:
"201":
description: Created
content:
application/hal+json:
schema:
$ref: '#/components/schemas/RepresentationModelClinic'
...
components:
schemas:
...
RepresentationModelClinic:
type: object
properties:
_links:
type: array
items:
$ref: '#/components/schemas/Link'
EntityModelClinic:
type: object
properties:
name:
type: string
addresses:
maxItems: 2147483647
minItems: 1
uniqueItems: true
type: array
items:
$ref: '#/components/schemas/Address'
_links:
type: array
items:
$ref: '#/components/schemas/Link'
...
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 schema in the api-doc should match the actual data structure returned by Spring Data Rest. It is appropriately represented by EntityModelA but not RepresentationModelA.
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
bnasslahsen commentedon Feb 25, 2021
@mathias-ewald,
Your analysis is correct.
I have added a fix for that.
You can test it using the latest snapshot.
1 remaining item