-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: #20: Fix KeyError: 'title' and related issues
- Loading branch information
Showing
5 changed files
with
210 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import pytest | ||
import typing as t | ||
from python_client_generator.utils import add_schema_title_if_missing | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"raw_schema, expected_schema", | ||
[ | ||
( | ||
{"X": {"type": "string", "enum": ["A", "B"]}}, | ||
{ | ||
"X": { | ||
"title": "X", | ||
"type": "string", | ||
"enum": ["A", "B"], | ||
} | ||
}, | ||
), # Should add title to enum schema | ||
( | ||
{ | ||
"X": { | ||
"type": "object", | ||
"properties": { | ||
"a": {"type": "string"}, | ||
"b": {"type": "string"}, | ||
}, | ||
} | ||
}, | ||
{ | ||
"X": { | ||
"title": "X", | ||
"type": "object", | ||
"properties": { | ||
"a": {"type": "string"}, | ||
"b": {"type": "string"}, | ||
}, | ||
} | ||
}, | ||
), # Should add title to object schema | ||
( | ||
{ | ||
"X": { | ||
"title": "X", | ||
"type": "string", | ||
"enum": ["A", "B"], | ||
} | ||
}, | ||
{ | ||
"X": { | ||
"title": "X", | ||
"type": "string", | ||
"enum": ["A", "B"], | ||
} | ||
}, | ||
), # Shouldn't fail if title is already present | ||
], | ||
) | ||
def test_add_schema_title_if_missing(raw_schema: t.Dict[str, t.Any], expected_schema) -> None: | ||
assert add_schema_title_if_missing(raw_schema) == expected_schema |