Skip to content

Commit

Permalink
fix: Deprecate minify CLI option
Browse files Browse the repository at this point in the history
  • Loading branch information
dblanchette committed Nov 29, 2024
1 parent c3856aa commit b428474
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 26 deletions.
3 changes: 1 addition & 2 deletions json_schema_for_humans/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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],
Expand All @@ -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,
Expand Down
9 changes: 3 additions & 6 deletions json_schema_for_humans/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
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,
link_to_reused_ref: bool = True,
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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
10 changes: 1 addition & 9 deletions json_schema_for_humans/generation_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -147,21 +146,14 @@ 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,
link_to_reused_ref=link_to_reused_ref,
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:
Expand Down
22 changes: 13 additions & 9 deletions tests/interface_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit b428474

Please sign in to comment.