Script to Validate Node Against DB Schema #214
nh916
started this conversation in
Show and tell
Replies: 1 comment
-
put script on local machineCreate venv
activate venvinstall needed requirements in venvpip install jsonschema pip install requests run python scriptthe python script will finish without errors if the db schema is successful, otherwise it will output the errors New Python script with terminal interfaceimport json
from pathlib import Path
import jsonschema
import requests
def get_db_schema():
"""
get db schema from server
"""
json_schema = requests.get(
"https://development.api.mycriptapp.org/api/v1/schema"
).json()["data"]
return json_schema
def validate_giant_json(json_path, node_type, http_method):
db_schema = get_db_schema()
# this field needs to be overwritten with whatever is needed
node_type: str = node_type.title()
http_method: str = http_method.title()
db_schema["$ref"] = f"#/$defs/{node_type}{http_method}"
with open(file=json_path, mode="r") as file_handle:
cript_json = json.loads(file_handle.read())
jsonschema.validate(instance=cript_json, schema=db_schema)
if __name__ == "__main__":
json_path = input("please specify the location of the CRIPT JSON file \n")
# convert user input to Path object
json_path = Path(json_path).resolve()
print(json_path)
node_type = input("which node do you want to validate? \n").title()
http_method = input("which HTTP method are you using? POST or PATCH \n").title()
validate_giant_json(json_path=json_path, node_type=node_type, http_method=http_method) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Install Requirements
Run Script
Beta Was this translation helpful? Give feedback.
All reactions