Skip to content

Add javax Positive/Negative bean validation constraint support#5052

Closed
Neo1228 wants to merge 1 commit intoswagger-api:masterfrom
Neo1228:feature/bean-validation-positive-negative
Closed

Add javax Positive/Negative bean validation constraint support#5052
Neo1228 wants to merge 1 commit intoswagger-api:masterfrom
Neo1228:feature/bean-validation-positive-negative

Conversation

@Neo1228
Copy link
Copy Markdown

@Neo1228 Neo1228 commented Feb 14, 2026

Summary

  • add support for javax.validation.constraints.Positive, Negative, PositiveOrZero, and NegativeOrZero in bean validation schema resolution
  • map these annotations to OpenAPI numeric constraints (minimum/maximum and exclusiveMinimum/exclusiveMaximum)
  • wire support in both group-aware and no-group validation flows in ModelResolver
  • add regression-safe behavior so existing stronger bounds are not loosened

Details

  • @Positive => minimum: 0, exclusiveMinimum: true
  • @Negative => maximum: 0, exclusiveMaximum: true
  • @PositiveOrZero => minimum: 0, exclusiveMinimum: false
  • @NegativeOrZero => maximum: 0, exclusiveMaximum: false

When existing bounds are already stricter (for example @Min(5) with @Positive), the stricter bound is preserved.

Tests

  • added integration test: BeanValidationTest
    • validates generated schema values for Positive/Negative/PositiveOrZero/NegativeOrZero
    • validates non-loosening behavior with stronger @Min/@Max
  • expanded unit tests: ValidationAnnotationsUtilsTest
    • added tests for all four new utility methods
    • added tests that ensure existing stricter constraints are preserved

Commands run:

  • mvn -pl modules/swagger-core "-Dtest=io.swagger.v3.core.resolving.BeanValidationTest,io.swagger.v3.core.util.ValidationAnnotationsUtilsTest" test
  • mvn test -pl modules/swagger-core

- map Positive/Negative/PositiveOrZero/NegativeOrZero to schema limits

- wire constraints in grouped and no-group bean validation flows

- add regression tests for non-loosening behavior with stronger Min/Max
@Neo1228
Copy link
Copy Markdown
Author

Neo1228 commented Feb 14, 2026

Closing as duplicate of #5044 to avoid overlap.

@Neo1228 Neo1228 closed this Feb 14, 2026
@Neo1228 Neo1228 deleted the feature/bean-validation-positive-negative branch February 14, 2026 20:03
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.

1 participant