diff --git a/lex/lexlint/breaking.go b/lex/lexlint/breaking.go index 3d82e84c..03295881 100644 --- a/lex/lexlint/breaking.go +++ b/lex/lexlint/breaking.go @@ -55,13 +55,13 @@ func breakingDefs(nsid syntax.NSID, name string, local, remote lexicon.SchemaDef issues := []LintIssue{} // NOTE: in some situations this sort of change might actually be allowed? - if reflect.TypeOf(local) != reflect.TypeOf(remote) { + if reflect.TypeOf(local.Inner) != reflect.TypeOf(remote.Inner) { issues = append(issues, LintIssue{ NSID: nsid, LintLevel: "error", LintName: "type-change", LintDescription: "schema definition type changed", - Message: fmt.Sprintf("schema type changed (%s): %T != %T", name, local, remote), + Message: fmt.Sprintf("schema type changed (%s): %T != %T", name, local.Inner, remote.Inner), }) return issues } diff --git a/lex/lexlint/breaking_test.go b/lex/lexlint/breaking_test.go new file mode 100644 index 00000000..e2213987 --- /dev/null +++ b/lex/lexlint/breaking_test.go @@ -0,0 +1,24 @@ +package lexlint + +import ( + "testing" + + "github.com/bluesky-social/indigo/atproto/lexicon" + + "github.com/stretchr/testify/assert" +) + +func TestBreakingDefs_InnerTypeChange(t *testing.T) { + assert := assert.New(t) + + // When a field changes type (e.g. string -> object), breakingDefs should + // report a type-change error rather than panicking on a type assertion. + local := lexicon.SchemaDef{Inner: lexicon.SchemaString{}} + remote := lexicon.SchemaDef{Inner: lexicon.SchemaObject{}} + + issues := breakingDefs("com.example.test", "testField", local, remote) + + assert.Len(issues, 1) + assert.Equal("type-change", issues[0].LintName) + assert.Equal("error", issues[0].LintLevel) +}