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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.

The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [v2.4.3] - 2022-03-10
### Changed

- Add schema caching

## [v2.4.2] - 2022-03-02
### Changed

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

__version__ = "2.4.2"
__version__ = "2.4.3"

with open("README.md", "r") as fh:
long_description = fh.read()
Expand All @@ -28,8 +28,8 @@
keywords="STAC validation raster",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/sparkgeo/stac-validator",
download_url="https://github.com/sparkgeo/stac-validator/archive/v2.3.0.tar.gz",
url="https://github.com/stac-utils/stac-validator",
download_url="https://github.com/stac-utils/stac-validator/archive/v2.4.3.tar.gz",
install_requires=[
"requests>=2.19.1",
"jsonschema>=3.2.0",
Expand Down
6 changes: 6 additions & 0 deletions stac_validator/utilities.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import json
from urllib.parse import urlparse
from urllib.request import urlopen
Expand Down Expand Up @@ -56,6 +57,11 @@ def fetch_and_parse_file(input_path) -> dict:
return data


@functools.lru_cache(maxsize=48)
def fetch_and_parse_schema(input_path) -> dict:
return fetch_and_parse_file(input_path)


# validate new versions at schemas.stacspec.org
def set_schema_addr(version, stac_type: str):
if version in NEW_VERSIONS:
Expand Down
7 changes: 4 additions & 3 deletions stac_validator/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .utilities import (
fetch_and_parse_file,
fetch_and_parse_schema,
get_stac_type,
link_request,
set_schema_addr,
Expand Down Expand Up @@ -150,15 +151,15 @@ def extensions_validator(self, stac_type: str) -> dict:
def custom_validator(self):
# in case the path to custom json schema is local
# it may contain relative references
schema = fetch_and_parse_file(self.custom)
schema = fetch_and_parse_schema(self.custom)
if os.path.exists(self.custom):
custom_abspath = os.path.abspath(self.custom)
custom_dir = os.path.dirname(custom_abspath).replace("\\", "/")
custom_uri = f"file:///{custom_dir}/"
resolver = RefResolver(custom_uri, self.custom)
jsonschema.validate(self.stac_content, schema, resolver=resolver)
else:
schema = fetch_and_parse_file(self.custom)
schema = fetch_and_parse_schema(self.custom)
jsonschema.validate(self.stac_content, schema)

def core_validator(self, stac_type: str):
Expand Down Expand Up @@ -233,7 +234,7 @@ def recursive_validator(self, stac_type: str):
self.custom = set_schema_addr(self.version, stac_type.lower())
message = self.create_message(stac_type, "recursive")
if self.version == "0.7.0":
schema = fetch_and_parse_file(self.custom)
schema = fetch_and_parse_schema(self.custom)
# this next line prevents this: unknown url type: 'geojson.json' ??
schema["allOf"] = [{}]
jsonschema.validate(self.stac_content, schema)
Expand Down