From: Reinhard Tartler Date: Wed, 23 Sep 2026 20:02:07 -0400 Subject: Fix JSON marshal error tests for newer Go Go 1.24+ standard library encoding/json now supports marshaling maps with integer keys (such as map[interface{}]interface{}{1: "one"}), coercing them to strings instead of failing with an unsupported type error. Use an unmarshalable channel type (make(chan int)) in test payloads to reliably trigger json.Marshal errors across all Go versions. Bug-Debian: https://bugs.debian.org/1147128 Forwarded: https://github.com/pb33f/libopenapi-validator/issues/323 Last-Update: 2026-09-23 --- schema_validation/validate_document_test.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/schema_validation/validate_document_test.go b/schema_validation/validate_document_test.go index 434567a..c810822 100644 --- a/schema_validation/validate_document_test.go +++ b/schema_validation/validate_document_test.go @@ -183,16 +183,15 @@ x-values: func TestNormalizeJSON_ReturnsMarshalError(t *testing.T) { payload := map[string]interface{}{ "openapi": "3.1.0", - "invalid": map[interface{}]interface{}{ - 1: "one", - }, + "invalid": make(chan int), } normalized, err := normalizeJSON(payload) assert.Nil(t, normalized) - assert.Error(t, err) - assert.Contains(t, err.Error(), "unsupported type: map[interface {}]interface {}") + if assert.Error(t, err) { + assert.Contains(t, err.Error(), "unsupported type: chan int") + } } func TestValidateDocument_NormalizationErrorDoesNotValidateNil(t *testing.T) { @@ -205,9 +204,7 @@ paths: {}` doc, _ := libopenapi.NewDocument([]byte(spec)) badSpecJSON := map[string]interface{}{ "openapi": "3.1.0", - "invalid": map[interface{}]interface{}{ - 1: "one", - }, + "invalid": make(chan int), } info := doc.GetSpecInfo() info.GetSpecJSON() @@ -220,7 +217,7 @@ paths: {}` assert.Len(t, errors, 1) assert.Equal(t, "OpenAPI document validation failed", errors[0].Message) assert.Contains(t, errors[0].Reason, "cannot be converted to JSON") - assert.Contains(t, errors[0].Reason, "unsupported type: map[interface {}]interface {}") + assert.Contains(t, errors[0].Reason, "unsupported type: chan int") assert.NotContains(t, errors[0].Reason, "got null, want object") assert.Empty(t, errors[0].SchemaValidationErrors) } @@ -235,9 +232,7 @@ paths: {}` doc, _ := libopenapi.NewDocument([]byte(spec)) badSpecJSON := map[string]interface{}{ "openapi": "3.1.0", - "invalid": map[interface{}]interface{}{ - 1: "one", - }, + "invalid": make(chan int), } corrupt := []byte(`{not valid json!!!}`) info := doc.GetSpecInfo()