Aiven-Open / Aiven-Open/karapace

When referring to other Protobuf schemas from a schema, only references are required and import statements are ignored.

オープン
#738 コメント 0 件 リアクション 1 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
634
フォーク
110
平均マージ
4日 7時間
マージ済み PR(30日)
4

説明

# What happened?

When creating a Protobuf schema with references, types from the referred schemas can be used even without actually importing them in the schema itself.

1. Create schema A by sending a POST request over `subjects/mySubjectA/versions` with the following body:
```json
{
"schema": "syntax = \"proto3\";\nmessage MyType {\n int32 id = 1;\n}",
"schemaType": "PROTOBUF"
}
```
2. Create schema B by sending a POST request over `subjects/mySubjectB/versions` with the following body:
```json
{
"schema": "syntax = \"proto3\";\nmessage MyRecord {\n string f1 = 1;\n MyType f2 = 2;\n}",
"schemaType": "PROTOBUF",
"references": [
{
"name": "mySubjectA",
"subject": "mySubjectA",
"version": 1
}
]
}
```

Creating schema succeeds without import statement.
Creating fails, if you remove the references.
This would imply that import statement is ignored and only the references are read.

# What did you expect to happen?

Creating schema would fail if types are used from the referred schema without actually importing.

The following test should throw an exception but doesn't:

```python3

def test_invalid_import() -> None:
plan = """\
syntax = "proto3";

package my.package;

message ExternalMessage {
string field = 1;
}
"""

customer_plan_event = """\
syntax = "proto3";

package another.package;

message CustomerPlanEvent {
message Created {
my.package.ExternalMessage message = 1;
}
}
"""

no_ref_schema = ValidatedTypedSchema.parse(SchemaType.PROTOBUF, plan)
dep = Dependency("this_is_ignored", Subject("this_also"), 1, no_ref_schema)
ref_schema = ValidatedTypedSchema.parse(SchemaType.PROTOBUF, customer_plan_event, None, {"foobar": dep})
```

We are apparently ignoring both the name and the subject and we are relying on the fact that the reference map is in sync with the import statements

# What else do we need to know?

Tested only with Protobuf schemas, did not try with other schema types.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。