mirror of
https://github.com/deepset-ai/haystack.git
synced 2025-08-28 18:36:36 +00:00
Generate JSON schema index for Schemastore (#2225)
* Generate JSON schema index * Add index file Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
parent
116fe2db26
commit
d1b7761504
61
.github/utils/generate_json_schema.py
vendored
61
.github/utils/generate_json_schema.py
vendored
@ -69,6 +69,9 @@ class Config(BaseConfig):
|
|||||||
|
|
||||||
|
|
||||||
def get_json_schema():
|
def get_json_schema():
|
||||||
|
"""
|
||||||
|
Generate JSON schema for Haystack pipelines.
|
||||||
|
"""
|
||||||
schema_definitions = {}
|
schema_definitions = {}
|
||||||
additional_definitions = {}
|
additional_definitions = {}
|
||||||
|
|
||||||
@ -210,11 +213,69 @@ def get_json_schema():
|
|||||||
return pipeline_schema
|
return pipeline_schema
|
||||||
|
|
||||||
|
|
||||||
|
def list_indexed_versions(index):
|
||||||
|
"""
|
||||||
|
Given the schema index as a parsed JSON,
|
||||||
|
return a list of all the versions it contains.
|
||||||
|
"""
|
||||||
|
indexed_versions = []
|
||||||
|
for version_entry in index["oneOf"]:
|
||||||
|
for property_entry in version_entry["allOf"]:
|
||||||
|
if "properties" in property_entry.keys():
|
||||||
|
indexed_versions.append(property_entry["properties"]["version"]["const"])
|
||||||
|
return indexed_versions
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_rc_versions(index):
|
||||||
|
"""
|
||||||
|
Given the schema index as a parsed JSON,
|
||||||
|
removes any existing (unstable) rc version from it.
|
||||||
|
"""
|
||||||
|
new_versions_list = []
|
||||||
|
for version_entry in index["oneOf"]:
|
||||||
|
for property_entry in version_entry["allOf"]:
|
||||||
|
if "properties" in property_entry.keys():
|
||||||
|
if "rc" not in property_entry["properties"]["version"]["const"]:
|
||||||
|
new_versions_list.append(version_entry)
|
||||||
|
break
|
||||||
|
index["oneOf"] = new_versions_list
|
||||||
|
return index
|
||||||
|
|
||||||
|
|
||||||
|
def new_version_entry(version):
|
||||||
|
"""
|
||||||
|
Returns a new entry for the version index JSON schema.
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
"allOf": [
|
||||||
|
{"properties": {"version": {"const": version}}},
|
||||||
|
{
|
||||||
|
"$ref": "https://raw.githubusercontent.com/deepset-ai/haystack/master/json-schemas/"
|
||||||
|
f"haystack-pipeline-{version}.schema.json"
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def generate_json_schema():
|
def generate_json_schema():
|
||||||
|
# Create new schema file
|
||||||
pipeline_schema = get_json_schema()
|
pipeline_schema = get_json_schema()
|
||||||
destination_path.parent.mkdir(parents=True, exist_ok=True)
|
destination_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
destination_path.write_text(json.dumps(pipeline_schema, indent=2))
|
destination_path.write_text(json.dumps(pipeline_schema, indent=2))
|
||||||
|
|
||||||
|
# Update schema index
|
||||||
|
index = []
|
||||||
|
index_path = Path(__file__).parent.parent.parent / "json-schemas" / "haystack-pipeline.schema.json"
|
||||||
|
with open(index_path, "r") as index_file:
|
||||||
|
index = json.load(index_file)
|
||||||
|
if index:
|
||||||
|
index = cleanup_rc_versions(index)
|
||||||
|
indexed_versions = list_indexed_versions(index)
|
||||||
|
if not any(version == schema_version for version in indexed_versions):
|
||||||
|
index["oneOf"].append(new_version_entry(schema_version))
|
||||||
|
with open(index_path, "w") as index_file:
|
||||||
|
json.dump(index, index_file, indent=4)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
from github import Github
|
from github import Github
|
||||||
|
51
json-schemas/haystack-pipeline.schema.json
Normal file
51
json-schemas/haystack-pipeline.schema.json
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"$schema": "http://json-schema.org/draft-07/schema",
|
||||||
|
"$id": "https://haystack.deepset.ai/json-schemas/haystack-pipeline-1.1.0.schema.json",
|
||||||
|
"title": "Haystack Pipeline",
|
||||||
|
"description": "Haystack Pipeline YAML file describing the nodes of the pipelines. For more info read the docs at: https://haystack.deepset.ai/components/pipelines#yaml-file-definitions",
|
||||||
|
"type": "object",
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"const": "0.7"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "https://raw.githubusercontent.com/deepset-ai/haystack/master/json-schemas/haystack-pipeline-0.7.schema.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"const": "1.1.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "https://raw.githubusercontent.com/deepset-ai/haystack/master/json-schemas/haystack-pipeline-1.1.0.schema.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"allOf": [
|
||||||
|
{
|
||||||
|
"properties": {
|
||||||
|
"version": {
|
||||||
|
"const": "1.2.0rc0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$ref": "https://raw.githubusercontent.com/deepset-ai/haystack/master/json-schemas/haystack-pipeline-1.2.0rc0.schema.json"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user