Skip to content

Commit fecc4a7

Browse files
authored
Merge 19edc2c into 661de57
2 parents 661de57 + 19edc2c commit fecc4a7

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3131

3232
### Fixes
3333

34+
- Endpoint tags are now sanitized during parsing to fix an issue where `My Tag` and `MyTag` are seen as two different tags but are then later unified, causing errors when creating directories. Thanks @p1-ra! (#328)
3435
- Parser will softly ignore value error during schema responses' status code convertion from string to integer (not a number). Errors will be reported to the end user and parsing will continue to proceed (#327).
3536
- The generated `from_dict` and `to_dict` methods of models will now properly handle `nullable` and `not required` properties that are themselves generated models (#315). Thanks @forest-benchling!
3637
- Fix deserialization of `None` and `Unset` properties for all types by unifying the checks (#334). Thanks @forest-benchling!

openapi_python_client/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ def _build_api(self) -> None:
235235

236236
endpoint_template = self.env.get_template("endpoint_module.py.jinja")
237237
for tag, collection in self.openapi.endpoint_collections_by_tag.items():
238-
tag = utils.snake_case(tag)
239238
tag_dir = api_dir / tag
240239
tag_dir.mkdir()
241240
(tag_dir / "__init__.py").touch()

openapi_python_client/parser/openapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def from_data(
4848
operation: Optional[oai.Operation] = getattr(path_data, method)
4949
if operation is None:
5050
continue
51-
tag = (operation.tags or ["default"])[0]
51+
tag = utils.snake_case((operation.tags or ["default"])[0])
5252
collection = endpoints_by_tag.setdefault(tag, EndpointCollection(tag=tag))
5353
endpoint, schemas = Endpoint.from_data(
5454
data=operation, path=path, method=method, tag=tag, schemas=schemas

tests/test_parser/test_openapi.py

+48
Original file line numberDiff line numberDiff line change
@@ -829,3 +829,51 @@ def test_from_data_errors(self, mocker):
829829
assert result["default"].parse_errors[1].data == "3"
830830
assert result["tag_2"].parse_errors[0].data == "2"
831831
assert result_schemas == schemas_3
832+
833+
def test_from_data_tags_snake_case_sanitizer(self, mocker):
834+
from openapi_python_client.parser.openapi import Endpoint, EndpointCollection
835+
836+
path_1_put = oai.Operation.construct()
837+
path_1_post = oai.Operation.construct(tags=["AMF Subscription Info (Document)", "tag_3"])
838+
path_2_get = oai.Operation.construct()
839+
data = {
840+
"path_1": oai.PathItem.construct(post=path_1_post, put=path_1_put),
841+
"path_2": oai.PathItem.construct(get=path_2_get),
842+
}
843+
endpoint_1 = mocker.MagicMock(autospec=Endpoint, tag="default", relative_imports={"1", "2"})
844+
endpoint_2 = mocker.MagicMock(autospec=Endpoint, tag="AMFSubscriptionInfo (Document)", relative_imports={"2"})
845+
endpoint_3 = mocker.MagicMock(autospec=Endpoint, tag="default", relative_imports={"2", "3"})
846+
schemas_1 = mocker.MagicMock()
847+
schemas_2 = mocker.MagicMock()
848+
schemas_3 = mocker.MagicMock()
849+
endpoint_from_data = mocker.patch.object(
850+
Endpoint,
851+
"from_data",
852+
side_effect=[(endpoint_1, schemas_1), (endpoint_2, schemas_2), (endpoint_3, schemas_3)],
853+
)
854+
schemas = mocker.MagicMock()
855+
856+
result = EndpointCollection.from_data(data=data, schemas=schemas)
857+
858+
endpoint_from_data.assert_has_calls(
859+
[
860+
mocker.call(data=path_1_put, path="path_1", method="put", tag="default", schemas=schemas),
861+
mocker.call(
862+
data=path_1_post,
863+
path="path_1",
864+
method="post",
865+
tag="amf_subscription_info_document",
866+
schemas=schemas_1,
867+
),
868+
mocker.call(data=path_2_get, path="path_2", method="get", tag="default", schemas=schemas_2),
869+
],
870+
)
871+
assert result == (
872+
{
873+
"default": EndpointCollection("default", endpoints=[endpoint_1, endpoint_3]),
874+
"amf_subscription_info_document": EndpointCollection(
875+
"amf_subscription_info_document", endpoints=[endpoint_2]
876+
),
877+
},
878+
schemas_3,
879+
)

0 commit comments

Comments
 (0)