Skip to content

Commit

Permalink
Merge pull request #1430 from shaangill025/issue_1427
Browse files Browse the repository at this point in the history
DIF Pres Exch Updates
  • Loading branch information
ianco authored Nov 8, 2021
2 parents dbb11db + 4530f54 commit 576bcad
Show file tree
Hide file tree
Showing 12 changed files with 2,635 additions and 159 deletions.
84 changes: 79 additions & 5 deletions aries_cloudagent/protocols/present_proof/dif/pres_exch.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class Meta:
_from = fields.Str(description="From", required=False, data_key="from")
# Self References
from_nested = fields.List(
fields.Nested(lambda: SubmissionRequirementsSchema(exclude=("from_nested",))),
fields.Nested(lambda: SubmissionRequirementsSchema()),
required=False,
)

Expand Down Expand Up @@ -180,7 +180,7 @@ def __init__(
uri: str = None,
required: bool = None,
):
"""Initialize InputDescriptors."""
"""Initialize SchemaInputDescriptor."""
self.uri = uri
self.required = required

Expand All @@ -201,6 +201,59 @@ class Meta:
required = fields.Bool(description="Required", required=False)


class SchemasInputDescriptorFilter(BaseModel):
"""SchemasInputDescriptorFilter."""

class Meta:
"""InputDescriptor Schemas filter metadata."""

schema_class = "SchemasInputDescriptorFilterSchema"

def __init__(
self,
*,
oneof_filter: bool = False,
uri_groups: Sequence[Sequence[SchemaInputDescriptor]] = None,
):
"""Initialize SchemasInputDescriptorFilter."""
self.oneof_filter = oneof_filter
self.uri_groups = uri_groups


class SchemasInputDescriptorFilterSchema(BaseModelSchema):
"""Single SchemasInputDescriptorFilterSchema Schema."""

class Meta:
"""SchemasInputDescriptorFilterSchema metadata."""

model_class = SchemasInputDescriptorFilter
unknown = EXCLUDE

uri_groups = fields.List(fields.List(fields.Nested(SchemaInputDescriptorSchema)))
oneof_filter = fields.Bool(description="oneOf")

@pre_load
def extract_info(self, data, **kwargs):
"""deserialize."""
new_data = {}
if isinstance(data, dict):
if "oneof_filter" in data:
new_data["oneof_filter"] = True
uri_group_list_of_list = []
uri_group_list = data.get("oneof_filter")
for uri_group in uri_group_list:
if isinstance(uri_group, list):
uri_group_list_of_list.append(uri_group)
else:
uri_group_list_of_list.append([uri_group])
new_data["uri_groups"] = uri_group_list_of_list
elif isinstance(data, list):
new_data["oneof_filter"] = False
new_data["uri_groups"] = [data]
data = new_data
return data


class DIFHolder(BaseModel):
"""Single Holder object for Constraints."""

Expand Down Expand Up @@ -548,7 +601,7 @@ def __init__(
purpose: str = None,
metadata: dict = None,
constraint: Constraints = None,
schemas: Sequence[SchemaInputDescriptor] = None,
schemas: SchemasInputDescriptorFilter = None,
):
"""Initialize InputDescriptors."""
self.id = id
Expand Down Expand Up @@ -584,8 +637,29 @@ class Meta:
constraint = fields.Nested(
ConstraintsSchema, required=False, data_key="constraints"
)
schemas = fields.List(
fields.Nested(SchemaInputDescriptorSchema), required=False, data_key="schema"
schemas = fields.Nested(
SchemasInputDescriptorFilterSchema,
required=False,
data_key="schema",
description=(
"Accepts a list of schema or a dict containing filters like oneof_filter."
),
example=(
{
"oneOf": [
[
{"uri": "https://www.w3.org/Test1#Test1"},
{"uri": "https://www.w3.org/Test2#Test2"},
],
{
"oneof_filter": [
[{"uri": "https://www.w3.org/Test1#Test1"}],
[{"uri": "https://www.w3.org/Test2#Test2"}],
]
},
]
}
),
)


Expand Down
Loading

0 comments on commit 576bcad

Please sign in to comment.