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
JSON properties are incorrectly specified as required if they have been annotated with both @Null and any of @NotNull, @NotEmpty and @NotBlank.
This situation occurs when using Java constraint validation groups along with Spring to set the validation groups to constrain whether a property is required or not for certain scenarios.
For example, when a client must supply some value on create but is not permitted to change that value later on update.
To Reproduce
Using:
spring-boot-dependencies 2.5.4
springdoc-openapi-ui 1.6.6
For example, in a model class declare properties with annotations like:
publicclassSomeModel {
@Null(
groups = GroupA.class,
message = "Must not be provided in scenario A")
@NotBlank(
groups = GroupB.class,
message = "Must be provided in scenario B")
@Schema(
description = """ Some description of this property. Notes: - Must not be provided in scenario A - Must be provided in scenario B""",
required = false)
privateStringsomeProperty;
...
For the above code, SpringDoc will generate an OpenAPI spec with something like the following:
bnasslahsen
changed the title
Bug when determining whether a property is required/mandatory
Determining whether a property is required/mandatory
Mar 22, 2022
I have a PR that I can submit. What is the process?
I don't have permission to push my branch and I can't see any advice in the process in the CONTRIBUTING.adoc file.
BTW, I fully appreciate that you're not going to support validation groups. And my ticket isn't really about validation groups.
My desired behaviour is that the set of require properties should not contain any properties that may have contradictory validation annotations associated with them. Perhaps I didn't quite make that as clear as I could have.
Also, thanks so much for responding to this ticket so quickly. Much appreciated 🙏
Is it possible to disable the handling of the validation annotations?
We have a lot of code that uses groups and the swagger output it currently generates is incorrect. I can't seem to be able to provide an inline schema for the request, so I'm pretty much stuck.
Feature Description
JSON properties are incorrectly specified as required if they have been annotated with both
@Null
and any of@NotNull
,@NotEmpty
and@NotBlank
.This situation occurs when using Java constraint validation groups along with Spring to set the validation groups to constrain whether a property is required or not for certain scenarios.
For example, when a client must supply some value on create but is not permitted to change that value later on update.
To Reproduce
Using:
For example, in a model class declare properties with annotations like:
For the above code, SpringDoc will generate an OpenAPI spec with something like the following:
Expected behaviour
Do not specify that a JSON property is required if it has been annotated with both
@Null
and any of@NotNull
,@NotEmpty
and@NotBlank
.The text was updated successfully, but these errors were encountered: