Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7dc9eae

Browse files
authored
Merge pull request #186 from per1234/full-json-pointers
Allow full JSON pointers in schema validation result parsing functions
2 parents 3427584 + 25abd26 commit 7dc9eae

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

‎internal/project/packageindex/packageindexschemas_test.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,14 @@ func TestMinLength(t *testing.T) {
157157
require.NoError(t, err)
158158

159159
t.Run(fmt.Sprintf("%s less than minimum length of %d (%s)", testTable.propertyPointerString, testTable.minLength, testTable.complianceLevel), func(t *testing.T) {
160-
assert.True(t, schema.PropertyLessThanMinLength(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[testTable.complianceLevel]))
160+
assert.True(t, schema.PropertyLessThanMinLength(testTable.propertyPointerString, packageindex.Validate(packageIndex)[testTable.complianceLevel]))
161161
})
162162

163163
// Test schema validation results with minimum value length.
164164
propertyPointer.Set(packageIndex, strings.Repeat("a", testTable.minLength))
165165

166166
t.Run(fmt.Sprintf("%s at minimum length of %d (%s)", testTable.propertyPointerString, testTable.minLength, testTable.complianceLevel), func(t *testing.T) {
167-
assert.False(t, schema.PropertyLessThanMinLength(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[testTable.complianceLevel]))
167+
assert.False(t, schema.PropertyLessThanMinLength(testTable.propertyPointerString, packageindex.Validate(packageIndex)[testTable.complianceLevel]))
168168
})
169169
}
170170
}
@@ -316,7 +316,7 @@ func TestRequired(t *testing.T) {
316316

317317
validationResult := packageindex.Validate(packageIndex)
318318
t.Run(fmt.Sprintf("%s (%s)", testTable.propertyPointerString, testTable.complianceLevel), func(t *testing.T) {
319-
testTable.assertion(t, schema.RequiredPropertyMissing(strings.TrimPrefix(testTable.propertyPointerString, "/"), validationResult[testTable.complianceLevel]))
319+
testTable.assertion(t, schema.RequiredPropertyMissing(testTable.propertyPointerString, validationResult[testTable.complianceLevel]))
320320
})
321321
}
322322
}
@@ -348,7 +348,7 @@ func TestEnum(t *testing.T) {
348348
require.NoError(t, err)
349349

350350
t.Run(fmt.Sprintf("%s: %s (%s)", testTable.propertyPointerString, testTable.propertyValue, testTable.complianceLevel), func(t *testing.T) {
351-
testTable.assertion(t, schema.PropertyEnumMismatch(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[testTable.complianceLevel]))
351+
testTable.assertion(t, schema.PropertyEnumMismatch(testTable.propertyPointerString, packageindex.Validate(packageIndex)[testTable.complianceLevel]))
352352
})
353353
}
354354
}
@@ -512,7 +512,7 @@ func TestPattern(t *testing.T) {
512512
require.NoError(t, err)
513513

514514
t.Run(fmt.Sprintf("%s: %s (%s)", testTable.propertyPointerString, testTable.propertyValue, testTable.complianceLevel), func(t *testing.T) {
515-
testTable.assertion(t, schema.PropertyPatternMismatch(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[testTable.complianceLevel]))
515+
testTable.assertion(t, schema.PropertyPatternMismatch(testTable.propertyPointerString, packageindex.Validate(packageIndex)[testTable.complianceLevel]))
516516
})
517517
}
518518
}
@@ -567,7 +567,7 @@ func TestType(t *testing.T) {
567567
_, err = propertyPointer.Set(packageIndex, testTable.propertyValue)
568568

569569
t.Run(fmt.Sprintf("%s: %v (%s)", testTable.propertyPointerString, testTable.propertyValue, complianceLevel), func(t *testing.T) {
570-
testTable.assertion(t, schema.PropertyTypeMismatch(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[complianceLevel]))
570+
testTable.assertion(t, schema.PropertyTypeMismatch(testTable.propertyPointerString, packageindex.Validate(packageIndex)[complianceLevel]))
571571
})
572572
}
573573
}
@@ -632,7 +632,7 @@ func TestFormat(t *testing.T) {
632632
require.NoError(t, err)
633633

634634
t.Run(fmt.Sprintf("%s: %s (%s)", testTable.propertyPointerString, testTable.propertyValue, testTable.complianceLevel), func(t *testing.T) {
635-
testTable.assertion(t, schema.PropertyFormatMismatch(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[testTable.complianceLevel]))
635+
testTable.assertion(t, schema.PropertyFormatMismatch(testTable.propertyPointerString, packageindex.Validate(packageIndex)[testTable.complianceLevel]))
636636
})
637637
}
638638
}
@@ -693,7 +693,7 @@ func TestAdditionalProperties(t *testing.T) {
693693
require.NoError(t, err)
694694

695695
t.Run(fmt.Sprintf("Additional property in the %s object (%s)", testTable.propertyPointerString, testTable.complianceLevel), func(t *testing.T) {
696-
testTable.assertion(t, schema.ProhibitedAdditionalProperties(strings.TrimPrefix(testTable.propertyPointerString, "/"), packageindex.Validate(packageIndex)[testTable.complianceLevel]))
696+
testTable.assertion(t, schema.ProhibitedAdditionalProperties(testTable.propertyPointerString, packageindex.Validate(packageIndex)[testTable.complianceLevel]))
697697
})
698698
}
699699
}

‎internal/rule/schema/parsevalidationresult.go‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ import (
2626

2727
// RequiredPropertyMissing returns whether the given required property is missing from the document.
2828
func RequiredPropertyMissing(propertyName string, validationResult ValidationResult) bool {
29-
return ValidationErrorMatch("#", "/required$", "", "^#/"+propertyName+"$", validationResult)
29+
return ValidationErrorMatch("#", "/required$", "", "^#/?"+propertyName+"$", validationResult)
3030
}
3131

3232
// PropertyPatternMismatch returns whether the given property did not match the regular expression defined in the JSON schema.
3333
func PropertyPatternMismatch(propertyName string, validationResult ValidationResult) bool {
34-
return ValidationErrorMatch("#/"+propertyName, "/pattern$", "", "", validationResult)
34+
return ValidationErrorMatch("#/?"+propertyName, "/pattern$", "", "", validationResult)
3535
}
3636

3737
// PropertyLessThanMinLength returns whether the given property is less than the minimum length allowed by the schema.
3838
func PropertyLessThanMinLength(propertyName string, validationResult ValidationResult) bool {
39-
return ValidationErrorMatch("^#/"+propertyName+"$", "/minLength$", "", "", validationResult)
39+
return ValidationErrorMatch("^#/?"+propertyName+"$", "/minLength$", "", "", validationResult)
4040
}
4141

4242
// PropertyGreaterThanMaxLength returns whether the given property is greater than the maximum length allowed by the schema.
4343
func PropertyGreaterThanMaxLength(propertyName string, validationResult ValidationResult) bool {
44-
return ValidationErrorMatch("^#/"+propertyName+"$", "/maxLength$", "", "", validationResult)
44+
return ValidationErrorMatch("^#/?"+propertyName+"$", "/maxLength$", "", "", validationResult)
4545
}
4646

4747
// PropertyEnumMismatch returns whether the given property does not match any of the items in the enum array.
4848
func PropertyEnumMismatch(propertyName string, validationResult ValidationResult) bool {
49-
return ValidationErrorMatch("#/"+propertyName, "/enum$", "", "", validationResult)
49+
return ValidationErrorMatch("#/?"+propertyName, "/enum$", "", "", validationResult)
5050
}
5151

5252
// PropertyDependenciesMissing returns whether property dependencies of the given property are missing.
5353
func PropertyDependenciesMissing(propertyName string, validationResult ValidationResult) bool {
54-
return ValidationErrorMatch("", "/dependencies/"+propertyName+"/[0-9]+$", "", "", validationResult)
54+
return ValidationErrorMatch("", "/dependencies/?"+propertyName+"/[0-9]+$", "", "", validationResult)
5555
}
5656

5757
// PropertyTypeMismatch returns whether the given property has incorrect type.
5858
func PropertyTypeMismatch(propertyName string, validationResult ValidationResult) bool {
59-
return ValidationErrorMatch("^#/"+propertyName+"$", "/type$", "", "", validationResult)
59+
return ValidationErrorMatch("^#/?"+propertyName+"$", "/type$", "", "", validationResult)
6060
}
6161

6262
// PropertyFormatMismatch returns whether the given property has incorrect format.
6363
func PropertyFormatMismatch(propertyName string, validationResult ValidationResult) bool {
64-
return ValidationErrorMatch("^#/"+propertyName+"$", "/format$", "", "", validationResult)
64+
return ValidationErrorMatch("^#/?"+propertyName+"$", "/format$", "", "", validationResult)
6565
}
6666

6767
// ProhibitedAdditionalProperty returns whether the given property has prohibited additional subproperty(s).

‎internal/rule/schema/schema_test.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"regexp"
22-
"strings"
2322
"testing"
2423

2524
"github.com/arduino/arduino-lint/internal/project/general"
@@ -228,7 +227,7 @@ func TestProhibitedAdditionalProperties(t *testing.T) {
228227
var instance map[string]interface{}
229228
json.Unmarshal([]byte(rawInstance), &instance)
230229

231-
assert.False(t, ProhibitedAdditionalProperties(strings.TrimPrefix(testTable.objectPointerString, "/"), Validate(instance, validSchemaWithReferences)), fmt.Sprintf("No additional properties in %s", testTable.objectPointerString))
230+
assert.False(t, ProhibitedAdditionalProperties(testTable.objectPointerString, Validate(instance, validSchemaWithReferences)), fmt.Sprintf("No additional properties in %s", testTable.objectPointerString))
232231

233232
// Add additional property to object.
234233
pointer, err := gojsonpointer.NewJsonPointer(testTable.objectPointerString + "/fooAdditionalProperty")
@@ -237,7 +236,7 @@ func TestProhibitedAdditionalProperties(t *testing.T) {
237236
require.NoError(t, err)
238237

239238
t.Run(fmt.Sprintf("Additional property in the %s object", testTable.objectPointerString), func(t *testing.T) {
240-
testTable.assertion(t, ProhibitedAdditionalProperties(strings.TrimPrefix(testTable.objectPointerString, "/"), Validate(instance, validSchemaWithReferences)))
239+
testTable.assertion(t, ProhibitedAdditionalProperties(testTable.objectPointerString, Validate(instance, validSchemaWithReferences)))
241240
})
242241
}
243242
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /