diff --git a/src/openjd/cli/_common/_validation_utils.py b/src/openjd/cli/_common/_validation_utils.py index 9b051ff..19a0f62 100644 --- a/src/openjd/cli/_common/_validation_utils.py +++ b/src/openjd/cli/_common/_validation_utils.py @@ -15,11 +15,12 @@ def get_doc_type(filepath: Path) -> DocumentType: + # If the file has a .json extension, treat it strictly + # as JSON, otherwise treat it as YAML. if filepath.suffix.lower() == ".json": return DocumentType.JSON - elif filepath.suffix.lower() in (".yaml", ".yml"): + else: return DocumentType.YAML - raise RuntimeError(f"'{str(filepath)}' is not JSON or YAML.") def read_template(template_file: Path) -> dict[str, Any]: diff --git a/test/openjd/cli/test_common.py b/test/openjd/cli/test_common.py index ad21193..dad8dab 100644 --- a/test/openjd/cli/test_common.py +++ b/test/openjd/cli/test_common.py @@ -50,6 +50,7 @@ def template_dir_and_cwd(): [ pytest.param(".template.json", json.dump, id="Successful JSON"), pytest.param(".template.yaml", yaml.dump, id="Successful YAML"), + pytest.param(".ojdt", yaml.dump, id="Successful YAML with alternate extension"), ], ) def test_read_template_success(tempfile_extension: str, doc_serializer: Callable): @@ -119,6 +120,12 @@ def test_read_template_fileerror( 'specificationVersion: "jobtemplate-2023-09"\n', id="YAML missing field", ), + pytest.param( + # Extensions other than .json are treated as YAML + ".template.ojdt", + 'specificationVersion: "jobtemplate-2023-09"\n', + id="YAML missing field", + ), ], ) def test_read_job_template_parsingerror(tempfile_extension: str, file_contents: str): @@ -152,6 +159,12 @@ def test_read_job_template_parsingerror(tempfile_extension: str, file_contents: 'specificationVersion: "environment-2023-09"\n', id="YAML missing field", ), + pytest.param( + # Extensions other than .json are treated as YAML + ".template.ojde", + 'specificationVersion: "environment-2023-09"\n', + id="YAML missing field", + ), ], ) def test_read_environment_template_parsingerror(tempfile_extension: str, file_contents: str): @@ -243,15 +256,6 @@ def test_get_job_params_success(mock_param_args: list[str], expected_param_value "is not a file", id="Parameter filepath is not a file", ), - pytest.param( - ["file://some-image.png"], - True, - True, - "some-image.png", - None, - "is not JSON or YAML", - id="Parameter filepath is not JSON/YAML", - ), pytest.param( ["file://forbidden-file.json"], True,