You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project with Swagger 3, I noticed a different behavior compared to Swagger 2 and I think it's a bug because with a structure of a certain type, I can make the call to the API, but Swagger doesn't allow me to do it.
@Data
public class ClassOne {
@Valid
private ClassTwo description;
}
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ClassTwo {
@NotNull
private String name;
}
As you can see, ClassOne has an object with the @Valid annotation and I am not obliged to pass it (because maybe I want to pass other attributes that I have not added in this example). However, the @Valid annotation ensures that if I pass any attribute that is inside that class, then it must respect the rules that I indicate inside (@NotNull etc.). The problem is that on the swagger it says required, even if I do not indicate required and therefore I cannot make the call to the API. This is therefore a problem as I said before, because I may want to send other attributes of ClassOne.
This problem occurs only in the case of @PraameterObject, while if I use @RequestBody, it is not mandatory.
In my opinion swagger should not automatically add requird if an attribute has the annotation @NotNull or @NotBlank, it should refer to what the user indicates with the annotation @Schema
The text was updated successfully, but these errors were encountered:
lako12
changed the title
Aggiunge in automatico required se un campo è @notNull oppure @NotBlank
Automatically add required if a field is @notNull or @NotBlank
Dec 17, 2024
I have a project with Swagger 3, I noticed a different behavior compared to Swagger 2 and I think it's a bug because with a structure of a certain type, I can make the call to the API, but Swagger doesn't allow me to do it.
I have this API:
As you can see,
ClassOne
has an object with the@Valid
annotation and I am not obliged to pass it (because maybe I want to pass other attributes that I have not added in this example). However, the@Valid
annotation ensures that if I pass any attribute that is inside that class, then it must respect the rules that I indicate inside (@NotNull etc.). The problem is that on the swagger it says required, even if I do not indicate required and therefore I cannot make the call to the API. This is therefore a problem as I said before, because I may want to send other attributes ofClassOne
.This problem occurs only in the case of
@PraameterObject
, while if I use@RequestBody
, it is not mandatory.In my opinion swagger should not automatically add requird if an attribute has the annotation
@NotNull
or@NotBlank
, it should refer to what the user indicates with the annotation @Schemaattached is a zip with an example.
demo.zip
The text was updated successfully, but these errors were encountered: