networknt / json-schema-validator

A fast Java JSON schema validator that supports draft V4, V6, V7, V2019-09 and V2020-12
Apache License 2.0
800 stars 320 forks source link

Add builder for `SchemaValidatorsConfig` #1068

Closed justin-tay closed 2 weeks ago

justin-tay commented 2 weeks ago

This creates a SchemaValidatorsConfig.Builder to create SchemaValidatorsConfig instances. This also updates the documentation and release notes assuming that the next release will be 1.4.1. This also updates all the tests that used the constructor to the builder.

This is was done in order to

Note that there are differences in defaults from the builder vs the constructor.

The following builder creates the same values as the constructor previously.

SchemaValidatorsConfig config = SchemaValidatorsConfig.builder()
    .pathType(PathType.LEGACY)
    .errorMessageKeyword("message")
    .nullableKeywordEnabled(true)
    .build();

The following configurations were renamed with the old ones deprecated

The following defaults were changed in the builder vs the constructor

When using the builder custom error messages are not enabled by default and must be enabled by specifying the error message keyword to use ie. "message".

Deprecated Code Replacement
SchemaValidatorsConfig config = new SchemaValidatorsConfig(); SchemaValidatorsConfig config = SchemaValidatorsConfig().builder().pathType(PathType.LEGACY).errorMessageKeyword("message").nullableKeywordEnabled(true).build();
config.setEcma262Validator(true); builder.regularExpressionFactory(JoniRegularExpressionFactory.getInstance());
config.setHandleNullableField(true); builder.nullableKeywordEnabled(true);
config.setOpenAPI3StyleDiscriminators(true); builder.discriminatorKeywordEnabled(true);
config.setCustomMessageSupported(true); builder.errorMessageKeyword("message");
stevehu commented 2 weeks ago

@justin-tay Please let me know if we should release the 1.4.1 tag. Thanks.

justin-tay commented 2 weeks ago

@stevehu Think we should release the 1.4.1 tag. Thanks!