Skip to content

Commit

Permalink
NotNull annotation added for required field (even when the field has …
Browse files Browse the repository at this point in the history
…no other constraint).
  • Loading branch information
michalkolenda committed Sep 26, 2024
1 parent 246fa51 commit 4fc6c6d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class {m.classname} {#if m.parent}extends {m.parent}{/if}{#if m.serializa
* {v.description}
**/
{/if}
{#if v.hasValidation}{#include beanValidation.qute p=v/}{/if}
{#if v.hasValidation || v.required}{#include beanValidation.qute p=v/}{/if}
{#if v.isContainer}
private {v.datatypeWithEnum} {v.name}{#if v.required && v.defaultValue} = {v.defaultValue}{/if};
{#else}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ components:
required:
- id
- name
- secondName
- size
properties:
id:
Expand All @@ -58,6 +59,8 @@ components:
pattern: "[a-zA-Z]*"
minLength: 1
maxLength: 10
secondName:
type: string
size:
type: number
minimum: 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.stream.Stream;

import jakarta.validation.Valid;
import jakarta.validation.constraints.DecimalMax;
Expand Down Expand Up @@ -43,9 +44,10 @@ void testValidationAnnotationsAreInPlaceApi() {
void testValidationAnnotationsAreInPlaceModel() throws Exception {
Field id = ValidatedObject.class.getDeclaredField("id");
Field name = ValidatedObject.class.getDeclaredField("name");
Field secondName = ValidatedObject.class.getDeclaredField("secondName");
Field size = ValidatedObject.class.getDeclaredField("size");

assertThat(Arrays.stream(ValidatedObject.class.getFields())
assertThat(Stream.of(id, name, secondName, size)
.allMatch(f -> f.isAnnotationPresent(NotNull.class)))
.isTrue();

Expand Down

0 comments on commit 4fc6c6d

Please sign in to comment.