Closed pradeep-bose closed 3 months ago
This Redfish-JsonSchema-ResponseValidator
tool uses the jsonschema
package to perform the validation. And the data output from jsonschema
is very different from the output generated by Redfish-Service-Validator
. So reusing the tohtml.py
from that tool would (I think) not be practical.
Thanks @billdodd i just wanted some more verbose like information . The current verbose is not so detailed , it just provides the URL data and the schema that was verified. Not all the properties that were verified. I am pretty new to Draft4Validator function in jsonschema library.
So i wanted to get a code snippet to spew out all the items in the data / payload from the URI that were validated , even the PASS ones .
The code snippet below flags only the false ones, I had gone through the jsonschema validator object but couldnt find anything that shows what was passed and value matched with schema (somrthing more verbose )
Could you point me to the right python module / function
import jsonschema
from json import loads
with open ('Memory.v1_6_0.json','r') as fp:
schema_data = loads (fp.read())
with open ('memory_dimm.json','r') as fp:
memory_data = loads (fp.read())
try:
validator = jsonschema.Draft4Validator(schema_data)
print("Validator information ", validator)
#validator.validate(memory_data)
errors_found = []
for error in validator.iter_errors(memory_data):
errors_found.append(error.message)
except jsonschema.ValidationError as e:
print (e.message)
print(errors_found)
#jsonschema.validate(memory_data, schema_data)
print("Value of instance check ",jsonschema.Draft4Validator(schema_data).is_valid(memory_data))
agreed @billdodd , but some comprehensive report would be a good feature
@pradeep-bose - the mechanism you show showed above to loop through the errors (which is basically what is on the jsonschema website) is the only way I know to control the output of the default validator. But as you noted, it will only show you the errors.
There is an extension mechanism that could be investigated to see if there is a way to output information on passing results. But I haven't played with it and do not know how feasible that would be.
At this time we're archiving this project in favor of the Redfish Service Validator found here: https://github.com/DMTF/Redfish-Service-Validator
As of now , after running a test , we get the below summary
1 resources validated. 0 errors schemas returned from GET 1 schemas returned from cache 0
Is it possible to utilize the existing code and provide values like in Redfish service validator
which has a conformance report in HTML , which is very comprehensive
titles = ['Property Name', 'Value', 'Type', 'Exists', 'Result']
If we have the data output similar to Redfish service validator , then the snippet below can be used to spew a HTML report ? https://github.com/DMTF/Redfish-Service-Validator/blob/master/tohtml.py