From b428474ba6eeee0c0dd66ce9ae842a4a46c3b3d6 Mon Sep 17 00:00:00 2001 From: Denis Blanchette Date: Fri, 29 Nov 2024 11:55:11 -0500 Subject: [PATCH] fix: Deprecate `minify` CLI option --- json_schema_for_humans/cli.py | 3 +-- json_schema_for_humans/generate.py | 9 +++----- .../generation_configuration.py | 10 +-------- tests/interface_test.py | 22 +++++++++++-------- 4 files changed, 18 insertions(+), 26 deletions(-) diff --git a/json_schema_for_humans/cli.py b/json_schema_for_humans/cli.py index 44e78613..c49caddd 100644 --- a/json_schema_for_humans/cli.py +++ b/json_schema_for_humans/cli.py @@ -23,7 +23,6 @@ help="Override generation parameters from the configuration file. " "Format is parameter_name=parameter_value. For example: --config minify=false. Can be repeated.", ) -@click.option("--minify/--no-minify", default=True, help="Run minification on the HTML result") @click.option( "--deprecated-from-description", is_flag=True, help="Look in the description to find if an attribute is deprecated" ) @@ -43,6 +42,7 @@ help="If set and 2 parts of the schema refer to the same definition, the definition will only be rendered once " "and all other references will be replaced by a link.", ) +@click.option("--minify/--no-minify", default=False, help="Deprecated") def main( schema_files_or_dir: str, output_path_or_file: Optional[Path], @@ -57,7 +57,6 @@ def main( link_to_reused_ref: bool, ) -> None: final_config = get_final_config( - minify=minify, deprecated_from_description=deprecated_from_description, default_from_description=default_from_description, expand_buttons=expand_buttons, diff --git a/json_schema_for_humans/generate.py b/json_schema_for_humans/generate.py index 2ddb515f..ccb6148e 100644 --- a/json_schema_for_humans/generate.py +++ b/json_schema_for_humans/generate.py @@ -14,7 +14,7 @@ def generate_from_schema( schema_file: Union[str, Path], loaded_schemas: Optional[Dict[str, Any]] = None, - minify: bool = True, + minify: bool = False, deprecated_from_description: bool = False, default_from_description: bool = False, expand_buttons: bool = False, @@ -22,7 +22,6 @@ def generate_from_schema( config: Optional[GenerationConfiguration] = None, ) -> str: config = config or get_final_config( - minify=minify, deprecated_from_description=deprecated_from_description, default_from_description=default_from_description, expand_buttons=expand_buttons, @@ -41,7 +40,7 @@ def generate_from_schema( def generate_from_filename( schema_file_name: Union[str, Path], result_file_name: str, - minify: bool = True, + minify: bool = False, deprecated_from_description: bool = False, default_from_description: bool = False, expand_buttons: bool = False, @@ -52,7 +51,6 @@ def generate_from_filename( ) -> None: """Generate the schema documentation from a filename""" config = config or get_final_config( - minify=minify, deprecated_from_description=deprecated_from_description, default_from_description=default_from_description, expand_buttons=expand_buttons, @@ -71,7 +69,7 @@ def generate_from_filename( def generate_from_file_object( schema_file: Union[FileLikeType, _TemporaryFileWrapper], result_file: Union[FileLikeType, _TemporaryFileWrapper], - minify: bool = True, + minify: bool = False, deprecated_from_description: bool = False, default_from_description: bool = False, expand_buttons: bool = False, @@ -84,7 +82,6 @@ def generate_from_file_object( result_file should be opened in write mode. """ config = config or get_final_config( - minify=minify, deprecated_from_description=deprecated_from_description, default_from_description=default_from_description, expand_buttons=expand_buttons, diff --git a/json_schema_for_humans/generation_configuration.py b/json_schema_for_humans/generation_configuration.py index eb980243..c177f100 100644 --- a/json_schema_for_humans/generation_configuration.py +++ b/json_schema_for_humans/generation_configuration.py @@ -133,7 +133,6 @@ def template_path(self) -> Path: def get_final_config( - minify: bool, deprecated_from_description: bool, default_from_description: bool, expand_buttons: bool, @@ -147,7 +146,6 @@ def get_final_config( final_config = _load_config(config) else: final_config = GenerationConfiguration( - minify=minify, deprecated_from_description=deprecated_from_description, default_from_description=default_from_description, expand_buttons=expand_buttons, @@ -155,13 +153,7 @@ def get_final_config( copy_css=copy_css, copy_js=copy_js, ) - if ( - not minify - or deprecated_from_description - or default_from_description - or expand_buttons - or not link_to_reused_ref - ): + if deprecated_from_description or default_from_description or expand_buttons or not link_to_reused_ref: logging.info(CONFIG_DEPRECATION_MESSAGE) if config_parameters: diff --git a/tests/interface_test.py b/tests/interface_test.py index 0b44ccab..54389688 100644 --- a/tests/interface_test.py +++ b/tests/interface_test.py @@ -157,41 +157,45 @@ def _assert_deprecation_message(caplog: LogCaptureFixture, must_be_present: bool assert CONFIG_DEPRECATION_MESSAGE not in log_records -@pytest.mark.parametrize("minify, expect_warning", [(True, False), (False, True)]) +@pytest.mark.parametrize("deprecated_from_description, expect_warning", [(True, True), (False, False)]) def test_generate_from_schema_deprecation_warning( - tmp_path: Path, caplog: LogCaptureFixture, minify: bool, expect_warning: bool + tmp_path: Path, caplog: LogCaptureFixture, deprecated_from_description: bool, expect_warning: bool ) -> None: caplog.set_level(logging.INFO) - generate_from_schema(get_test_case_path("basic"), minify=minify) + generate_from_schema(get_test_case_path("basic"), deprecated_from_description=deprecated_from_description) _assert_deprecation_message(caplog, expect_warning) -@pytest.mark.parametrize("minify, expect_warning", [(True, False), (False, True)]) +@pytest.mark.parametrize("deprecated_from_description, expect_warning", [(True, True), (False, False)]) def test_generate_from_file_object_deprecation_warning( - tmp_path: Path, caplog: LogCaptureFixture, minify: bool, expect_warning: bool + tmp_path: Path, caplog: LogCaptureFixture, deprecated_from_description: bool, expect_warning: bool ) -> None: result_file_path = tmp_path / "result_file.html" caplog.set_level(logging.INFO) with open(get_test_case_path("basic")) as test_case_fp: with result_file_path.open("w", encoding="utf-8") as result_write_fp: - generate_from_file_object(test_case_fp, result_write_fp, minify=minify) + generate_from_file_object( + test_case_fp, result_write_fp, deprecated_from_description=deprecated_from_description + ) _assert_deprecation_message(caplog, expect_warning) -@pytest.mark.parametrize("minify, expect_warning", [(True, False), (False, True)]) +@pytest.mark.parametrize("deprecated_from_description, expect_warning", [(True, True), (False, False)]) def test_generate_from_file_name_deprecation_warning( - tmp_path: Path, caplog: LogCaptureFixture, minify: bool, expect_warning: bool + tmp_path: Path, caplog: LogCaptureFixture, deprecated_from_description: bool, expect_warning: bool ) -> None: test_case_path = get_test_case_path("basic") result_path = tmp_path / "result_file.html" caplog.set_level(logging.INFO) - generate_from_filename(test_case_path, str(result_path.resolve()), minify=minify) + generate_from_filename( + test_case_path, str(result_path.resolve()), deprecated_from_description=deprecated_from_description + ) _assert_deprecation_message(caplog, expect_warning)