From eab519aa9e6a2c8eb76c073c639a27d42508af48 Mon Sep 17 00:00:00 2001 From: "n.shokurov" Date: Mon, 13 Jul 2026 19:15:48 +0300 Subject: [PATCH 1/3] fix --- datacontract/export/protobuf_exporter.py | 16 +++++++++++++++- tests/test_export_protobuf.py | 6 +++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/datacontract/export/protobuf_exporter.py b/datacontract/export/protobuf_exporter.py index 2265f53bd..427246bc4 100644 --- a/datacontract/export/protobuf_exporter.py +++ b/datacontract/export/protobuf_exporter.py @@ -31,6 +31,20 @@ def _get_logical_type_option(prop: SchemaProperty, key: str): return prop.logicalTypeOptions.get(key) +def _get_proto_package_name(data_contract: OpenDataContractStandard) -> str: + """ + Returns the Protobuf package name from the contract's description customProperties + ("proto_package_name"), falling back to "example". + """ + description = data_contract.description + if description is None or description.customProperties is None: + return "example" + for cp in description.customProperties: + if cp.property == "proto_package_name" and cp.value: + return cp.value + return "example" + + def to_protobuf(data_contract: OpenDataContractStandard) -> str: """ Generates a Protobuf file from the data contract specification. @@ -58,7 +72,7 @@ def to_protobuf(data_contract: OpenDataContractStandard) -> str: # Build header with syntax and package declarations. header = 'syntax = "proto3";\n\n' - package = "example" # Default package, can be customized + package: str = _get_proto_package_name(data_contract) header += f"package {package};\n\n" # Append enum definitions before messages. diff --git a/tests/test_export_protobuf.py b/tests/test_export_protobuf.py index 407325f3a..84d92ebff 100644 --- a/tests/test_export_protobuf.py +++ b/tests/test_export_protobuf.py @@ -19,6 +19,10 @@ def test_to_protobuf(): kind: DataContract apiVersion: v3.1.0 id: test_protobuf +description: + customProperties: + - property: proto_package_name + value: com.example.product schema: - name: Product description: Details of Product. @@ -83,7 +87,7 @@ def test_to_protobuf(): expected_protobuf = """ syntax = "proto3"; -package example; +package com.example.product; // Enum for Category enum Category { From 3f2b4ad1b5ed332fc712229e2bf88b9ecbc81363 Mon Sep 17 00:00:00 2001 From: "n.shokurov" Date: Tue, 14 Jul 2026 21:27:13 +0300 Subject: [PATCH 2/3] fix --- datacontract/export/protobuf_exporter.py | 11 +++++------ tests/test_export_protobuf.py | 7 +++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/datacontract/export/protobuf_exporter.py b/datacontract/export/protobuf_exporter.py index 427246bc4..bf3602690 100644 --- a/datacontract/export/protobuf_exporter.py +++ b/datacontract/export/protobuf_exporter.py @@ -33,14 +33,13 @@ def _get_logical_type_option(prop: SchemaProperty, key: str): def _get_proto_package_name(data_contract: OpenDataContractStandard) -> str: """ - Returns the Protobuf package name from the contract's description customProperties - ("proto_package_name"), falling back to "example". + Returns the Protobuf package name from the contract's customProperties + ("protoPackageName"), falling back to "example". """ - description = data_contract.description - if description is None or description.customProperties is None: + if data_contract.customProperties is None: return "example" - for cp in description.customProperties: - if cp.property == "proto_package_name" and cp.value: + for cp in data_contract.customProperties: + if cp.property == "protoPackageName" and cp.value: return cp.value return "example" diff --git a/tests/test_export_protobuf.py b/tests/test_export_protobuf.py index 84d92ebff..aefc21753 100644 --- a/tests/test_export_protobuf.py +++ b/tests/test_export_protobuf.py @@ -19,10 +19,9 @@ def test_to_protobuf(): kind: DataContract apiVersion: v3.1.0 id: test_protobuf -description: - customProperties: - - property: proto_package_name - value: com.example.product +customProperties: + - property: protoPackageName + value: com.example.product schema: - name: Product description: Details of Product. From 346afd863bd516a2e0e6d367bbcaf2b1f3685770 Mon Sep 17 00:00:00 2001 From: "n.shokurov" Date: Tue, 14 Jul 2026 21:29:17 +0300 Subject: [PATCH 3/3] fix --- docs/docs/exports/protobuf.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/docs/exports/protobuf.md b/docs/docs/exports/protobuf.md index 4da33e0bb..cfd47dc70 100644 --- a/docs/docs/exports/protobuf.md +++ b/docs/docs/exports/protobuf.md @@ -51,3 +51,25 @@ message LineItems { ``` {/* END AUTOGENERATED EXAMPLE */} + +## Configuration + +You can customize the generated Protobuf package name using the data contract's `customProperties`: + +```yaml +kind: DataContract +apiVersion: v3.1.0 +id: my-contract +version: 1.0.0 +customProperties: + - property: protoPackageName + value: com.example.mydata +schema: + - name: Orders + properties: + # ... fields ... +``` + +### Supported Properties + +- **`protoPackageName`** (optional) — The package name for the generated Protobuf file. Defaults to `"example"` if not specified.