Skip to content

Commit 2958b17

Browse files
committed
fix validation in data class: the validation annotations should have @field: prefix
1 parent e5d5588 commit 2958b17

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/main/kotlin/ch/derlin/bbdata/input/NewValue.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ import javax.validation.constraints.Size
1717

1818
data class NewValue(
1919

20-
@NotNull
21-
@Min(value = 0, message = "objectId must be positive.")
20+
@field:NotNull
21+
@field:Min(value = 0, message = "objectId must be positive.")
2222
val objectId: Long? = null,
2323

24-
@NotNull
25-
@Size(min = 32, max = 32, message = "wrong size: should be 32 chars long.")
24+
@field:NotNull
25+
@field:Size(min = 32, max = 32, message = "wrong size: should be 32 chars long.")
2626
val token: String? = null,
2727

2828
//@NotNull(message = "Invalid date. Format: YYYY-MM-ddTHH:mm[:ss], range: 2016-01-01T00:00 to 2050-01-01T00:00")
2929
val timestamp: DateTime? = null,
3030

31-
@NotNull
32-
@NotEmpty
31+
@field:NotNull
32+
@field:NotEmpty
3333
var value: String? = null,
3434

35-
@Size(max = 1024, message = "too long. Maximum set to 1024.")
35+
@field:Size(max = 1024, message = "too long. Maximum set to 1024.")
3636
val comment: String? = null
3737
) {
3838

src/main/kotlin/ch/derlin/bbdata/output/api/objects/ObjectsTokenController.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,17 @@ import io.swagger.v3.oas.annotations.Operation
1414
import io.swagger.v3.oas.annotations.tags.Tag
1515
import org.springframework.cache.CacheManager
1616
import org.springframework.http.ResponseEntity
17+
import org.springframework.validation.annotation.Validated
1718
import org.springframework.web.bind.annotation.*
1819
import javax.validation.Valid
20+
import javax.validation.constraints.Min
1921
import javax.validation.constraints.Size
2022

2123
/**
2224
* date: 23.12.19
2325
* @author Lucy Linder <lucy.derlin@gmail.com>
2426
*/
25-
27+
@Validated
2628
@RestController
2729
@RequestMapping("/objects")
2830
@Tag(name = "Objects Tokens", description = "Manage object tokens")
@@ -32,10 +34,11 @@ class ObjectsTokenController(private val objectsAccessManager: ObjectsAccessMana
3234

3335

3436
data class BulkTokenBody(
35-
@NotNull
37+
@field:javax.validation.constraints.NotNull
38+
@field:Min(value = 0, message = "objectId must be positive.")
3639
val objectId: Long = 0,
3740

38-
@Size(max = Beans.DESCRIPTION_MAX)
41+
@field:Size(max = Beans.DESCRIPTION_MAX)
3942
val description: String? = null
4043
)
4144

@@ -82,7 +85,7 @@ class ObjectsTokenController(private val objectsAccessManager: ObjectsAccessMana
8285
@PutMapping("bulk/tokens")
8386
fun addObjectTokenBulk(
8487
@UserId userId: Int,
85-
@Valid @RequestBody tokenBodies: List<BulkTokenBody>): MutableList<Token> {
88+
@Valid @NotNull @RequestBody tokenBodies: List<@Valid BulkTokenBody>): MutableList<Token> {
8689

8790
tokenBodies.forEach {
8891
// ensure rights

0 commit comments

Comments
 (0)