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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Support for @Positive #3001

wants to merge 4 commits into from

Conversation

mpleine
Copy link

@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.

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.

3 participants