-
-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(🎁) infer data vs schema when
--input-file-type
is auto (#1249)
* infer data vs schema when `--input-file-type` is auto * Improve is_schema conditions * Fix coverage * Fix is_schema * Improve coverage * Improve coverage * Improve coverage --------- Co-authored-by: KotlinIsland <[email protected]> Co-authored-by: Koudai Aono <[email protected]>
- Loading branch information
1 parent
083691c
commit 03eeddb
Showing
14 changed files
with
99 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"components": { | ||
"schemas": { | ||
"A": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openapi: "3.0.0" | ||
components: | ||
schemas: | ||
InventoryItem: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openapi: "3.0.0" | ||
schemas: | ||
Problem: | ||
properties: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openapi: "3.0.0" | ||
components: | ||
schemas: | ||
ObjectBase: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openapi: "3.0.0" | ||
components: | ||
schemas: | ||
ObjectBase: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
openapi: 3.0 | ||
openapi: "3.0.0" | ||
components: | ||
schemas: | ||
string: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from pathlib import Path | ||
|
||
from datamodel_code_generator import InputFileType, infer_input_type | ||
|
||
DATA_PATH: Path = Path(__file__).parent / 'data' | ||
|
||
|
||
def test_infer_input_type(): | ||
def assert_infer_input_type(file: Path, raw_data_type: InputFileType) -> None: | ||
__tracebackhide__ = True | ||
if file.is_dir(): | ||
return | ||
if file.suffix not in ('.yaml', '.json'): | ||
return | ||
result = infer_input_type(file.read_text()) | ||
assert result == raw_data_type, f'{file} was the wrong type!' | ||
|
||
for file in (DATA_PATH / 'json').rglob('*'): | ||
if str(file).endswith('broken.json'): | ||
continue | ||
assert_infer_input_type(file, InputFileType.Json) | ||
for file in (DATA_PATH / 'jsonschema').rglob('*'): | ||
if str(file).endswith(('external_child.json', 'external_child.yaml')): | ||
continue | ||
if 'reference_same_hierarchy_directory' in str(file): | ||
continue | ||
assert_infer_input_type(file, InputFileType.JsonSchema) | ||
for file in (DATA_PATH / 'openapi').rglob('*'): | ||
if str(file).endswith( | ||
( | ||
'aliases.json', | ||
'extra_data.json', | ||
'invalid.yaml', | ||
'list.json', | ||
'empty_data.json', | ||
'root_model.yaml', | ||
'json_pointer.yaml', | ||
'const.json', | ||
) | ||
): | ||
continue | ||
|
||
if str(file).endswith('not.json'): | ||
assert_infer_input_type(file, InputFileType.Json) | ||
continue | ||
assert_infer_input_type(file, InputFileType.OpenAPI) |