Skip to content

Commit

Permalink
feat: add support for checking uuid4 fields (#1972)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea authored Mar 12, 2024
1 parent 8fe6db9 commit d5f90a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gapic/schema/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from google.api import annotations_pb2 # type: ignore
from google.api import client_pb2
from google.api import field_behavior_pb2
from google.api import field_info_pb2
from google.api import http_pb2
from google.api import resource_pb2
from google.api import routing_pb2
Expand Down Expand Up @@ -307,6 +308,17 @@ def required(self) -> bool:
return (field_behavior_pb2.FieldBehavior.Value('REQUIRED') in
self.options.Extensions[field_behavior_pb2.field_behavior])

@property
def uuid4(self) -> bool:
"""
Return True if the format of this field is a Universally
Unique Identifier, version 4 field, False otherwise.
Returns:
bool: Whether this field is UUID4.
"""
return self.options.Extensions[field_info_pb2.field_info].format == field_info_pb2.FieldInfo.Format.Value("UUID4")

@property
def resource_reference(self) -> Optional[str]:
"""Return a resource reference type if it exists.
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/schema/wrappers/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import pytest

from google.api import field_behavior_pb2
from google.api import field_info_pb2
from google.api import resource_pb2
from google.cloud import extended_operations_pb2 as ex_ops_pb2
from google.protobuf import descriptor_pb2
Expand Down Expand Up @@ -140,6 +141,19 @@ def test_not_required():
assert not field.required


def test_uuid4():
field = make_field()
field.options.Extensions[field_info_pb2.field_info].format = field_info_pb2.FieldInfo.Format.Value(
"UUID4"
)
assert field.uuid4


def test_not_uuid4():
field = make_field()
assert not field.uuid4


def test_ident_sphinx():
field = make_field(type='TYPE_BOOL')
assert field.ident.sphinx == 'bool'
Expand Down

0 comments on commit d5f90a2

Please sign in to comment.