From 39fefd7f233c1a74ca0cd1ada518f30b4075d6e5 Mon Sep 17 00:00:00 2001 From: nitro-neal Date: Wed, 26 Oct 2022 20:14:19 -0500 Subject: [PATCH] Add required (#245) * fix postal address * change name * adding required * fix merge * Update credential/exchange/builder_test.go Co-authored-by: Gabe * AdditionalProperties * Update credential/exchange/builder_test.go * merge fix Co-authored-by: Gabe --- credential/exchange/builder_test.go | 55 +++++++++++++++++++++++++++++ credential/exchange/model.go | 32 +++++++++-------- 2 files changed, 72 insertions(+), 15 deletions(-) diff --git a/credential/exchange/builder_test.go b/credential/exchange/builder_test.go index 41358454..5295f03f 100644 --- a/credential/exchange/builder_test.go +++ b/credential/exchange/builder_test.go @@ -143,8 +143,63 @@ func TestInputDescriptorBuilderProperties(t *testing.T) { assert.NoError(t, err) definition, err := builder.Build() + assert.NotEmpty(t, definition) assert.NoError(t, err) +} + +func TestInputDescriptorBuilderRequired(t *testing.T) { + builder := NewPresentationDefinitionBuilder() + + b := []byte( + `{ + "addressCountry":{ + "type":"string" + }, + "addressLocality":{ + "type":"string" + }, + "addressRegion":{ + "type":"string" + }, + "postalCode":{ + "type":"string" + }, + "streetAddress":{ + "type":"string" + } + }`) + + var props interface{} + err := json.Unmarshal(b, &props) + assert.NoError(t, err) + + err = builder.SetInputDescriptors([]InputDescriptor{ + { + ID: uuid.NewString(), + Name: "children-info", + Constraints: &Constraints{ + Fields: []Field{ + { + Path: []string{"$.vc.credentialSubject.children[*].firstName", "$.credentialSubject.children[*].firstName"}, + ID: "children-info-first-name", + Filter: &Filter{ + Type: "string", + MinLength: 1, + Properties: props, + Required: []string{"postalCode, streetAddress"}, + AdditionalProperties: true, + }, + }, + }, + }, + }, + }) + + assert.NoError(t, err) + definition, err := builder.Build() assert.NotEmpty(t, definition) + assert.NoError(t, err) + } func TestInputDescriptorBuilder(t *testing.T) { diff --git a/credential/exchange/model.go b/credential/exchange/model.go index 1172e61c..01820e60 100644 --- a/credential/exchange/model.go +++ b/credential/exchange/model.go @@ -285,21 +285,23 @@ type RelationalConstraint struct { } type Filter struct { - Type string `json:"type,omitempty"` - Format string `json:"format,omitempty"` - Properties interface{} `json:"properties,omitempty"` - Pattern string `json:"pattern,omitempty"` - Minimum interface{} `json:"minimum,omitempty"` - Maximum interface{} `json:"maximum,omitempty"` - MinLength int `json:"minLength,omitempty"` - MaxLength int `json:"maxLength,omitempty"` - ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"` - ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"` - Const interface{} `json:"const,omitempty"` - Enum []interface{} `json:"enum,omitempty"` - Not interface{} `json:"not,omitempty"` - AllOf interface{} `json:"allOf,omitempty"` - OneOf interface{} `json:"oneOf,omitempty"` + Type string `json:"type,omitempty"` + Format string `json:"format,omitempty"` + Properties interface{} `json:"properties,omitempty"` + Required []string `json:"required,omitempty"` + AdditionalProperties bool `json:"additionalProperties,omitempty"` + Pattern string `json:"pattern,omitempty"` + Minimum interface{} `json:"minimum,omitempty"` + Maximum interface{} `json:"maximum,omitempty"` + MinLength int `json:"minLength,omitempty"` + MaxLength int `json:"maxLength,omitempty"` + ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"` + ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"` + Const interface{} `json:"const,omitempty"` + Enum []interface{} `json:"enum,omitempty"` + Not interface{} `json:"not,omitempty"` + AllOf interface{} `json:"allOf,omitempty"` + OneOf interface{} `json:"oneOf,omitempty"` } // CredentialStatus https://identity.foundation/presentation-exchange/#credential-status-constraint-feature