Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: validate schemas
name: validate Fabric schemas

on:
pull_request:
paths:
- 'fabric/item/**/*.json'
- 'fabric/**/*.json'

jobs:
test:
Expand All @@ -24,4 +24,4 @@ jobs:

- name: Run tests
run: |
pytest
pytest ./tests/validate-fabric-schemas_test.py
1 change: 1 addition & 0 deletions fabric/gitIntegration/platformProperties/2.0.0/schema.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions fabric/gitIntegration/platformProperties/2.1.0/schema.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions fabric/gitIntegration/schedules/1.0.0/schema.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 4 additions & 1 deletion fabric/item/graphqlApi/definition/1.0.0/schema.json
Original file line number Diff line number Diff line change
@@ -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#"
}
3 changes: 2 additions & 1 deletion fabric/item/operationsAgents/definition/1.0.0/schema.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
51 changes: 51 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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}"
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']}"