remondis-it / pact-consumer-builder

Library for generating pact consumer expectations from java beans
Apache License 2.0
14 stars 6 forks source link

Question: DTOs with Java Validation Constraints #32

Open hansjoergkeser opened 3 years ago

hansjoergkeser commented 3 years ago

Hi there,

Am currently using your "generator" to create expected json body definitions and it already helped a lot :-) I wondered if it can handle classes/DTOs with variables, which have constraints like

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

@Max(100)
int numberMax;

@Min(10)
int numberMin;

@NotNull
String nonNullableString;

With Pact it seems I'd have to define matchers with regex, e.g. like this for a string with min length 10:

.stringMatcher("value", "^[A-Z0-9]{10,}$", "example-value-with-at-least-10-chars-or-numbers")
schuettec commented 3 years ago

Hi sorry for the late answer. Currently the processing of annotations is not supported. I don't know if Pact Builder can handle or should handle the annotation processing. Would be a piece of work to at least provide a way to reflectively inspect the field/property.