cancel
Showing results for 
Search instead for 
Did you mean: 

Issue running networknt schema validator in Readyapi groovy script

Steeb21
New Contributor

Issue running networknt schema validator in Readyapi groovy script

Hi, I am trying to run a schema validator library, networknt, in a groovy script in Readyapi, but for some unknown reason, the factory method used to generate the schemaNode won't work. Here is the script:

@Grapes([
@Grab('com.fasterxml.jackson.core:jackson-databind:2.9.6'),
@Grab('org.slf4j:slf4j-api:1.7.30'),
@Grab('org.apache.commons:commons-lang3:3.11'),
@Grab('com.networknt:json-schema-validator:1.0.52')
])

import com.networknt.schema.JsonSchemaFactory

import com.networknt.schema.SpecVersion

JsonSchemaFactory factory = JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909)

 

The error I get:

ERROR: groovy.lang.MissingMethodException: No signature of method: static com.networknt.schema.JsonSchemaFactory.getInstance() is applicable for argument types: (com.networknt.schema.SpecVersion$VersionFlag) values: [V201909]
groovy.lang.MissingMethodException: No signature of method: static com.networknt.schema.JsonSchemaFactory.getInstance() is applicable for argument types: (com.networknt.schema.SpecVersion$VersionFlag) values: [V201909]
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1518)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1504)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:52)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:128)
at Script5.run(Script5.groovy:9)
at com.eviware.soapui.support.scripting.groovy.SoapUIGroovyScriptEngine.run(SoapUIGroovyScriptEngine.java:94)
at com.eviware.soapui.support.scripting.groovy.SoapUIProGroovyScriptEngineFactory$SoapUIProGroovyScriptEngine.run(SoapUIProGroovyScriptEngineFactory.java:83)
at com.eviware.soapui.impl.wsdl.teststeps.WsdlGroovyScriptTestStep.run(WsdlGroovyScriptTestStep.java:159)
at com.eviware.soapui.impl.wsdl.panels.teststeps.GroovyScriptStepDesktopPanel$RunAction$1.run(GroovyScriptStepDesktopPanel.java:331)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:835)

 

I checked if it's not an incompatibility with the version of groovy in Readyapi I am using. Readyapi 3.2.0, Groovy 2.4.17. I downgraded my groovy version installed locally to that of the groovy version in Readyapi and tried running same script in groovyConsole and it works properly. The script I am trying to run is from the validator's github documentation which i am linking here

 

I'll appreciate if anyone can point out what I might be doing wrong or help in resolving this issue. Thank you.

3 REPLIES 3
nmrao
Community Hero

Re: Issue running networknt schema validator in Readyapi groovy script

Couple of things here:

 

1. ReadyAPI doesn't support pulling the Dependencies with @Grab out-of-the-box. Looks you made use of ivy library?

 

2. ReadyAPI uses higher version of jackson, say 2.11.1

3. Here you are trying to pull old version which might conflict with preloaded library. I think, you may still work without pulling jackson dependency.

b. there is already json-shema-validation in ReadyAPI lib directory but lower version, and you are pulling higher version in the script. If you really needed, you may use it in the same way as you replaced the groovy version ( of course, it may not be supported by Smartbear. NOTE have a back of library which you are replacing so that you will be able to go to original state if needed)

 

4. Most of all, using incorrect usage of API as per the error reported in the question.

 


The error I get:

ERROR: groovy.lang.MissingMethodException: No signature of method: static com.networknt.schema.JsonSchemaFactory.getInstance() is applicable for argument types: (com.networknt.schema.SpecVersion$VersionFlag) values: [V201909]

 

May be below link might help!

https://github.com/networknt/json-schema-validator/blob/master/doc/specversion.md#to-create-a-jsonsc...



Regards,
Rao.
Steeb21
New Contributor

Re: Issue running networknt schema validator in Readyapi groovy script

Thank you @nmrao  for your feedback.

 

- I do make use of Ivy to pull in dependencies.

 

- I checked the json-schema-validator in Readyapi lib, there is 0.1.7 and 2.2.8 jar files. Now the version of what I am trying to get run is 1.0.52 (latest version for networknt), which would be a lower version to 2.2.8 in Readyapi lib. So this won't be a higher version compared to what is used by Readyapi. This also makes me think that these schema validators are from different libraries. Would you happen to know from which library are the ones used in Readyapi? Also, even if there are other libraries in Readyapi, I import libraries in my groovy script in Readyapi, I would think it is whatever I import which is used while executing the script.

 

- I will mention that I am able to use still another json-schema-validator library (this time from io.rest-assured) to do schema validation, and it works fine in Readyapi scripts without any issue. The only reason I am trying to use the one from networknt is because I will be able to do validation for latest versions of schema drafts. The one from rest-assured validates json schemas up to draft v4 only.

 

- I do think I am properly using the API, reason why I do not understand why I get the "MissingMethodException" error. I did try same script in a groovy script out of Readyapi, just to make sure I am properly using it. for more details, the javadoc specify how to use the static method getInstance() here 

 

- Thank you for sharing the link on how we could create a JsonSchemaFactory using SpecVersionDetector detect() method. This is something I have tried using but I get another error, probably from another method being used be detect():

  • ERROR: java.lang.NoSuchMethodError: com.networknt.schema.JsonSchemaFactory.normalizeMetaSchemaUri(Ljava/lang/String;)Ljava/lang/String;
nmrao
Community Hero

Re: Issue running networknt schema validator in Readyapi groovy script

The naming convention used from different library sources are unfortunately the same, hence the confusion.

there is 0.1.7 => this is the same one which you are trying to use 1.0.52.

 

One is free to use the changed libraries as long as aware of the changes and know how to go back to original state in case required. I think you are well aware of what you are doing which is good.

 

As I pointed git hub earlier, you can further check the same for some sample or tests which might help and also don't have much idea or never needed what you are trying. What is the use case by the way? Don't the tool validate ?

 

 

 

 

 

 

 

 



Regards,
Rao.
New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors