diff --git a/.github/workflows/validate-schemas.yml b/.github/workflows/validate-fabric-schemas.yml similarity index 77% rename from .github/workflows/validate-schemas.yml rename to .github/workflows/validate-fabric-schemas.yml index bdf1789f..ed028692 100644 --- a/.github/workflows/validate-schemas.yml +++ b/.github/workflows/validate-fabric-schemas.yml @@ -1,9 +1,9 @@ -name: validate schemas +name: validate Fabric schemas on: pull_request: paths: - - 'fabric/item/**/*.json' + - 'fabric/**/*.json' jobs: test: @@ -24,4 +24,4 @@ jobs: - name: Run tests run: | - pytest \ No newline at end of file + pytest ./tests/validate-fabric-schemas_test.py \ No newline at end of file diff --git a/fabric/gitIntegration/platformProperties/2.0.0/schema.json b/fabric/gitIntegration/platformProperties/2.0.0/schema.json index 6cf0cf17..b150b761 100644 --- a/fabric/gitIntegration/platformProperties/2.0.0/schema.json +++ b/fabric/gitIntegration/platformProperties/2.0.0/schema.json @@ -1,4 +1,5 @@ { + "$id": "https://developer.microsoft.com/json-schemas/fabric/gitIntegration/platformProperties/2.0.0/schema.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "Fabric item Git integration configuration", "description": "Configuration file used by fabric Git integration on items in Git repositories", diff --git a/fabric/gitIntegration/platformProperties/2.1.0/schema.json b/fabric/gitIntegration/platformProperties/2.1.0/schema.json index 334578cd..492e6112 100644 --- a/fabric/gitIntegration/platformProperties/2.1.0/schema.json +++ b/fabric/gitIntegration/platformProperties/2.1.0/schema.json @@ -1,4 +1,5 @@ { + "$id": "https://developer.microsoft.com/json-schemas/fabric/gitIntegration/platformProperties/2.1.0/schema.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "Fabric item Git integration configuration", "description": "Configuration file used by fabric Git integration on items in Git repositories", diff --git a/fabric/gitIntegration/schedules/1.0.0/schema.json b/fabric/gitIntegration/schedules/1.0.0/schema.json index 0deb8496..b4cd85b8 100644 --- a/fabric/gitIntegration/schedules/1.0.0/schema.json +++ b/fabric/gitIntegration/schedules/1.0.0/schema.json @@ -1,4 +1,5 @@ { + "$id": "https://developer.microsoft.com/json-schemas/fabric/gitIntegration/schedules/1.0.0/schema.json", "$schema": "http://json-schema.org/draft-07/schema#", "title": "Fabric item schedules Git integration configuration", "description": "Configuration file used by fabric Git integration on item schedules in Git repositories", diff --git a/fabric/item/graphqlApi/definition/1.0.0/schema.json b/fabric/item/graphqlApi/definition/1.0.0/schema.json index 0967ef42..25a8556d 100644 --- a/fabric/item/graphqlApi/definition/1.0.0/schema.json +++ b/fabric/item/graphqlApi/definition/1.0.0/schema.json @@ -1 +1,4 @@ -{} +{ + "$id": "https://developer.microsoft.com/json-schemas/fabric/item/graphsqlApi/definition/1.0.0/schema.json", + "$schema": "https://json-schema.org/draft-07/schema#" +} diff --git a/fabric/item/operationsAgents/definition/1.0.0/schema.json b/fabric/item/operationsAgents/definition/1.0.0/schema.json index 23099f4d..11aa6b24 100644 --- a/fabric/item/operationsAgents/definition/1.0.0/schema.json +++ b/fabric/item/operationsAgents/definition/1.0.0/schema.json @@ -1,5 +1,6 @@ { - "$schema": "https://developer.microsoft.com/json-schemas/fabric/item/operationsAgents/definition/1.0.0/schema.json", + "$id": "https://developer.microsoft.com/json-schemas/fabric/item/operationsAgents/definition/1.0.0/schema.json", + "$schema": "http://json-schema.org/draft-07/schema#", "title": "Operations Agent", "description": "Artifact definition of Operations Agent.", "type": "object", diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 00000000..edc971b7 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,51 @@ +# JSON Schema Tests + +This directory contains automated tests to validate the JSON schemas in this repository. + +## Prerequisites + +- Python 3.7 or higher +- pytest + +Install pytest if you haven't already: + +```powershell +pip install pytest +``` + +## Running Tests + +### Run all tests + +```powershell +pytest tests/validate-fabric-schemas_test.py +``` + +### Run with verbose output + +```powershell +pytest tests/validate-fabric-schemas_test.py -v +``` + +### Run with detailed failure information + +```powershell +pytest tests/validate-fabric-schemas_test.py -vv +``` + +## Contributing New Tests + +When adding new schema validation tests: + +1. Follow the existing pattern using `@pytest.mark.parametrize` to run tests against all JSON files +2. Use the `find_json_files()` helper to discover schema files +3. Provide clear error messages that include the file path and specific issue +4. Update this README with documentation for your new test + +### Current Test Scope + +The tests currently validate schemas in the `fabric` directory. To change the scope, modify the `SCHEMA_DIR` constant in `validate-fabric-schemas_test.py`. + +## CI/CD Integration + +These tests are designed to run in automated pipelines to ensure schema quality before changes are merged. diff --git a/tests/validate-schemas_test.py b/tests/validate-fabric-schemas_test.py similarity index 51% rename from tests/validate-schemas_test.py rename to tests/validate-fabric-schemas_test.py index bca8752c..6d9486f5 100644 --- a/tests/validate-schemas_test.py +++ b/tests/validate-fabric-schemas_test.py @@ -3,7 +3,7 @@ import glob import pytest -SCHEMA_DIR = "fabric/item" +SCHEMA_DIR = "fabric" def find_json_files(root_dir): """Yield all .json files under a directory recursively.""" @@ -37,4 +37,31 @@ def test_refs_exist(json_file): base_path = os.path.dirname(json_file) for ref_path in extract_refs(schema, base_path): - assert os.path.isfile(ref_path), f"Missing file for $ref in {json_file}: {ref_path}" \ No newline at end of file + assert os.path.isfile(ref_path), f"Missing file for $ref in {json_file}: {ref_path}" + + +@pytest.mark.parametrize("json_file", list(find_json_files(SCHEMA_DIR))) +def test_id_properties_exist(json_file): + with open(json_file, "r", encoding="utf-8") as f: + try: + schema = json.load(f) + except json.JSONDecodeError as e: + pytest.fail(f"Invalid JSON in {json_file}: {e}") + + assert "$id" in schema, f"Missing $id property in {json_file}" + assert isinstance(schema["$id"], str), f"$id property must be a string in {json_file}" + assert schema["$id"].startswith("https://developer.microsoft.com/json-schemas"), \ + f"$id property in {json_file} must start with 'https://developer.microsoft.com/json-schemas', got: {schema['$id']}" + +@pytest.mark.parametrize("json_file", list(find_json_files(SCHEMA_DIR))) +def test_schema_properties_exist(json_file): + with open(json_file, "r", encoding="utf-8") as f: + try: + schema = json.load(f) + except json.JSONDecodeError as e: + pytest.fail(f"Invalid JSON in {json_file}: {e}") + + assert "$schema" in schema, f"Missing $schema property in {json_file}" + assert isinstance(schema["$schema"], str), f"$schema property must be a string in {json_file}" + assert schema["$schema"].startswith("http://json-schema.org/") or schema["$schema"].startswith("https://json-schema.org/"), \ + f"$schema property in {json_file} must start with 'http://json-schema.org/', got: {schema['$schema']}" \ No newline at end of file