Skip to content

Support for @Positive #3001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 8, 2025
Merged

Support for @Positive #3001

merged 4 commits into from
Jun 8, 2025

Conversation

mpleine
Copy link
Contributor

@mpleine mpleine commented May 21, 2025

Added support for @positive annotation validation constraint

When merged, the following documentation should be updated also

https://github.com/springdoc/springdoc.github.io/blob/master/src/docs/asciidoc/faq.adoc?plain=1#L192-L193
https://github.com/springdoc/springdoc.github.io/blob/master/src/docs/asciidoc/intro.adoc?plain=1#L15

Suggestion:
Maybe there could be a complete list in the documentation, which validation annotations are currently supported (and the ones that are not listed there, are currently not supported)

@@ -189,6 +190,9 @@ public static boolean fieldRequired(Field field, @Nullable io.swagger.v3.oas.ann
public static void applyValidationsToSchema(Schema<?> schema, List<Annotation> annotations) {
annotations.forEach(anno -> {
String annotationName = anno.annotationType().getSimpleName();
if (annotationName.equals(Positive.class.getSimpleName())) {
schema.setMinimum(BigDecimal.ONE);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Value BigDecimal.ONE is valid only for integers.
For decimals, for example, we can have a valid value 0.00001.

Copy link

@kdebski85 kdebski85 Jun 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the right approach is schema.setExclusiveMinimumValue(BigDecimal.ZERO);

However, according to https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-models/src/main/java/io/swagger/v3/oas/models/media/Schema.java#L441 it is supported only in OpenAPI 3.1.

@mpleine mpleine marked this pull request as draft June 8, 2025 05:55
@bnasslahsen bnasslahsen merged commit 0fcb6e3 into springdoc:main Jun 8, 2025
1 check passed
@kdebski85
Copy link

kdebski85 commented Jun 8, 2025

@bnasslahsen Any reason it was merged?
The implementation is invalid for decimal numbers. Please see my comments above.

@kdebski85
Copy link

@mpleine Are you going to prepare another PR that would fix it for decimals?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants