/** * Return a default, frozen configuration * * @return a new configuration */ public static ValidationConfiguration byDefault() { return newBuilder().freeze(); }
/** * A builder with the default configuration * * @see JsonSchemaFactory#newBuilder() */ JsonSchemaFactoryBuilder() { reportProvider = new ListReportProvider(LogLevel.INFO, LogLevel.FATAL); loadingCfg = LoadingConfiguration.byDefault(); validationCfg = ValidationConfiguration.byDefault(); }
/** * Constructor * * @param cfg the validation configuration to use */ public SyntaxValidator(final ValidationConfiguration cfg) { final MessageBundle syntaxMessages = cfg.getSyntaxMessages(); final ProcessorMap<JsonRef, ValueHolder<SchemaTree>, ValueHolder<SchemaTree>> map = new ProcessorMap<JsonRef, ValueHolder<SchemaTree>, ValueHolder<SchemaTree>>(FUNCTION); Dictionary<SyntaxChecker> dict; dict = cfg.getDefaultLibrary().getSyntaxCheckers(); final SyntaxProcessor byDefault = new SyntaxProcessor( cfg.getSyntaxMessages(), dict); map.setDefaultProcessor(byDefault); final Map<JsonRef,Library> libraries = cfg.getLibraries(); JsonRef ref; SyntaxProcessor syntaxProcessor; for (final Map.Entry<JsonRef, Library> entry: libraries.entrySet()) { ref = entry.getKey(); dict = entry.getValue().getSyntaxCheckers(); syntaxProcessor = new SyntaxProcessor(syntaxMessages, dict); map.addEntry(ref, syntaxProcessor); } processor = map.getProcessor(); }
public ValidationProcessor(final ValidationConfiguration cfg, final Processor<SchemaContext, ValidatorList> processor) { syntaxMessages = cfg.getSyntaxMessages(); validationMessages = cfg.getValidationMessages(); this.processor = processor; }
@Test public void defaultLibraryIsDraftV4() { final ValidationConfiguration defaultConfiguration = ValidationConfiguration.byDefault(); assertSame(defaultConfiguration.getDefaultLibrary(), DraftV4Library.get()); }
private Processor<SchemaContext, ValidatorList> buildProcessor() { final RefResolver resolver = new RefResolver(loader); final Map<JsonRef, Library> libraries = validationCfg.getLibraries(); final Library defaultLibrary = validationCfg.getDefaultLibrary(); final ValidationChain defaultChain = new ValidationChain(resolver, defaultLibrary, validationCfg); final ProcessorMap<JsonRef, SchemaContext, ValidatorList> map = new ProcessorMap<JsonRef, SchemaContext, ValidatorList>(FUNCTION); map.setDefaultProcessor(defaultChain); JsonRef ref; ValidationChain chain; for (final Map.Entry<JsonRef, Library> entry: libraries.entrySet()) { ref = entry.getKey(); chain = new ValidationChain(resolver, entry.getValue(), validationCfg); map.addEntry(ref, chain); } final Processor<SchemaContext, ValidatorList> processor = map.getProcessor(); return new CachingProcessor<SchemaContext, ValidatorList>(processor, SchemaContextEquivalence.getInstance(), validationCfg.getCacheSize()); } }
public ValidationChain(final RefResolver refResolver, final Library library, final ValidationConfiguration cfg) { final SyntaxProcessor syntaxProcessor = new SyntaxProcessor( cfg.getSyntaxMessages(), library.getSyntaxCheckers()); final ProcessorChain<ValueHolder<SchemaTree>, ValueHolder<SchemaTree>> chain1 = ProcessorChain.startWith(refResolver).chainWith(syntaxProcessor); resolver = new CachingProcessor<ValueHolder<SchemaTree>, ValueHolder<SchemaTree>>( chain1.getProcessor(), SchemaHolderEquivalence.INSTANCE, cfg.getCacheSize() ); final SchemaDigester digester = new SchemaDigester(library); final ValidatorBuilder keywordBuilder = new ValidatorBuilder(library); ProcessorChain<SchemaContext, ValidatorList> chain2 = ProcessorChain.startWith(digester).chainWith(keywordBuilder); if (cfg.getUseFormat()) { final FormatProcessor format = new FormatProcessor(library, cfg); chain2 = chain2.chainWith(format); } builder = new CachingProcessor<SchemaContext, ValidatorList>( chain2.getProcessor(), SchemaContextEquivalence.getInstance(), cfg.getCacheSize() ); }
@Test public void defaultLibraryIsAccountedFor() { final String ref = "x://y.z/schema#"; final Library library = Library.newBuilder().freeze(); cfg.setDefaultLibrary(ref, library); assertSame(cfg.freeze().getDefaultLibrary(), library); } }
/** * Return a frozen version of this configuration * * @return a {@link ValidationConfiguration} * @see ValidationConfiguration#ValidationConfiguration(ValidationConfigurationBuilder) */ @Override public ValidationConfiguration freeze() { return new ValidationConfiguration(this); } }
@BeforeMethod public void initConfiguration() { cfg = ValidationConfiguration.newBuilder(); }
protected TestSuite(final SchemaVersion version, final String fileName) throws IOException { final ValidationConfiguration cfg = ValidationConfiguration.newBuilder() .setDefaultVersion(version).freeze(); validator = JsonSchemaFactory.newBuilder() .setValidationConfiguration(cfg).freeze().getValidator(); testSuite = JsonLoader.fromResource("/testsuite/" + fileName + ".json"); }
@BeforeMethod public void init() { final Keyword keyword = Keyword.newBuilder(K1) .withSyntaxChecker(mock(SyntaxChecker.class)) .withIdentityDigester(NodeType.ARRAY, NodeType.values()) .withValidatorClass(K1Validator.class) .freeze(); final Library library = DraftV4Library.get().thaw() .addKeyword(keyword).freeze(); final ValidationConfiguration cfg = ValidationConfiguration.newBuilder() .setDefaultLibrary("foo://bar#", library).freeze(); final JsonSchemaFactory factory = JsonSchemaFactory.newBuilder() .setValidationConfiguration(cfg).freeze(); processor = factory.getProcessor(); COUNT.set(0); }
final ValidationConfiguration cfg = ValidationConfiguration.newBuilder() .setDefaultLibrary("http://my.site/myschema#", library) .setValidationMessages(bundle).freeze();
final ValidationConfiguration cfg = ValidationConfiguration.newBuilder() .setDefaultLibrary("http://my.site/myschema#", library) .setValidationMessages(bundle).freeze();
/** * @return A {@link JsonSchemaFactory} instance configured with the OpenAPI / Swagger V20 metaschema library suitable * for use in validating OpenAPI / Swagger documents */ public static JsonSchemaFactory schemaFactory() { return JsonSchemaFactory .newBuilder() .setValidationConfiguration( ValidationConfiguration.newBuilder() .setDefaultLibrary(OAI_V2_METASCHEMA_URI, SwaggerV20Library.get()) .setSyntaxMessages(getBundle(SwaggerV20Library.SyntaxBundle.class)) .setValidationMessages(getBundle(SwaggerV20Library.ValidationBundle.class)) .freeze()) .setReportProvider( // Only emit ERROR and above from the JSON schema validation new ListReportProvider(LogLevel.ERROR, LogLevel.FATAL)) .freeze(); }
/** * @param logLevel log level * @param exceptionThreshold exception threshold * @return A {@link JsonSchemaFactory} instance configured with the OpenAPI / Swagger V20 metaschema library suitable * for use in validating OpenAPI / Swagger documents */ public static JsonSchemaFactory schemaFactory(final LogLevel logLevel, final LogLevel exceptionThreshold) { return JsonSchemaFactory .newBuilder() .setValidationConfiguration( ValidationConfiguration.newBuilder() .setDefaultLibrary(OAI_V2_METASCHEMA_URI, SwaggerV20Library.get()) .setSyntaxMessages(getBundle(SwaggerV20Library.SyntaxBundle.class)) .setValidationMessages(getBundle(SwaggerV20Library.ValidationBundle.class)) .freeze()) .setReportProvider( // Only emit ERROR and above from the JSON schema validation new ListReportProvider(logLevel, exceptionThreshold)) .freeze(); }
/** * @param logLevel log level * @param exceptionThreshold exception threshold * @return A {@link JsonSchemaFactory} instance configured with the OpenAPI / Swagger V20 metaschema library suitable * for use in validating OpenAPI / Swagger documents */ static JsonSchemaFactory schemaFactory(final LogLevel logLevel, final LogLevel exceptionThreshold) { return JsonSchemaFactory .newBuilder() .setValidationConfiguration( ValidationConfiguration.newBuilder() .setDefaultLibrary(OAI_V2_METASCHEMA_URI, SwaggerV20Library.get()) .setSyntaxMessages(getBundle(SwaggerV20Library.SyntaxBundle.class)) .setValidationMessages(getBundle(SwaggerV20Library.ValidationBundle.class)) .freeze()) .setReportProvider( // Only emit ERROR and above from the JSON schema validation new ListReportProvider(logLevel, exceptionThreshold)) .freeze(); }