Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

Commit 39fefd7

Browse files
nitro-nealGabe
andauthored
Add required (#245)
* fix postal address * change name * adding required * fix merge * Update credential/exchange/builder_test.go Co-authored-by: Gabe <[email protected]> * AdditionalProperties * Update credential/exchange/builder_test.go * merge fix Co-authored-by: Gabe <[email protected]>
1 parent 50f3596 commit 39fefd7

File tree

2 files changed

+72
-15
lines changed

2 files changed

+72
-15
lines changed

credential/exchange/builder_test.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,63 @@ func TestInputDescriptorBuilderProperties(t *testing.T) {
143143

144144
assert.NoError(t, err)
145145
definition, err := builder.Build()
146+
assert.NotEmpty(t, definition)
146147
assert.NoError(t, err)
148+
}
149+
150+
func TestInputDescriptorBuilderRequired(t *testing.T) {
151+
builder := NewPresentationDefinitionBuilder()
152+
153+
b := []byte(
154+
`{
155+
"addressCountry":{
156+
"type":"string"
157+
},
158+
"addressLocality":{
159+
"type":"string"
160+
},
161+
"addressRegion":{
162+
"type":"string"
163+
},
164+
"postalCode":{
165+
"type":"string"
166+
},
167+
"streetAddress":{
168+
"type":"string"
169+
}
170+
}`)
171+
172+
var props interface{}
173+
err := json.Unmarshal(b, &props)
174+
assert.NoError(t, err)
175+
176+
err = builder.SetInputDescriptors([]InputDescriptor{
177+
{
178+
ID: uuid.NewString(),
179+
Name: "children-info",
180+
Constraints: &Constraints{
181+
Fields: []Field{
182+
{
183+
Path: []string{"$.vc.credentialSubject.children[*].firstName", "$.credentialSubject.children[*].firstName"},
184+
ID: "children-info-first-name",
185+
Filter: &Filter{
186+
Type: "string",
187+
MinLength: 1,
188+
Properties: props,
189+
Required: []string{"postalCode, streetAddress"},
190+
AdditionalProperties: true,
191+
},
192+
},
193+
},
194+
},
195+
},
196+
})
197+
198+
assert.NoError(t, err)
199+
definition, err := builder.Build()
147200
assert.NotEmpty(t, definition)
201+
assert.NoError(t, err)
202+
148203
}
149204

150205
func TestInputDescriptorBuilder(t *testing.T) {

credential/exchange/model.go

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -285,21 +285,23 @@ type RelationalConstraint struct {
285285
}
286286

287287
type Filter struct {
288-
Type string `json:"type,omitempty"`
289-
Format string `json:"format,omitempty"`
290-
Properties interface{} `json:"properties,omitempty"`
291-
Pattern string `json:"pattern,omitempty"`
292-
Minimum interface{} `json:"minimum,omitempty"`
293-
Maximum interface{} `json:"maximum,omitempty"`
294-
MinLength int `json:"minLength,omitempty"`
295-
MaxLength int `json:"maxLength,omitempty"`
296-
ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"`
297-
ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"`
298-
Const interface{} `json:"const,omitempty"`
299-
Enum []interface{} `json:"enum,omitempty"`
300-
Not interface{} `json:"not,omitempty"`
301-
AllOf interface{} `json:"allOf,omitempty"`
302-
OneOf interface{} `json:"oneOf,omitempty"`
288+
Type string `json:"type,omitempty"`
289+
Format string `json:"format,omitempty"`
290+
Properties interface{} `json:"properties,omitempty"`
291+
Required []string `json:"required,omitempty"`
292+
AdditionalProperties bool `json:"additionalProperties,omitempty"`
293+
Pattern string `json:"pattern,omitempty"`
294+
Minimum interface{} `json:"minimum,omitempty"`
295+
Maximum interface{} `json:"maximum,omitempty"`
296+
MinLength int `json:"minLength,omitempty"`
297+
MaxLength int `json:"maxLength,omitempty"`
298+
ExclusiveMinimum interface{} `json:"exclusiveMinimum,omitempty"`
299+
ExclusiveMaximum interface{} `json:"exclusiveMaximum,omitempty"`
300+
Const interface{} `json:"const,omitempty"`
301+
Enum []interface{} `json:"enum,omitempty"`
302+
Not interface{} `json:"not,omitempty"`
303+
AllOf interface{} `json:"allOf,omitempty"`
304+
OneOf interface{} `json:"oneOf,omitempty"`
303305
}
304306

305307
// CredentialStatus https://identity.foundation/presentation-exchange/#credential-status-constraint-feature

0 commit comments

Comments
 (0)