-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: validate INT input with min/max
- Loading branch information
1 parent
3f0e863
commit b276525
Showing
5 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
33 changes: 32 additions & 1 deletion
33
core/src/main/java/io/kestra/core/models/flows/input/IntInput.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,49 @@ | ||
package io.kestra.core.models.flows.input; | ||
|
||
import io.kestra.core.models.flows.Input; | ||
import io.kestra.core.models.validations.ManualConstraintViolation; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.util.Set; | ||
import java.util.regex.Pattern; | ||
import javax.validation.ConstraintViolationException; | ||
|
||
@SuperBuilder | ||
@Getter | ||
@NoArgsConstructor | ||
public class IntInput extends Input<Integer> { | ||
|
||
@Schema(title = "Minimal value.") | ||
Integer min; | ||
|
||
@Schema(title = "Maximal value.") | ||
Integer max; | ||
|
||
@Override | ||
public void validate(Integer input) throws ConstraintViolationException { | ||
// no validation yet | ||
if (min != null && input.compareTo(min) < 0) { | ||
throw new ConstraintViolationException("Invalid input '" + input + "', it must be more than '" + min + "'", | ||
Set.of(ManualConstraintViolation.of( | ||
"Invalid input", | ||
this, | ||
IntInput.class, | ||
getName(), | ||
input | ||
))); | ||
} | ||
|
||
if (max != null && input.compareTo(max) > 0) { | ||
throw new ConstraintViolationException("Invalid input '" + input + "', it must be less than '" + max + "'", | ||
Set.of(ManualConstraintViolation.of( | ||
"Invalid input", | ||
this, | ||
IntInput.class, | ||
getName(), | ||
input | ||
))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters