From ff50cd6bd265d679390b781ecd9f5979633c4813 Mon Sep 17 00:00:00 2001 From: Ezequiel Rodriguez Date: Tue, 2 Jul 2024 23:14:32 -0700 Subject: [PATCH] Fix global overrides for any/interface ref types (#1835) When overriding with any or interface{}, the code should prefer the "any" (empty) schema instead, not the object schema since that's different e.g. --- operation.go | 4 ++-- operation_test.go | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/operation.go b/operation.go index 24b0496b2..ac79e3102 100644 --- a/operation.go +++ b/operation.go @@ -841,9 +841,9 @@ func parseObjectSchema(parser *Parser, refType string, astFile *ast.File) (*spec case refType == NIL: return nil, nil case refType == INTERFACE: - return PrimitiveSchema(OBJECT), nil + return &spec.Schema{}, nil case refType == ANY: - return PrimitiveSchema(OBJECT), nil + return &spec.Schema{}, nil case IsGolangPrimitiveType(refType): refType = TransToValidSchemeType(refType) diff --git a/operation_test.go b/operation_test.go index fb43a446e..50e4ac3b1 100644 --- a/operation_test.go +++ b/operation_test.go @@ -2448,15 +2448,16 @@ func TestParseObjectSchema(t *testing.T) { schema, err := operation.parseObjectSchema("interface{}", nil) assert.NoError(t, err) - assert.Equal(t, schema, PrimitiveSchema(OBJECT)) + assert.Equal(t, schema, &spec.Schema{}) schema, err = operation.parseObjectSchema("any", nil) assert.NoError(t, err) - assert.Equal(t, schema, PrimitiveSchema(OBJECT)) + assert.Equal(t, schema, &spec.Schema{}) schema, err = operation.parseObjectSchema("any{data=string}", nil) assert.NoError(t, err) - assert.Equal(t, schema, PrimitiveSchema(OBJECT).SetProperty("data", *PrimitiveSchema("string"))) + assert.Equal(t, schema, + (&spec.Schema{}).WithAllOf(spec.Schema{}, *PrimitiveSchema(OBJECT).SetProperty("data", *PrimitiveSchema("string")))) schema, err = operation.parseObjectSchema("int", nil) assert.NoError(t, err)