0

I want to use camel json schema validator in order to validate a JSON file with a JSON schema using draft 07 .

Apache Camel uses draft 04 by default and in order to change it to draft 07 I have to use a schemaLoader of type JsonSchemaLoader according to its documentation.

How to use the schemaLoader correctly ?? I followed this solution and Apache Camel logs :

JsonSchemaException: Validation: null is an invalid segment for URI

Midovsky
  • 11
  • 2

1 Answers1

0

Here is what we are using on our Camel-3 project (and which is working fine):

public class MyFactory {

    @Produces
    @ApplicationScoped
    @Named("my-schema")
    public final JsonSchemaLoader createJsonSchemaLoader() {        
        return (camelContext, schemaStream) -> {
            SchemaValidatorsConfig conf = new SchemaValidatorsConfig();
            conf.setJavaSemantics(true);        
            conf.setFailFast(false);                    
            conf.setUriMappings(                
                Map.of(
                    "http://.../my-schema.json", "resource:META-INF/schemas/my-schema.json",                    
                )
            );          
            return JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7).getSchema(schemaStream, conf);         
        };
    }

}


from("direct:testJson")
  .to("json-validator:META-INF/schemas/my-schema.json?schemaLoader=#my-schema")
Dharman
  • 30,962
  • 25
  • 85
  • 135
TacheDeChoco
  • 3,683
  • 1
  • 14
  • 17
  • Thank you, but apparently the problem was because the "$id"s in my schema weren't URIs, so I deleted all of them and it worked fine ^^ – Midovsky Nov 29 '21 at 16:14