[Spring-java] required readonly attribute generate not null field
Created by: esoni88
Hi All, regard required, readOnly and writeOnly open api specification report:
If a readOnly or writeOnly property is included in the required list, required affects just the relevant scope – responses only or requests only. That is, read-only required properties apply to responses only, and write-only required properties – to requests only.
so if i declare a field required and read-only means that in the request that field should be empty.
example with this yam:
Poll:
title: Poll
type: object
description: A poll is an election, or a survey of people's opinions to ask inside the platform
properties:
id:
type: integer
format: int64
readOnly: true
description: Unique Identifier of a Poll
openapigenerator generate the class with id not null
@JsonProperty("id") private Long id;
@NotNull public Long getId() { return id; }
public void setId(Long id) { this.id = id; }
What happen if i run my code and i perform a post with an empty id ? Spring raise bad request but it is not correct. For openapi specification read-only required properties apply to responses only and not for the request. I think that openapi generator should generate @NotNull only for writeOnly property