Skip to content

Commit d1123a1

Browse files
committed
feat: add overture-schema-cli package
Introduce a command-line interface for working with Overture schema models. The CLI provides tools for schema introspection, validation, and JSON Schema generation. Commands: list-types [--theme THEME] [--detailed] List registered Overture types, optionally filtered by theme. With --detailed, shows model descriptions from docstrings. json-schema [--theme THEME] [--type TYPE] Generate JSON Schema for specified themes/types or all models. validate [--theme THEME] [--type TYPE] [--show-field FIELD] FILE Validate GeoJSON features against Overture schemas. Supports: - Single features and FeatureCollections - Heterogeneous collections (mixed types) - JSONL input from stdin (use '-' as FILE) - Automatic type detection via discriminator fields - Rich error display with data context windows Type Resolution: When --type is not specified, the validator builds a discriminated union from registered models and uses Pydantic's tagged union support to identify the most likely type. For heterogeneous collections, each feature is validated against its detected type independently. Error Display: Validation errors show surrounding data context to help locate issues. The --show-field option pins specific fields (e.g., id) in the display header for easier identification in large datasets. Pipeline Support: The validate command accepts JSONL on stdin for integration with tools like jq and gpq: gpq convert file.geoparquet --to geojson | \ jq -c '.features[]' | \ overture-schema validate --type building - Module Structure: - commands.py: Click command definitions - type_analysis.py: Union type construction and discriminator handling - error_formatting.py: Validation error processing and display - data_display.py: Context window and field extraction - output.py: Rich console output helpers
1 parent ecd2250 commit d1123a1

28 files changed

+4997
-128
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
default: test-all
44

55
uv-sync:
6-
@uv sync --all-packages
6+
@uv sync --all-packages 2> /dev/null
77

88
check: test doctest
99
@uv run ruff check -q packages/

packages/overture-schema-annex/pyproject.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
[project]
2-
dependencies = [
3-
"overture-schema-core",
4-
"pydantic>=2.0",
5-
]
2+
dependencies = ["overture-schema-core", "pydantic>=2.0"]
63
description = "Add your description here"
74
dynamic = ["version"]
85
license = "MIT"
@@ -24,7 +21,7 @@ path = "src/overture/schema/__about__.py"
2421
packages = ["src/overture"]
2522

2623
[project.entry-points."overture.models"]
27-
"sources.sources" = "overture.schema.annex.models:Sources"
24+
"annex:sources" = "overture.schema.annex:Sources"
2825

2926
[tool.pytest.ini_options]
3027
pythonpath = ["src"]

packages/overture-schema-annex/src/overture/schema/annex/__main__.py

Lines changed: 0 additions & 122 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# overture-schema-cli
2+
3+
Command-line interface for validating and working with Overture Maps schema.
4+
5+
This package provides the `overture-schema` command for validating GeoJSON and YAML files against Overture Maps schemas.
6+
7+
## Installation
8+
9+
```bash
10+
pip install overture-schema-cli
11+
```
12+
13+
## Usage
14+
15+
```bash
16+
overture-schema validate <file>
17+
```
18+
19+
See the main [overture-schema](https://github.com/OvertureMaps/schema) documentation for more details.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[project]
2+
dependencies = [
3+
"overture-schema-core",
4+
"pydantic>=2.0",
5+
"pyyaml>=6.0.2",
6+
"click>=8.0",
7+
"rich>=13.0",
8+
"yamlcore>=0.0.4",
9+
]
10+
description = "Command-line interface for Overture Maps schema validation and JSON Schema generation"
11+
dynamic = ["version"]
12+
license = "MIT"
13+
name = "overture-schema-cli"
14+
readme = "README.md"
15+
requires-python = ">=3.10"
16+
17+
[tool.uv.sources]
18+
overture-schema-core = { workspace = true }
19+
20+
[build-system]
21+
build-backend = "hatchling.build"
22+
requires = ["hatchling"]
23+
24+
[dependency-groups]
25+
dev = [
26+
"pytest>=7.0",
27+
"ruff",
28+
"mypy",
29+
]
30+
31+
[tool.hatch.version]
32+
path = "src/overture/schema/cli/__about__.py"
33+
34+
[tool.hatch.build.targets.wheel]
35+
packages = ["src/overture"]
36+
37+
[project.scripts]
38+
overture-schema = "overture.schema.cli:cli"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.1.0"
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""CLI subpackage for overture-schema."""
2+
3+
from .commands import (
4+
cli,
5+
create_union_type_from_models,
6+
handle_generic_error,
7+
handle_validation_error,
8+
load_input,
9+
perform_validation,
10+
resolve_types,
11+
)
12+
from .types import (
13+
ErrorLocation,
14+
ModelDict,
15+
UnionType,
16+
ValidationErrorDict,
17+
)
18+
19+
__all__ = [
20+
"cli",
21+
"create_union_type_from_models",
22+
"handle_generic_error",
23+
"handle_validation_error",
24+
"load_input",
25+
"perform_validation",
26+
"resolve_types",
27+
"ErrorLocation",
28+
"ModelDict",
29+
"UnionType",
30+
"ValidationErrorDict",
31+
]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Support for python -m overture.schema.cli."""
2+
3+
from .commands import cli
4+
5+
if __name__ == "__main__":
6+
cli()

0 commit comments

Comments
 (0)