Description
Describe the bug
When I create 2 entities A and B with a relation from A to B, the generated api doc describes the relation as B being embedded in A instead of modelling an href to another entity.
To Reproduce
Spring Boot: 2.4.3
Springdoc: 1.5.5
public class Pet {
...
@ManyToOne
private Owner owner;
}
public class Owner {
...
}
public interface PetRepo extends JpaRepository<Pet, UUID> {
}
public interface OwnerRepo extends JpaRepository<Owner, UUID> {
}
The generated api doc for GET /pets/{id}
/pets/{id}:
get:
tags:
- pet-entity-controller
description: get-pet
operationId: getItemResource-pet-get
parameters:
- name: id
in: path
required: true
schema:
type: string
responses:
"200":
description: OK
content:
application/hal+json:
schema:
$ref: '#/components/schemas/EntityModelPet'
"404":
description: Not Found
...
EntityModelPet:
type: object
properties:
id:
type: string
format: uuid
name:
type: string
owner:
$ref: '#/components/schemas/Owner'
_links:
$ref: '#/components/schemas/Links'
The owner
property is not part of the response body of the GET
call but it is a link in the _links
section.
For the POST
call, we get
post:
tags:
- pet-entity-controller
description: create-pet
operationId: postCollectionResource-pet-post
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
responses:
"201":
description: Created
content:
application/hal+json:
schema:
$ref: '#/components/schemas/EntityModelPet'
...
Pet:
required:
- name
type: object
properties:
id:
type: string
format: uuid
name:
type: string
owner:
$ref: '#/components/schemas/Owner'
In this case, the owner
property should be a String, not an Owner
.
Expected behavior
In the GET
-case, the model should not include any properties that are relations
In the POST
-case the owner
property should be a string, since the entity is references via href.
Current Workaround
I found a workaround by adding @Schema(implementation = String.class, accessMode = AccessMode.WRITE_ONLY)
to the relation property in the data model as follows, but I think the springdoc should do it right out of the box.
public class Pet {
...
@ManyToOne
@Schema(implementation = String.class, accessMode = AccessMode.WRITE_ONLY)
private Owner owner;
}