I have a class
public abstract class Transfer<ID_TYPE> {
protected ID_TYPE id;
protected BigDecimal amount;
protected String text;
protected Debitor debit;
protected Creditor credit;
}
public class Debitor {
private Reference<String, String> number;
private Integer property;
}
public class Reference<T, U> {
T reference;
U value;
}
I have a RestController
with POST
public ResponseEntity<Transfer> post(@RequestBody Transfer transfer,
@RequestHeader HttpHeaders headers) {
// do something
}
What I need to do, is to override the schema of my requestbody in the open api definition to hides some fields (only for post method)
{
debit: {
number: {
reference: 'value' // Reference.value is hidden
}
}
}
I cannot change the signature of my POST endpoint and cannot a create DTO to only expose required fields.
What I tried to do so far :
Annotate my fields with
@Schema
that should not be displayed in swagger with a READ ONLY access mode => This solution is not good because it number.reference.value might be mandatory for other post method.Try to add @RequestBody
@io.swagger.v3.oas.annotations.parameters.RequestBody(content = {
@Content(schema = @Schema(name = "number", type = "integer", required = true)) })
But when I use this annotation, the property' name is not displayed and I don't know how to handle nested properties.
Is there a way to do that ? Can we create a custom open api yaml file that would override the default one only on few endpoints ?
Thanks for your help