Skip to content

Commit

Permalink
fix: formatting and linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
punit-kulal committed Oct 3, 2023
1 parent 4741766 commit ae99ddb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
1 change: 0 additions & 1 deletion formats/json/compatibility.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ func CheckAdditionalProperties(schema *jsonschema.Schema, diffs *compatibilityEr
diffs.add(additionalPropertiesNotTrue, schema.Location, "additionalProperties need to be not defined or true for evaluation as an open content model")
}
}

}

func TypeCheckExecutor(spec TypeCheckSpec) SchemaCompareCheck {
Expand Down
19 changes: 9 additions & 10 deletions formats/json/compatibility_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,46 +95,45 @@ func checkItemSchema(prevSchema, currSchema *jsonschema.Schema, diffs *compatibi
diffs.add(itemSchemaModification, currSchema.Location, "prev prefix items contains %d elements, current contains %d", len(prevItems), len(currItems))
}
}
if prevItems == nil && currItems != nil{
if prevItems == nil && currItems != nil {
diffs.add(itemSchemaModification, currSchema.Location, "prev prefix items is absent, current contains %d", len(currItems))
}
if prevItems != nil && currItems == nil {
diffs.add(itemSchemaModification, currSchema.Location, "prev prefix items contains %d elements, current contains absent", len(prevItems))
}
}else {
} else {
prevItems := getItems(prevSchema)
currItems := getItems(currSchema)
if len(prevItems) != len(currItems) {
diffs.add(itemSchemaModification, currSchema.Location, "prev items contains %d elements, current contains %d", len(prevItems), len(currItems))
}
}

}

func checkRestOfItemsSchema(prevSchema, currSchema *jsonschema.Schema, diffs *compatibilityErr){
func checkRestOfItemsSchema(prevSchema, currSchema *jsonschema.Schema, diffs *compatibilityErr) {
var prevItem, currItem *jsonschema.Schema
var ok bool
// check schema for remaining array elements
if prevSchema.Draft == jsonschema.Draft2020{
if prevSchema.Draft == jsonschema.Draft2020 {
prevItem = prevSchema.Items2020
currItem = currSchema.Items2020
}else{
} else {
if prevSchema.AdditionalItems != nil {
prevItem, ok = prevSchema.AdditionalItems.(*jsonschema.Schema)
if !ok { // prev schema additional Items is boolean value
if prevSchema.AdditionalItems != currSchema.AdditionalItems {
// curr schema additonal items is not equivalent
// curr schema additional items is not equivalent
diffs.add(itemSchemaModification, prevSchema.Location, "the value of additional items has changed")
}
return // since both cases equal and non equal have been evaluated.
}
}
if currSchema.AdditionalItems != nil {
currItem, ok = currSchema.AdditionalItems.(*jsonschema.Schema)
if !ok { // curr schema is boolean
if !ok { // curr schema is boolean
if prevSchema.AdditionalItems == nil {
diffs.add(itemSchemaAddition, prevSchema.Location, "additional items has been set, changes are not allowed to additional items")
}else if prevSchema.AdditionalItems != currSchema.AdditionalItems {
} else if prevSchema.AdditionalItems != currSchema.AdditionalItems {
diffs.add(itemSchemaModification, prevSchema.Location, "additional items has been modified, changes are not allowed")
}
return
Expand All @@ -143,7 +142,7 @@ func checkRestOfItemsSchema(prevSchema, currSchema *jsonschema.Schema, diffs *co
}
if prevItem == nil && currItem != nil {
diffs.add(itemSchemaAddition, currItem.Location, "item schema cannot be added in schema changes")
}else if prevItem != nil && currItem == nil {
} else if prevItem != nil && currItem == nil {
diffs.add(itemsSchemaDeletion, prevItem.Location, "items schema cannot be deleted in modification changes")
}
}
Expand Down
1 change: 0 additions & 1 deletion formats/json/compatibility_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func Test_Check_OneOf_Conditions(t *testing.T) {
assert.Equal(t, oneOfModified, diffs3.diffs[0].kind)
}


func Test_CheckPropertyAddition_ReturnsSuccess_WhenPropertyAdded(t *testing.T) {
prev := initialiseSchema(t, "./testdata/propertyAddition/prev.json")
new := initialiseSchema(t, "./testdata/propertyAddition/added.json")
Expand Down
1 change: 1 addition & 0 deletions formats/json/compatibility_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func Test_TypeCheckExecutorCorrectness(t *testing.T) {
// }

func initialiseSchema(t *testing.T, path string) *jsonschema.Schema {
t.Helper()
sc, err := jsonschema.Compile(path)
if err != nil {
assert.Fail(t, fmt.Sprintf("failed while compiling schema: %s", path))
Expand Down
11 changes: 5 additions & 6 deletions formats/json/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"strings"


"github.com/santhosh-tekuri/jsonschema/v5"
)

Expand Down Expand Up @@ -41,7 +40,7 @@ func exploreItems(jsonSchema *jsonschema.Schema, locationSchemaMap map[string]*j
}
}

func exploreAdditionalItems(jsonSchema *jsonschema.Schema, locationSchemaMap map[string]*jsonschema.Schema, baseLocation string){
func exploreAdditionalItems(jsonSchema *jsonschema.Schema, locationSchemaMap map[string]*jsonschema.Schema, baseLocation string) {
itemSchema := getRestOfItemsSchema(jsonSchema)
if itemSchema != nil {
explore(itemSchema, locationSchemaMap, baseLocation)
Expand Down Expand Up @@ -151,7 +150,7 @@ func getItems(jsSchema *jsonschema.Schema) []*jsonschema.Schema {
if jsSchema.PrefixItems != nil {
return jsSchema.PrefixItems
}
}else {
} else {
schemaArr, ok := jsSchema.Items.([]*jsonschema.Schema)
if ok {
return schemaArr
Expand All @@ -164,11 +163,11 @@ func getItems(jsSchema *jsonschema.Schema) []*jsonschema.Schema {
return []*jsonschema.Schema{}
}

func getRestOfItemsSchema(jsSchema *jsonschema.Schema) *jsonschema.Schema{
func getRestOfItemsSchema(jsSchema *jsonschema.Schema) *jsonschema.Schema {
if jsSchema.Draft == jsonschema.Draft2020 {
return jsSchema.Items2020
}else{
schema, ok := jsSchema.AdditionalItems.(*jsonschema.Schema)
} else {
schema, ok := jsSchema.AdditionalItems.(*jsonschema.Schema)
if !ok {
return nil
}
Expand Down

0 comments on commit ae99ddb

Please sign in to comment.