Hello,
I do not know how can I keep my schema definitions DRY. Example situation: I have a schema for person and I need also a schema for a collection of person objects. The problem: I want to have only one place where person is defined. I came up with several ways to solve this, but neither one seems to be a satisfying solution:
1) Put everything into one JSON file with subschemas and then tell my validator which subschema to use by refs. However, I could not find a way how to tell jsonschema implementation it should not use the whole schema, but only its subschema. I could extract the subschema myself from the Python dict, but then references to other subschemas would be lost.
2) Put schemas into several JSON files and use their absolute URLs in refs. However, this is not possible very much - they have no absolute URLs, in fact they are internal files and they have no URLs at all. Even if I publish them in my Flask app and they would have absolute URLs, I don't know those from inside the app, because the app could be deployed anywhere. In fact, I know those URLs from inside the app (Flask has it's url_for(..., _external=True) helper), but as long as I want to keep schemas in pure JSON files separated from the rest of the code, this does not seem to lead anywhere.
3) Do not use JSON files and define schema as Python files. In package "schemas" I can have several Python modules and they can import each other and reuse definitions. This actually gets the job done, but well... circular imports could be an issue and in the end of the day, I am not using JSON schema, I am using Python dicts that look like JSON schema... and Python modules... I do not like this solution, I consider it to be a hack.
Is there a "good" solution for this? Thanks!
Honza