Add basic support for all google.protobuf types
This commit is contained in:
parent
53ce1255d3
commit
2a3e1e1827
@ -88,6 +88,14 @@ def get_ref_type(
|
||||
cased = [stringcase.pascalcase(part) for part in parts]
|
||||
type_name = f'"{"".join(cased)}"'
|
||||
|
||||
# Use precompiled classes for google.protobuf.* objects
|
||||
if type_name.startswith("google.protobuf.") and type_name.count(".") == 2:
|
||||
type_name = type_name.rsplit(".", maxsplit=1)[1]
|
||||
import_package = "betterproto.lib.google.protobuf"
|
||||
import_alias = safe_snake_case(import_package)
|
||||
imports.add(f"import {import_package} as {import_alias}")
|
||||
return f"{import_alias}.{type_name}"
|
||||
|
||||
if "." in type_name:
|
||||
# This is imported from another package. No need
|
||||
# to use a forward ref and we need to add the import.
|
||||
|
@ -1,5 +1,7 @@
|
||||
{
|
||||
"maybe": false,
|
||||
"ts": "1972-01-01T10:00:20.021Z",
|
||||
"duration": "1.200s"
|
||||
"duration": "1.200s",
|
||||
"important": 10,
|
||||
"empty": {}
|
||||
}
|
||||
|
@ -3,10 +3,12 @@ syntax = "proto3";
|
||||
import "google/protobuf/duration.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
import "google/protobuf/empty.proto";
|
||||
|
||||
message Test {
|
||||
google.protobuf.BoolValue maybe = 1;
|
||||
google.protobuf.Timestamp ts = 2;
|
||||
google.protobuf.Duration duration = 3;
|
||||
google.protobuf.Int32Value important = 4;
|
||||
google.protobuf.Empty empty = 5;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user