diff --git a/schemas/python-sdk/repository-config/1.16.0.json b/schemas/python-sdk/repository-config/1.16.0.json new file mode 100644 index 0000000..e932aab --- /dev/null +++ b/schemas/python-sdk/repository-config/1.16.0.json @@ -0,0 +1,342 @@ +{ + "$defs": { + "InfrahubCheckDefinitionConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the Check Definition", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the check code.", + "format": "path", + "title": "File Path", + "type": "string" + }, + "parameters": { + "description": "The input parameters required to run this check", + "title": "Parameters", + "type": "object" + }, + "targets": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The group to target when running this check, leave blank for global checks", + "title": "Targets" + }, + "class_name": { + "default": "Check", + "description": "The name of the check class to run.", + "title": "Class Name", + "type": "string" + } + }, + "required": [ + "name", + "file_path" + ], + "title": "InfrahubCheckDefinitionConfig", + "type": "object" + }, + "InfrahubGeneratorDefinitionConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the Generator Definition", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the generator code.", + "format": "path", + "title": "File Path", + "type": "string" + }, + "query": { + "description": "The GraphQL query to use as input.", + "title": "Query", + "type": "string" + }, + "parameters": { + "description": "The input parameters required to run this check", + "title": "Parameters", + "type": "object" + }, + "targets": { + "description": "The group to target when running this generator", + "title": "Targets", + "type": "string" + }, + "class_name": { + "default": "Generator", + "description": "The name of the generator class to run.", + "title": "Class Name", + "type": "string" + }, + "convert_query_response": { + "default": false, + "description": "Decide if the generator should convert the result of the GraphQL query to SDK InfrahubNode objects.", + "title": "Convert Query Response", + "type": "boolean" + }, + "execute_in_proposed_change": { + "default": true, + "description": "Decide if the generator should execute in a proposed change.", + "title": "Execute In Proposed Change", + "type": "boolean" + }, + "execute_after_merge": { + "default": true, + "description": "Decide if the generator should execute after a merge.", + "title": "Execute After Merge", + "type": "boolean" + } + }, + "required": [ + "name", + "file_path", + "query", + "targets" + ], + "title": "InfrahubGeneratorDefinitionConfig", + "type": "object" + }, + "InfrahubJinja2TransformConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the transform", + "title": "Name", + "type": "string" + }, + "query": { + "description": "The name of the GraphQL Query", + "title": "Query", + "type": "string" + }, + "template_path": { + "description": "The path within the repository of the template file", + "format": "path", + "title": "Template Path", + "type": "string" + }, + "description": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Description for this transform", + "title": "Description" + } + }, + "required": [ + "name", + "query", + "template_path" + ], + "title": "InfrahubJinja2TransformConfig", + "type": "object" + }, + "InfrahubPythonTransformConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the Transform", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the transform code.", + "format": "path", + "title": "File Path", + "type": "string" + }, + "class_name": { + "default": "Transform", + "description": "The name of the transform class to run.", + "title": "Class Name", + "type": "string" + }, + "convert_query_response": { + "default": false, + "description": "Decide if the transform should convert the result of the GraphQL query to SDK InfrahubNode objects.", + "title": "Convert Query Response", + "type": "boolean" + } + }, + "required": [ + "name", + "file_path" + ], + "title": "InfrahubPythonTransformConfig", + "type": "object" + }, + "InfrahubRepositoryArtifactDefinitionConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the artifact definition", + "title": "Name", + "type": "string" + }, + "artifact_name": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Name of the artifact created from this definition", + "title": "Artifact Name" + }, + "parameters": { + "description": "The input parameters required to render this artifact", + "title": "Parameters", + "type": "object" + }, + "content_type": { + "description": "The content type of the rendered artifact", + "title": "Content Type", + "type": "string" + }, + "targets": { + "description": "The group to target when creating artifacts", + "title": "Targets", + "type": "string" + }, + "transformation": { + "description": "The transformation to use.", + "title": "Transformation", + "type": "string" + } + }, + "required": [ + "name", + "parameters", + "content_type", + "targets", + "transformation" + ], + "title": "InfrahubRepositoryArtifactDefinitionConfig", + "type": "object" + }, + "InfrahubRepositoryGraphQLConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the GraphQL Query", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the query code.", + "format": "path", + "title": "File Path", + "type": "string" + } + }, + "required": [ + "name", + "file_path" + ], + "title": "InfrahubRepositoryGraphQLConfig", + "type": "object" + } + }, + "additionalProperties": false, + "properties": { + "check_definitions": { + "description": "User defined checks", + "items": { + "$ref": "#/$defs/InfrahubCheckDefinitionConfig" + }, + "title": "Check Definitions", + "type": "array" + }, + "schemas": { + "description": "Schema files", + "items": { + "format": "path", + "type": "string" + }, + "title": "Schemas", + "type": "array" + }, + "jinja2_transforms": { + "description": "Jinja2 data transformations", + "items": { + "$ref": "#/$defs/InfrahubJinja2TransformConfig" + }, + "title": "Jinja2 Transforms", + "type": "array" + }, + "artifact_definitions": { + "description": "Artifact definitions", + "items": { + "$ref": "#/$defs/InfrahubRepositoryArtifactDefinitionConfig" + }, + "title": "Artifact Definitions", + "type": "array" + }, + "python_transforms": { + "description": "Python data transformations", + "items": { + "$ref": "#/$defs/InfrahubPythonTransformConfig" + }, + "title": "Python Transforms", + "type": "array" + }, + "generator_definitions": { + "description": "Generator definitions", + "items": { + "$ref": "#/$defs/InfrahubGeneratorDefinitionConfig" + }, + "title": "Generator Definitions", + "type": "array" + }, + "queries": { + "description": "GraphQL Queries", + "items": { + "$ref": "#/$defs/InfrahubRepositoryGraphQLConfig" + }, + "title": "Queries", + "type": "array" + }, + "objects": { + "description": "Objects", + "items": { + "format": "path", + "type": "string" + }, + "title": "Objects", + "type": "array" + }, + "menus": { + "description": "Menus", + "items": { + "format": "path", + "type": "string" + }, + "title": "Menus", + "type": "array" + } + }, + "title": "InfrahubRepositoryConfig", + "type": "object" +} \ No newline at end of file diff --git a/schemas/python-sdk/repository-config/1.17.0.json b/schemas/python-sdk/repository-config/1.17.0.json new file mode 100644 index 0000000..e932aab --- /dev/null +++ b/schemas/python-sdk/repository-config/1.17.0.json @@ -0,0 +1,342 @@ +{ + "$defs": { + "InfrahubCheckDefinitionConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the Check Definition", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the check code.", + "format": "path", + "title": "File Path", + "type": "string" + }, + "parameters": { + "description": "The input parameters required to run this check", + "title": "Parameters", + "type": "object" + }, + "targets": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "The group to target when running this check, leave blank for global checks", + "title": "Targets" + }, + "class_name": { + "default": "Check", + "description": "The name of the check class to run.", + "title": "Class Name", + "type": "string" + } + }, + "required": [ + "name", + "file_path" + ], + "title": "InfrahubCheckDefinitionConfig", + "type": "object" + }, + "InfrahubGeneratorDefinitionConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the Generator Definition", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the generator code.", + "format": "path", + "title": "File Path", + "type": "string" + }, + "query": { + "description": "The GraphQL query to use as input.", + "title": "Query", + "type": "string" + }, + "parameters": { + "description": "The input parameters required to run this check", + "title": "Parameters", + "type": "object" + }, + "targets": { + "description": "The group to target when running this generator", + "title": "Targets", + "type": "string" + }, + "class_name": { + "default": "Generator", + "description": "The name of the generator class to run.", + "title": "Class Name", + "type": "string" + }, + "convert_query_response": { + "default": false, + "description": "Decide if the generator should convert the result of the GraphQL query to SDK InfrahubNode objects.", + "title": "Convert Query Response", + "type": "boolean" + }, + "execute_in_proposed_change": { + "default": true, + "description": "Decide if the generator should execute in a proposed change.", + "title": "Execute In Proposed Change", + "type": "boolean" + }, + "execute_after_merge": { + "default": true, + "description": "Decide if the generator should execute after a merge.", + "title": "Execute After Merge", + "type": "boolean" + } + }, + "required": [ + "name", + "file_path", + "query", + "targets" + ], + "title": "InfrahubGeneratorDefinitionConfig", + "type": "object" + }, + "InfrahubJinja2TransformConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the transform", + "title": "Name", + "type": "string" + }, + "query": { + "description": "The name of the GraphQL Query", + "title": "Query", + "type": "string" + }, + "template_path": { + "description": "The path within the repository of the template file", + "format": "path", + "title": "Template Path", + "type": "string" + }, + "description": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Description for this transform", + "title": "Description" + } + }, + "required": [ + "name", + "query", + "template_path" + ], + "title": "InfrahubJinja2TransformConfig", + "type": "object" + }, + "InfrahubPythonTransformConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the Transform", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the transform code.", + "format": "path", + "title": "File Path", + "type": "string" + }, + "class_name": { + "default": "Transform", + "description": "The name of the transform class to run.", + "title": "Class Name", + "type": "string" + }, + "convert_query_response": { + "default": false, + "description": "Decide if the transform should convert the result of the GraphQL query to SDK InfrahubNode objects.", + "title": "Convert Query Response", + "type": "boolean" + } + }, + "required": [ + "name", + "file_path" + ], + "title": "InfrahubPythonTransformConfig", + "type": "object" + }, + "InfrahubRepositoryArtifactDefinitionConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the artifact definition", + "title": "Name", + "type": "string" + }, + "artifact_name": { + "anyOf": [ + { + "type": "string" + }, + { + "type": "null" + } + ], + "default": null, + "description": "Name of the artifact created from this definition", + "title": "Artifact Name" + }, + "parameters": { + "description": "The input parameters required to render this artifact", + "title": "Parameters", + "type": "object" + }, + "content_type": { + "description": "The content type of the rendered artifact", + "title": "Content Type", + "type": "string" + }, + "targets": { + "description": "The group to target when creating artifacts", + "title": "Targets", + "type": "string" + }, + "transformation": { + "description": "The transformation to use.", + "title": "Transformation", + "type": "string" + } + }, + "required": [ + "name", + "parameters", + "content_type", + "targets", + "transformation" + ], + "title": "InfrahubRepositoryArtifactDefinitionConfig", + "type": "object" + }, + "InfrahubRepositoryGraphQLConfig": { + "additionalProperties": false, + "properties": { + "name": { + "description": "The name of the GraphQL Query", + "title": "Name", + "type": "string" + }, + "file_path": { + "description": "The file within the repository with the query code.", + "format": "path", + "title": "File Path", + "type": "string" + } + }, + "required": [ + "name", + "file_path" + ], + "title": "InfrahubRepositoryGraphQLConfig", + "type": "object" + } + }, + "additionalProperties": false, + "properties": { + "check_definitions": { + "description": "User defined checks", + "items": { + "$ref": "#/$defs/InfrahubCheckDefinitionConfig" + }, + "title": "Check Definitions", + "type": "array" + }, + "schemas": { + "description": "Schema files", + "items": { + "format": "path", + "type": "string" + }, + "title": "Schemas", + "type": "array" + }, + "jinja2_transforms": { + "description": "Jinja2 data transformations", + "items": { + "$ref": "#/$defs/InfrahubJinja2TransformConfig" + }, + "title": "Jinja2 Transforms", + "type": "array" + }, + "artifact_definitions": { + "description": "Artifact definitions", + "items": { + "$ref": "#/$defs/InfrahubRepositoryArtifactDefinitionConfig" + }, + "title": "Artifact Definitions", + "type": "array" + }, + "python_transforms": { + "description": "Python data transformations", + "items": { + "$ref": "#/$defs/InfrahubPythonTransformConfig" + }, + "title": "Python Transforms", + "type": "array" + }, + "generator_definitions": { + "description": "Generator definitions", + "items": { + "$ref": "#/$defs/InfrahubGeneratorDefinitionConfig" + }, + "title": "Generator Definitions", + "type": "array" + }, + "queries": { + "description": "GraphQL Queries", + "items": { + "$ref": "#/$defs/InfrahubRepositoryGraphQLConfig" + }, + "title": "Queries", + "type": "array" + }, + "objects": { + "description": "Objects", + "items": { + "format": "path", + "type": "string" + }, + "title": "Objects", + "type": "array" + }, + "menus": { + "description": "Menus", + "items": { + "format": "path", + "type": "string" + }, + "title": "Menus", + "type": "array" + } + }, + "title": "InfrahubRepositoryConfig", + "type": "object" +} \ No newline at end of file diff --git a/schemas/python-sdk/repository-config/latest.json b/schemas/python-sdk/repository-config/latest.json index deb52d9..8ab6031 120000 --- a/schemas/python-sdk/repository-config/latest.json +++ b/schemas/python-sdk/repository-config/latest.json @@ -1 +1 @@ -1.15.0.json \ No newline at end of file +1.17.0.json \ No newline at end of file diff --git a/tests/test_schema_validation.py b/tests/test_schema_validation.py index 42ec70c..9beba75 100644 --- a/tests/test_schema_validation.py +++ b/tests/test_schema_validation.py @@ -6,6 +6,7 @@ import glob import json from dataclasses import dataclass +from enum import StrEnum from pathlib import Path import jsonschema @@ -16,15 +17,66 @@ ALL_JSON_FILES = sorted(glob.glob(str(REPO_ROOT / "**" / "*.json"), recursive=True)) +class SchemaSection(StrEnum): + PYTHON_SDK = "python-sdk" + INFRAHUB = "infrahub" + DEVELOP = "develop" + VERSIONS = "versions" + + @property + def has_schema_dir(self) -> bool: + return self in { + SchemaSection.PYTHON_SDK, + SchemaSection.INFRAHUB, + SchemaSection.VERSIONS, + } + + @dataclass class JsonTestCase: - name: str file_path: Path + @property + def file_name(self) -> str: + return self.file_path.name + + @property + def version(self) -> str: + return self.file_path.stem + + @property + def name(self) -> str: + return f"{self.section}/{self.schema_type}{self.version}" + + @property + def relative_path(self) -> Path: + return self.file_path.relative_to(REPO_ROOT) + + @property + def relative_dir(self) -> Path: + return self.relative_path.parent + + @property + def section(self) -> SchemaSection: + return SchemaSection(self.sections[0]) + + @property + def schema_type(self) -> str: + if self.section.has_schema_dir: + return f"{self.sections[1]}/" + return "" + + @property + def sections(self) -> list[str]: + section_parts = self.relative_dir.parts + assert section_parts[0] == "schemas", ( + "Expected JSON files to be under 'schemas/' directory" + ) + return list(section_parts[1:]) + ALL_JSON_TEST_CASES = [ - JsonTestCase(name=json_file, file_path=Path(json_file)) - for json_file in ALL_JSON_FILES + JsonTestCase(file_path=Path(json_file)) for json_file in ALL_JSON_FILES ]