Skip to content

Commit

Permalink
The scope of this pr is to replace the old parsing strategy and move …
Browse files Browse the repository at this point in the history
…towards a tree based type verification strategy.

From this commit it's possible to refer to a type using a partial path and not only a fully specified path. If we declare for e.g. the following schema:
```protobuf
syntax = "proto3";

package my.awesome.customer.plan.entity.v1beta1;

message CustomerPlan {
  string plan_name = 1;
}
```

When importing it it's sufficient to use a part of the full specified path (that in this case would be `my.awesome.customer.plan.entity.v1beta1.CustomerPlan`). As e.g. it would be enough to use `entity.v1beta1.CustomerPlan` or `v1beta1.CustomerPlan`, so the following declaration would be accepted:
```protobuf
syntax = "proto3";

package my.awesome.customer.plan.entity.v1beta1;
import "my/awesome/customer/plan/entity/v1beta1/entity.proto";

message CustomerPlanEvent {
  message Created {
    entity.v1beta1.CustomerPlan plan = 1;
  }
}
```
  • Loading branch information
eliax1996 committed Oct 17, 2023
1 parent 8a4ff32 commit 04bff10
Show file tree
Hide file tree
Showing 9 changed files with 630 additions and 227 deletions.
83 changes: 0 additions & 83 deletions karapace/protobuf/dependency.py

This file was deleted.

39 changes: 17 additions & 22 deletions karapace/protobuf/known_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,26 +107,21 @@ def static_init(cls) -> None:
cls.index_simple[item] = key


@static_init
class DependenciesHardcoded:
index: Set = set()

@classmethod
def static_init(cls) -> None:
cls.index = {
"bool",
"bytes",
"double",
"float",
"fixed32",
"fixed64",
"int32",
"int64",
"sfixed32",
"sfixed64",
"sint32",
"sint64",
"string",
"uint32",
"uint64",
}
index: Set[str] = {
"bool",
"bytes",
"double",
"float",
"fixed32",
"fixed64",
"int32",
"int64",
"sfixed32",
"sfixed64",
"sint32",
"sint64",
"string",
"uint32",
"uint64",
}
21 changes: 14 additions & 7 deletions karapace/protobuf/proto_file_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
from karapace.dependency import Dependency
from karapace.protobuf.compare_result import CompareResult, Modification
from karapace.protobuf.compare_type_storage import CompareTypes
from karapace.protobuf.extend_element import ExtendElement
from karapace.protobuf.location import Location
from karapace.protobuf.option_element import OptionElement
from karapace.protobuf.service_element import ServiceElement
from karapace.protobuf.syntax import Syntax
from karapace.protobuf.type_element import TypeElement
from typing import Dict, List, Optional
from typing import Dict, List, NewType, Optional


def _collect_dependencies_types(compare_types: CompareTypes, dependencies: Optional[Dict[str, Dependency]], is_self: bool):
Expand All @@ -29,18 +32,22 @@ def _collect_dependencies_types(compare_types: CompareTypes, dependencies: Optio
_collect_dependencies_types(compare_types, sub_deps, is_self)


TypeName = NewType("TypeName", str)
PackageName = NewType("PackageName", str)


class ProtoFileElement:
def __init__(
self,
location: Location,
package_name: Optional[str] = None,
package_name: Optional[PackageName] = None,
syntax: Optional[Syntax] = None,
imports: Optional[list] = None,
public_imports: Optional[list] = None,
imports: Optional[List[TypeName]] = None,
public_imports: Optional[List[TypeName]] = None,
types: Optional[List[TypeElement]] = None,
services: Optional[list] = None,
extend_declarations: Optional[list] = None,
options: Optional[list] = None,
services: Optional[List[ServiceElement]] = None,
extend_declarations: Optional[List[ExtendElement]] = None,
options: Optional[List[OptionElement]] = None,
) -> None:
if types is None:
types = list()
Expand Down
Loading

0 comments on commit 04bff10

Please sign in to comment.