Open keithrfung opened 3 years ago
from typing import Any, Tuple
from os.path import join, dirname, realpath
from json import load
from jsonschema import validate
from jsonschema.exceptions import ValidationError
__all__ = ["get_election_description_schema", "validate_json_schema"]
def _load_schema(json_schema_file_name: str) -> Any:
"""Loads the given schema"""
with open(join(dirname(realpath(__file__)), json_schema_file_name), "r") as file:
schema = load(file)
return schema
def get_election_description_schema() -> Any:
"""Get default schema for election description schema"""
return _load_schema("election_description_schema.json")
def validate_json_schema(
json_data: Any,
json_schema: Any,
) -> Tuple[bool, str]:
"""Validate json schema"""
try:
validate(instance=json_data, schema=json_schema)
except ValidationError as err:
return (False, err.message)
return (True, "Json schema validated")
Hey @keithrfung
I would like to take up this issue.
As far as I have understood the description, those two files have to be moved into the api project under schema
folder correct?
But what is the above code that you have given?
Hey @keithrfung, is this issue available I would like to work on it.
@bhushan-borole and @PradyumnaKrishna Sorry I missed both of these.
The schemas are currently in the process of being moved to the github.com/microsoft/electionguard repositories. The idea is that there should be some schemas readily available at that level that can be used in the API to ensure the models are correct.
It would likely be wiser to help at that level first. However, this issue is still stands if either of you would like to work. The issue is about making a method to check the schema after a post is made to the call to check a manifest. The schema check itself is getting entirely removed from the bottom python level.
Feature Request
Is your feature request related to a problem? Please describe. These should get moved into to the electionguard-python-api https://github.com/microsoft/electionguard-python/blob/6d70f6602746bfcf840b59ce986f2c76c5fe58e5/src/electionguard/election_description_schema.json
https://github.com/microsoft/electionguard-python/blob/6d70f6602746bfcf840b59ce986f2c76c5fe58e5/src/electionguard/schema.py
Ideally with a
schema
folder. These could then be moved toelectionguard
root at a later point.Accompanying PR to remove schema checking at base level.
Accompany issue: https://github.com/microsoft/electionguard-python/issues/384