-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jooby-validation: skip double validation when filter is on lambda and…
… controller - jooby-apt: set the `io.jooby.validation.BeanValidator:true` route attribute - fix #3530
- Loading branch information
Showing
7 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3530; | ||
|
||
import jakarta.validation.constraints.NotEmpty; | ||
|
||
public class Bean3530 { | ||
@NotEmpty private String name; | ||
|
||
public @NotEmpty String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(@NotEmpty String name) { | ||
this.name = name; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3530; | ||
|
||
import io.jooby.annotation.POST; | ||
import jakarta.validation.Valid; | ||
|
||
public class Controller3530 { | ||
|
||
@POST("/3530/controller") | ||
public Bean3530 create(@Valid Bean3530 value) { | ||
return value; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.i3530; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import io.jooby.StatusCode; | ||
import io.jooby.hibernate.validator.HibernateValidatorModule; | ||
import io.jooby.jackson.JacksonModule; | ||
import io.jooby.junit.ServerTest; | ||
import io.jooby.junit.ServerTestRunner; | ||
import io.jooby.validation.BeanValidator; | ||
import io.jooby.validation.ValidationContext; | ||
import okhttp3.MediaType; | ||
import okhttp3.RequestBody; | ||
|
||
public class Issue3530 { | ||
|
||
@ServerTest | ||
public void shouldRunValidationOnce(ServerTestRunner runner) { | ||
runner | ||
.define( | ||
app -> { | ||
app.install(new JacksonModule()); | ||
app.install(new HibernateValidatorModule()); | ||
|
||
app.use(BeanValidator.validate()); | ||
|
||
app.post( | ||
"/3530/lambda", | ||
ctx -> { | ||
assertInstanceOf(ValidationContext.class, ctx); | ||
return ctx.body(Bean3530.class); | ||
}); | ||
|
||
// Must NOT be validation context: | ||
app.use( | ||
next -> | ||
ctx -> { | ||
assertFalse(ctx instanceof ValidationContext); | ||
return next.apply(ctx); | ||
}); | ||
app.mvc(new Controller3530_()); | ||
}) | ||
.ready( | ||
http -> { | ||
http.post( | ||
"/3530/lambda", | ||
RequestBody.create("{}", MediaType.parse("application/json")), | ||
rsp -> { | ||
assertEquals(StatusCode.UNPROCESSABLE_ENTITY.value(), rsp.code()); | ||
}); | ||
http.post( | ||
"/3530/controller", | ||
RequestBody.create("{}", MediaType.parse("application/json")), | ||
rsp -> { | ||
assertEquals(StatusCode.UNPROCESSABLE_ENTITY.value(), rsp.code()); | ||
}); | ||
}); | ||
} | ||
} |