diff --git a/karapace/protobuf/schema.py b/karapace/protobuf/schema.py index a0d91b1cb..576db1182 100644 --- a/karapace/protobuf/schema.py +++ b/karapace/protobuf/schema.py @@ -169,7 +169,12 @@ def _process_nested_type( one_of_parent_name = parent_name + "." + element_type.name process_one_of(verifier, package_name, one_of_parent_name, one_of) for field in element_type.fields: - verifier.add_used_type(parent_name, field.element_type) + # since we declare the subtype in the same level of the scope, it's legit + # use the same scoping when declare the dependent type. + if field.element_type in [defined_in_same_scope.name for defined_in_same_scope in element_type.nested_types]: + verifier.add_used_type(parent_name + "." + element_type.name, field.element_type) + else: + verifier.add_used_type(parent_name, field.element_type) for nested_type in element_type.nested_types: self._process_nested_type(verifier, package_name, parent_name + "." + element_type.name, nested_type) diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt index 3b2822d6b..50b7be256 100644 --- a/requirements/requirements-dev.txt +++ b/requirements/requirements-dev.txt @@ -123,7 +123,7 @@ multidict==6.0.4 # -r requirements.txt # aiohttp # yarl -networkx==2.8.8 +networkx==3.1 # via -r requirements.txt packaging==23.1 # via diff --git a/requirements/requirements.in b/requirements/requirements.in index 65b90c0ba..25bfad6b7 100644 --- a/requirements/requirements.in +++ b/requirements/requirements.in @@ -4,7 +4,7 @@ aiohttp<4 aiokafka<1 isodate<1 jsonschema<5 -networkx<3 +networkx<4 protobuf<4 python-dateutil<3 tenacity<9 diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 7112a7d12..273282c65 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -53,7 +53,7 @@ multidict==6.0.4 # via # aiohttp # yarl -networkx==2.8.8 +networkx==3.1 # via -r requirements.in packaging==23.1 # via aiokafka diff --git a/tests/integration/test_schema_protobuf.py b/tests/integration/test_schema_protobuf.py index 9a89a17cd..f81e03437 100644 --- a/tests/integration/test_schema_protobuf.py +++ b/tests/integration/test_schema_protobuf.py @@ -620,6 +620,24 @@ class ReferenceTestCase(BaseTestCase): } """ +SELF_REFERENCED_SCHEMA = """\ +syntax = "proto3"; + +package fancy.company.in.party.v1; +message MyFirstMessage { + string my_fancy_string = 1; +} +message AnotherMessage { + message WowANestedMessage { + enum BamFancyEnum { + // Hei! This is a comment! + MY_AWESOME_FIELD = 0; + } + BamFancyEnum im_tricky_im_referring_to_the_previous_enum = 1; + } +} +""" + @pytest.mark.parametrize( "testcase", @@ -1000,6 +1018,13 @@ async def test_references(testcase: ReferenceTestCase, registry_async_client: Cl assert fetch_schema_res.status_code == 200 +async def test_self_reference_schema(registry_async_client: Client) -> None: + body = {"schemaType": SchemaType.PROTOBUF, "schema": SELF_REFERENCED_SCHEMA} + res = await registry_async_client.post("subjects/self_referenced_schema_test/versions", json=body) + + assert res.status_code == 200 + + async def test_protobuf_error(registry_async_client: Client) -> None: testdata = TestCaseSchema( schema_type=SchemaType.PROTOBUF,