spring-cloud-gateway
spring-cloud-gateway copied to clipboard
Add @NotNull to BeforeRoutePredicateFactory.Config. datetime
Question & Enhancement
-
I compared
AfterRoutePredicateFactoryandBeforeRoutePredicateFactoryare quite similar but is diffrent about@NotNull. If there no reason I think should add@NotNulltoBeforeRoutePredicateFactory.Config.datetime -
I don't realy know about
@Validatedanotation works in predicates. I try few test with or without@Validatedbut it have no given. Could you remove@Validatedin every predicates If there are no reason to apply@Validated? Because it require me to understanding@Validatedwhen I make custom predicate.
It happens when configuration is bound from properties, similar to how it works in spring boot @ConfigurationProperties, it uses the same mechanism, so supporting constraints and @Validated.
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
@spencergibb @spencergibb I still don’t fully understand the use of @Validated in PredicateFactory.Config, but I believe it might not be crucial to this issue.
I looked three classes within the PredicateFactory.
public class HeaderRoutePredicateFactory extends AbstractRoutePredicateFactory<HeaderRoutePredicateFactory.Config> {
@Validated
public static class Config {
@NotEmpty
private String header;
}
In HeaderRoutePredicateFactory, the header field is validated to ensure it is not empty.
public class AfterRoutePredicateFactory extends AbstractRoutePredicateFactory<AfterRoutePredicateFactory.Config> {
public static class Config {
@NotNull
private ZonedDateTime datetime;
}
}
Similarly, in AfterRoutePredicateFactory, the datetime field is checked for null values, but @Validated is not used here.
public class BeforeRoutePredicateFactory extends AbstractRoutePredicateFactory<BeforeRoutePredicateFactory.Config> {
public static class Config {
private ZonedDateTime datetime;
}
}
BeforeRoutePredicateFactory is quite similar to AfterRoutePredicateFactory, but it’s missing the @NotNull annotation on the datetime field. It seems necessary to include this validation, as BeforeRoutePredicateFactory doesn’t currently check if the datetime field is null.
Yup, it's inconsistent. PRs welcome.
Closed via #3583