From 53ce1255d35f17a42aef69ad75c049975c1ca38f Mon Sep 17 00:00:00 2001 From: boukeversteegh Date: Fri, 29 May 2020 15:36:00 +0200 Subject: [PATCH] Do not unwrap google.protobuf.Value and unsupported wrapper types --- betterproto/plugin.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/betterproto/plugin.py b/betterproto/plugin.py index 3d9c1bb..4be1d21 100755 --- a/betterproto/plugin.py +++ b/betterproto/plugin.py @@ -1,13 +1,15 @@ #!/usr/bin/env python -from collections import defaultdict import itertools import os.path +import re import stringcase import sys import textwrap +from collections import defaultdict from typing import Dict, List, Optional, Type from betterproto.casing import safe_snake_case +import betterproto try: # betterproto[compiler] specific dependencies @@ -259,11 +261,13 @@ def generate_code(request, response): field_type = f.Type.Name(f.type).lower()[5:] field_wraps = "" - if f.type_name.startswith( - ".google.protobuf" - ) and f.type_name.endswith("Value"): - w = f.type_name.split(".").pop()[:-5].upper() - field_wraps = f"betterproto.TYPE_{w}" + match_wrapper = re.match( + "\\.google\\.protobuf\\.(.+)Value", f.type_name + ) + if match_wrapper: + wrapped_type = "TYPE_" + match_wrapper.group(1).upper() + if wrapped_type in dir(betterproto): + field_wraps = f"betterproto.{wrapped_type}" map_types = None if f.type == 11: