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
{{ message }}
Repository navigation
Determining whether a property is required/mandatory #1568
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:
changed the title [-]Bug when determining whether a property is required/mandatory[/-][+]Determining whether a property is required/mandatory[/+]on 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 🙏
Reacted by Przemysław Grzonka, Matthew Daumen and Patrick Gross
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.
Activity
bnasslahsen commentedon Mar 22, 2022
@evantoli,
Duplicate of #1374 and #1486
There is no plan to support groups.
Feel free to propose a PR for it and we will review it.
[-]Bug when determining whether a property is required/mandatory[/-][+]Determining whether a property is required/mandatory[/+]evantoli commentedon Mar 23, 2022
Hi @bnasslahsen,
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.adocfile.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 🙏
JamesPace-Carta commentedon Oct 21, 2022
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.
ML-Marco commentedon Nov 14, 2024
Here is a workaround for this issue. It doesn't look like as if the Swagger project is actively maintained any more.
I know it's ugly but better than nothing: