Editable $id and $schema properties for config generated JSONSchema
stephen-bunn opened this issue · 0 comments
Expected Behavior
Defined config classes should have the ability to define the generated JSONschema's $id
and $schema
properties. Most likely the expected usage would look something like the following:
from file_config import config, var
@config(schema_id="Resource.json", schema_draft="http://json-schema.org/draft-07/schema#")
class MyResource(object):
name: str = var()
This would build the following JSONSchema:
{
"type": "object",
"required":
[
"name"
],
"properties":
{
"name":
{
"$id": "#/properties/name",
"type": "string"
}
},
"$id": "Resource.json",
"$schema": "http://json-schema.org/draft-07/schema#"
}
Current Behavior
Currently, the default behavior to generate the id is just to take the name of the class and set that as the JSONschema $id
. By default, the $id
of the above config class would be MyResource.json
without any method to modify this value.
The document $schema
is hard-set to draft-07 as that draft is the minimum required to support several features such as pattern matching for the file_config.Regex
fields. Unsure how to allow this to be mutable as of right now.
Possible Solution
The code that is utilized to set these properties is found at https://github.com/stephen-bunn/file-config/blob/master/src/file_config/schema_builder.py#L447-L451. Changing this to read properties from the config's metadata store should be simple.
I propose that we add the following optional kwargs to the config()
decorator to allow the dynamic setting of generated JSONschema $id
and $schema
fields.
schema_id
- controls the$id
property in JSONschemaschema_draft
- controls the$schema
property in JSONschema
As we hard-depend on draft-07 for our schema building, there will probably either need to be some kind of validation or warning issued when a draft < 07 is specified for schema_draft
.
Steps to Reproduce (for bugs)
N/A
Context
N/A
Your Environment
- File Config Version: 0.3.10
- Python Version: 3.7
Operating System and Version:Link to your branch (if applicable):
❤️ Thank you!