-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
networknt / json-schema-validator - Unknown Metaschema: http://json-schema.org/draft-07/schema# #273
Comments
@harpreetk1986 Thanks a lot for raising this issue. I am wondering if this is due to the recent update on the json-schema.org to redirect all HTTP requests to HTTPS. I have updated the draft-2019-09 at this location. https://github.com/networknt/json-schema-validator/blob/master/src/main/java/com/networknt/schema/JsonMetaSchema.java#L151 Have you debugged into it to see where the error message is coming from? |
@stevehu. Thanks for the reply. I just did a debug and found the following: Issue is coming in findMetaSchemaForSchema() function of JsonSchemaFactory Class at below line of code: Here uri is "http://json-schema.org/draft-07/schema#" |
@stevehu : I debug more and found out that, I am calling JsonSchemaFactory.getInstance() and this function is always returning Version flag as V4. Do I need to call getInstance() by passing the version flag. If yes, from where should I fetch that from? |
Yes. You need to specify which draft version to use unless you are using v4 which is the default. |
To prevent users to use the old method. I am thinking to deprecate the getInstance(). What do you think?
|
@stevehu . It is a good idea, it makes complete sense to me. I am thinking , how it can be more dynamic to pass the version flag which supports multiple versions. Since schema can contain any draft version. May be we have to fetch the Draft versions from Schema and create mapping to map to the corresponding version to pass as parameters of getInstance has format like V4, V6 etc. And once if new draft version is released, that needs to be added to the mapping to map to the corresponding version to pass. |
I thought about it when I implement the versioning. We can just decide the version based on the $schema in the schema file; however, we cannot make a decision for the reference schemas if there are any. For example, if you have a schema v7 that refers to another remote schema v4. Which version should the library use? To let the user specify the version at least make them aware of this issue. The other reason is that not all schema files have the $schema. |
I just checked in the @deprecated code. It is not the final solution but just to reduce the risk. Let's keep this conversation going to have a better solution. |
Sure. Thank you. |
Sure, this way also it will work for me. Thanks. |
I'm getting this error and I believe I'm specifying the correct version val config = SchemaValidatorsConfig()
config.isFailFast = true
val mapper = ObjectMapper()
val validatorFactory = JsonSchemaFactory.builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V7)).objectMapper(mapper).build();
validatorFactory.getSchema(schemaString, config) |
@andrhamm Thanks for raising it. It looks like the scope of the problem is getting bigger. I will take a look at it once I have free cycles. It would be great if someone in the community can take a look at your case. |
I miss the same problem, I can't generate a JsonSchema from my JSON schema file of draft-07. Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jsonSchemaService' defined in file [/projects/java-vadilation/target/classes/com/example/javavadilation/service/JsonSchemaService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'getJsonSchemaFromClasspath' defined in class path resource [com/example/javavadilation/config/JsonSchemaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.networknt.schema.JsonSchema]: Factory method 'getJsonSchemaFromClasspath' threw exception; nested exception is com.networknt.schema.JsonSchemaException: Unknown Metaschema: https://json-schema.org/draft-07/schema#
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:798)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:228)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1358)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1204)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 61 more |
@mcoder2014 It looks like the stack trace is part of the spring framework and misses the important info. I am wondering if you could create a small test case to reproduce the issue. Even better if you could debug into it to find the root cause. Thanks. |
If I use
If I change the
|
I think the URL is changed to https from http a couple of months ago. Can you try https? |
Now it is still unknown Metaschema:
|
I tried to reproduce the issue but couldn't. I am wondering if you could submit a PR with a test case to reproduce the issue. Thanks a lot for raising it. |
Thanks, I have commit a pull request with a small test case. It is small but can't run on my computer. Hope you can find the cause about the problem. |
Thanks a lot for raising this issue and joining the discussion. I have added a normalize method to switch the protocol to https and remove the query parameters and fragment. |
Hi,
While using networknt / json-schema-validator, I am getting error while validating schema -06 and above. Getting following error:
com.networknt.schema.JsonSchemaException: Unknown Metaschema: http://json-schema.org/draft-07/schema#
Only schema-04 is working fine.
Here is sample schema I am using:
{
"$schema" : "http://json-schema.org/draft-07/schema#",
"$id" : "http://json-schema.org/draft-07/schema#"
}
The text was updated successfully, but these errors were encountered: