question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[java-gen] Support Min/Max/Pattern javax.validation.constraints

See original GitHub issue

Is your enhancement related to a problem? Please describe

I noticed that required fields get a @NotNull annotation applied, but there are other supported validation patterns that can be applied to generated Java models as well

https://javaee.github.io/tutorial/bean-validation002.html

Describe the solution you’d like

Examples

https://github.com/fabric8io/kubernetes-client/blob/1d7d869681faafe166e5581bcde0f928499ef765/java-generator/core/src/test/resources/akka-microservices-crd.yml#L48-L49

Mapped to

@Min(0)
@Max(1000)

https://github.com/fabric8io/kubernetes-client/blob/1d7d869681faafe166e5581bcde0f928499ef765/java-generator/core/src/test/resources/akka-microservices-crd.yml#L75-L76

Mapped to

@Pattern(...)

Describe alternatives you’ve considered

Manually adding these where they would be needed.

Additional context

The objects will fail to be constructed if an invalid value is provided when the annotations are present.

Use-case: Preventing bad user-provided input fields into an API layer.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:25 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
OneCricketeercommented, Sep 8, 2022
1reaction
leoandrea7commented, Jun 22, 2022

@andreaTP new issue opened

Read more comments on GitHub >

github_iconTop Results From Across the Web

21.1 Using Bean Validation Constraints
Constraints can be built in or user defined. User-defined constraints are called custom constraints. Several built-in constraints are available in the javax.
Read more >
Package javax.validation.constraints - Java EE
Defines several DecimalMin annotations on the same element. Digits. The annotated element must be a number within accepted range Supported types are: BigDecimal ......
Read more >
Java Bean Validation Basics - Baeldung
Learn how to validate domain objects in Spring Boot using Hibernate Validator, the reference implementation of the Bean Validation framework.
Read more >
java - Why do bean validation Min/Max constraints not support ...
Use the @DecimalMin annotation. You will need to pass a literal String value, because the attrubute value must be constant (String.
Read more >
Bean validation built-in constraints - IBM
The Bean Validation API is supported by constraints that are primarily ... are available in the javax.validation.constraints package.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found