Skip to content

Latest commit

 

History

History
45 lines (41 loc) · 1.26 KB

README.md

File metadata and controls

45 lines (41 loc) · 1.26 KB

Json schema spring boot starter

Auto configuration for json-schema-validator

How to use

  1. Dependency
<dependency>
    <groupId>ru.rnemykin.spring.boot</groupId>
    <artifactId>json-schema-spring-boot-starter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
  1. Use default configuration or define your own
@Bean
public Library library(AbstractKeywordProcessor processor, ApplicationContext ctx) {
    LibraryBuilder builder = DraftV4Library.get().thaw();
    builder.addKeyword(
            Keyword.newBuilder(processor.keyword())
                    .withSyntaxChecker(...)
                    .withDigester(...)
                    .withValidatorFactory(new SpringAwareKeywordValidatorFactory(...)
                    .freeze()
    );
    return builder.freeze();
}    
  1. Write custom keywordValidators
@ToString
@Component
public class EnumDbValueKeywordProcessor extends AbstractKeywordProcessor {
   .....
}
  1. Do validation (see example)
@Autowired
private JsonSchemaFactory jsonSchemaFactory;
//...
ProcessingReport report = jsonSchemaFactory.getValidator().validate(schema, entity);