Open Nephery opened 2 months ago
Hi @Nephery,
Yeah, that's the downside of the Swagger annotation providing everything as String
values.
We could add extra smarts to cover some straightforward scenarios such as this one, but to be honest, I'd expect something like the jakarta @AssertTrue
validation annotation to be present in this case, which allows enforcement and can be picked up without having to parse a String
.
I'm open to a PR though, if you deem it worthwhile.
I fully agree, that the schema currently being generated there is invalid. The issue can be avoided by not using the @Schema(allowableValues = "true")
in such a case and/or a fix is required here.
That's fair.
I raised #456 to add support for Jakarta @AssertTrue
and @AssertFalse
.
Maybe I'll come back around in the future to try and raise a PR to add some support for primitive types in @Schema(allowableValues = "true")
. But adding support for Jakarta @AssertTrue
and @AssertFalse
does actually solve my immediate issue. So that's good enough for me for now. 🙂
The support for the Jakarta @AssertTrue
/@AssertFalse
annotations has been released in v4.36.0.
I'm leaving this issue open for now, as the original topic (Swagger annotations) has not yet been resolved.
For the following Swagger 2 module properties:
The outputted JSON always treats them as Strings, and does not consider the actual type of the property.
For example, if I have the following:
This would produce a schema like:
Instead of
"const" : "true"
, I would have expected this to be"const" : true
(i.e. not a String value). The same happens for any other primitive types.