Repository: koxudaxi/datamodel-code-generator

Issue:
(🎁) Log input file type when when `--input-file-type` is `auto`
I was left a little confused when my json file was silently detected as jsonschema instead of json.


Discussion:
I agree. the CLI should show the detail of the error.

Resolving patch:
diff --git a/datamodel_code_generator/__init__.py b/datamodel_code_generator/__init__.py
--- a/datamodel_code_generator/__init__.py
+++ b/datamodel_code_generator/__init__.py
@@ -2,6 +2,7 @@
 
 import contextlib
 import os
+import sys
 from datetime import datetime, timezone
 from enum import Enum
 from pathlib import Path
@@ -308,6 +309,10 @@ def generate(
                 if is_openapi(input_text_)  # type: ignore
                 else InputFileType.JsonSchema
             )
+            print(
+                f'The input file type was determined to be: {input_file_type.value}',
+                file=sys.stderr,
+            )
         except:  # noqa
             raise Error('Invalid file format')
 


Test patch:
diff --git a/tests/test_main.py b/tests/test_main.py
--- a/tests/test_main.py
+++ b/tests/test_main.py
@@ -588,7 +588,7 @@ def test_main_no_file(capsys: CaptureFixture) -> None:
     assert (
         captured.out == (EXPECTED_MAIN_PATH / 'main_no_file' / 'output.py').read_text()
     )
-    assert not captured.err
+    assert captured.err == 'The input file type was determined to be: openapi\n'
 
 
 def test_main_extra_template_data_config(capsys: CaptureFixture) -> None:
@@ -614,7 +614,7 @@ def test_main_extra_template_data_config(capsys: CaptureFixture) -> None:
             EXPECTED_MAIN_PATH / 'main_extra_template_data_config' / 'output.py'
         ).read_text()
     )
-    assert not captured.err
+    assert captured.err == 'The input file type was determined to be: openapi\n'
 
 
 def test_main_custom_template_dir_old_style(capsys: CaptureFixture) -> None:
@@ -641,7 +641,7 @@ def test_main_custom_template_dir_old_style(capsys: CaptureFixture) -> None:
         captured.out
         == (EXPECTED_MAIN_PATH / 'main_custom_template_dir' / 'output.py').read_text()
     )
-    assert not captured.err
+    assert captured.err == 'The input file type was determined to be: openapi\n'
 
 
 def test_main_custom_template_dir(capsys: CaptureFixture) -> None:
@@ -668,7 +668,7 @@ def test_main_custom_template_dir(capsys: CaptureFixture) -> None:
         captured.out
         == (EXPECTED_MAIN_PATH / 'main_custom_template_dir' / 'output.py').read_text()
     )
-    assert not captured.err
+    assert captured.err == 'The input file type was determined to be: openapi\n'
 
 
 @freeze_time('2019-07-26')
diff --git a/tests/test_main_kr.py b/tests/test_main_kr.py
--- a/tests/test_main_kr.py
+++ b/tests/test_main_kr.py
@@ -146,7 +146,7 @@ def test_main_no_file(capsys: CaptureFixture) -> None:
         == (EXPECTED_MAIN_KR_PATH / 'main_no_file' / 'output.py').read_text()
     )
 
-    assert not captured.err
+    assert captured.err == 'The input file type was determined to be: openapi\n'
 
 
 def test_main_custom_template_dir(capsys: CaptureFixture) -> None:
@@ -175,7 +175,7 @@ def test_main_custom_template_dir(capsys: CaptureFixture) -> None:
             EXPECTED_MAIN_KR_PATH / 'main_custom_template_dir' / 'output.py'
         ).read_text()
     )
-    assert not captured.err
+    assert captured.err == 'The input file type was determined to be: openapi\n'
 
 
 @freeze_time('2019-07-26')