Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Aug 6, 2024
1 parent 99319d0 commit 6babea0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 75 deletions.
21 changes: 21 additions & 0 deletions doc/ld/validator/testdata/extended_model.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"%s"
],
"id": "http://example.com/credentials/4643",
"type": [
"VerifiableCredential",
"CustomExt12"
],
"issuer": "https://example.com/issuers/14",
"issuanceDate": "2018-02-24T05:28:04Z",
"referenceNumber": 83294847,
"credentialSubject": [
{
"id": "did:example:abcdef1234567",
"name": "Jane Doe",
"favoriteFood": "Papaya"
}
]
}
12 changes: 12 additions & 0 deletions doc/ld/validator/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package validator

// Diff represents the difference between two objects.
type Diff struct {
OriginalValue interface{}
CompactedValue interface{}
}
9 changes: 3 additions & 6 deletions doc/ld/validator/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func WithDocumentLoader(jsonldDocumentLoader ld.DocumentLoader) ValidateOpts {
}
}

// WithJSONLDIncludeDetailedStructureDiffOnError option is for including detailed structure diff in error message.
func WithJSONLDIncludeDetailedStructureDiffOnError() ValidateOpts {
return func(opts *validateOpts) {
opts.jsonldIncludeDetailedStructureDiffOnError = true
Expand Down Expand Up @@ -105,7 +106,7 @@ func ValidateJSONLDMap(docMap map[string]interface{}, options ...ValidateOpts) e
errText := "JSON-LD doc has different structure after compaction"

if opts.jsonldIncludeDetailedStructureDiffOnError {
diff, _ := json2.Marshal(mapDiff)
diff, _ := json2.Marshal(mapDiff) // nolint:errcheck

errText = fmt.Sprintf("%s. Details: %v", errText, string(diff))
}
Expand Down Expand Up @@ -153,11 +154,7 @@ func validateContextURIPosition(contextURIPositions []string, docMap map[string]
return nil
}

type Diff struct {
OriginalValue interface{}
CompactedValue interface{}
}

// nolint: gocyclo
func mapsHaveSameStructure(
originalMap,
compactedMap map[string]interface{},
Expand Down
75 changes: 6 additions & 69 deletions doc/ld/validator/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var (

//go:embed testdata/context/wallet_v1.jsonld
walletV1Context []byte

//go:embed testdata/extended_model.json
extendedModel string
)

func Test_ValidateJSONLD(t *testing.T) {
Expand Down Expand Up @@ -187,29 +190,7 @@ func Test_ValidateJSONLDWithExtraUndefinedSubjectFields(t *testing.T) {
t.Run("Extended basic VC model, credentialSubject is defined as object - undefined fields present",
func(t *testing.T) {
// Use a different VC to verify the case when credentialSubject is an array.
vcJSONTemplate := `
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"%s"
],
"id": "http://example.com/credentials/4643",
"type": [
"VerifiableCredential",
"CustomExt12"
],
"issuer": "https://example.com/issuers/14",
"issuanceDate": "2018-02-24T05:28:04Z",
"referenceNumber": 83294847,
"credentialSubject": [
{
"id": "did:example:abcdef1234567",
"name": "Jane Doe",
"favoriteFood": "Papaya"
}
]
}
`
vcJSONTemplate := extendedModel

vcJSON := fmt.Sprintf(vcJSONTemplate, contextURL)

Expand All @@ -221,29 +202,7 @@ func Test_ValidateJSONLDWithExtraUndefinedSubjectFields(t *testing.T) {
t.Run("Extended basic VC model, credentialSubject is defined as object - undefined fields present and details",
func(t *testing.T) {
// Use a different VC to verify the case when credentialSubject is an array.
vcJSONTemplate := `
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"%s"
],
"id": "http://example.com/credentials/4643",
"type": [
"VerifiableCredential",
"CustomExt12"
],
"issuer": "https://example.com/issuers/14",
"issuanceDate": "2018-02-24T05:28:04Z",
"referenceNumber": 83294847,
"credentialSubject": [
{
"id": "did:example:abcdef1234567",
"name": "Jane Doe",
"favoriteFood": "Papaya"
}
]
}
`
vcJSONTemplate := extendedModel

vcJSON := fmt.Sprintf(vcJSONTemplate, contextURL)

Expand All @@ -254,29 +213,7 @@ func Test_ValidateJSONLDWithExtraUndefinedSubjectFields(t *testing.T) {

t.Run("Extended basic VC model, credentialSubject is defined as array - undefined fields present", func(t *testing.T) {
// Use a different VC to verify the case when credentialSubject is an array.
vcJSONTemplate := `
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"%s"
],
"id": "http://example.com/credentials/4643",
"type": [
"VerifiableCredential",
"CustomExt12"
],
"issuer": "https://example.com/issuers/14",
"issuanceDate": "2018-02-24T05:28:04Z",
"referenceNumber": 83294847,
"credentialSubject": [
{
"id": "did:example:abcdef1234567",
"name": "Jane Doe",
"favoriteFood": "Papaya"
}
]
}
`
vcJSONTemplate := extendedModel

vcJSON := fmt.Sprintf(vcJSONTemplate, contextURL)

Expand Down

0 comments on commit 6babea0

Please sign in to comment.