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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ lint:
# Linter performs static analysis to catch latent bugs
pylint --rcfile .pylintrc samtranslator
# Ensure templates adhere to JSON schema
bin/validate.sh
bin/validate_schema.py

prepare-companion-stack:
pytest -v --no-cov integration/setup -m setup
Expand Down
8 changes: 0 additions & 8 deletions bin/validate.sh

This file was deleted.

46 changes: 46 additions & 0 deletions bin/validate_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python

import json
from pathlib import Path
from typing import Iterator

from cfn_flip import to_json # type: ignore
from jsonschema import validate

SCHEMA = json.loads(Path("samtranslator/schema/schema.json").read_bytes())


def get_templates() -> Iterator[Path]:
paths = (
list(Path("tests/translator/input").glob("**/*.yaml"))
+ list(Path("tests/translator/input").glob("**/*.yml"))
+ list(Path("integration/resources/templates").glob("**/*.yaml"))
+ list(Path("integration/resources/templates").glob("**/*.yml"))
)
# TODO: Enable (most likely) everything but error_
skips = [
"error_",
"unsupported_resources",
"resource_with_invalid_type",
]

def should_skip(s: str) -> bool:
for skip in skips:
if skip in s:
return True
return False

for path in paths:
if not should_skip(str(path)):
yield path


def main() -> None:
for path in get_templates():
print(f"Checking {path}")
obj = json.loads(to_json(path.read_bytes()))
validate(obj, schema=SCHEMA)


if __name__ == "__main__":
main()