addValidationAnnotations

Description

If you activate this configuration toggle via the builder method withValidationAnnotations the generator scans the selected classes for the following Validation Annotations:

  • field annotations

    • javax.validation.constraints.Size

    • javax.validation.constraints.NotEmpty

    • jakarta.validation.constraints.Size

    • jakarta.validation.constraints.NotEmpty

If field annotations are found the generator will adapt the cardinality of AggregationRelationship to reflect the annotation.

This feature was previously activated via the withJavaxValidationAnnotations builder method in version between 2.3.0 and 2.4.0.

Default value

The default value of this configuration toggle is false.

Example

Here is an example from the JUnit tests using this configuration parameter:

List<String> scanPackages = new ArrayList<>();
scanPackages.add(packageUnderTest);
PlantUMLClassDiagramConfig config = new PlantUMLClassDiagramConfigBuilder(scanPackages).withValidationAnnotations(true)
        .build(); (1)
PlantUMLClassDiagramGenerator generator = new PlantUMLClassDiagramGenerator(config);
String result = generator.generateDiagramText();
String expectedDiagramText = IOUtils.toString(Objects.requireNonNull(classLoader.getResource(expectedFileName)), StandardCharsets.UTF_8);
assertNotNull(result);
assertNotNull(expectedDiagramText);
assertEquals(expectedDiagramText.replaceAll("\\s+", ""), result.replaceAll("\\s+", ""));
1 activate the validation annotations toggle in the configuration

which is rendered this way:

0028_javax_validation_annotations

and produces this PlantUML diagram text:

@startuml
class de.elnarion.test.domain.t0028.Light {
}

class de.elnarion.test.domain.t0028.Seat {
}

class de.elnarion.test.domain.t0028.Vehicle {
}

class de.elnarion.test.domain.t0028.Wheel {
}

de.elnarion.test.domain.t0028.Vehicle "1" o-- "1..*"  de.elnarion.test.domain.t0028.Light :  lights
de.elnarion.test.domain.t0028.Vehicle "1" o-- "1..10"  de.elnarion.test.domain.t0028.Seat :  seats
de.elnarion.test.domain.t0028.Vehicle "1" o-- "2..6"  de.elnarion.test.domain.t0028.Wheel :  wheels

@enduml