Skip to content

Commit ff50cd6

Browse files
authored
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.
1 parent 697572a commit ff50cd6

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

operation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -841,9 +841,9 @@ func parseObjectSchema(parser *Parser, refType string, astFile *ast.File) (*spec
841841
case refType == NIL:
842842
return nil, nil
843843
case refType == INTERFACE:
844-
return PrimitiveSchema(OBJECT), nil
844+
return &spec.Schema{}, nil
845845
case refType == ANY:
846-
return PrimitiveSchema(OBJECT), nil
846+
return &spec.Schema{}, nil
847847
case IsGolangPrimitiveType(refType):
848848
refType = TransToValidSchemeType(refType)
849849

operation_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2448,15 +2448,16 @@ func TestParseObjectSchema(t *testing.T) {
24482448

24492449
schema, err := operation.parseObjectSchema("interface{}", nil)
24502450
assert.NoError(t, err)
2451-
assert.Equal(t, schema, PrimitiveSchema(OBJECT))
2451+
assert.Equal(t, schema, &spec.Schema{})
24522452

24532453
schema, err = operation.parseObjectSchema("any", nil)
24542454
assert.NoError(t, err)
2455-
assert.Equal(t, schema, PrimitiveSchema(OBJECT))
2455+
assert.Equal(t, schema, &spec.Schema{})
24562456

24572457
schema, err = operation.parseObjectSchema("any{data=string}", nil)
24582458
assert.NoError(t, err)
2459-
assert.Equal(t, schema, PrimitiveSchema(OBJECT).SetProperty("data", *PrimitiveSchema("string")))
2459+
assert.Equal(t, schema,
2460+
(&spec.Schema{}).WithAllOf(spec.Schema{}, *PrimitiveSchema(OBJECT).SetProperty("data", *PrimitiveSchema("string"))))
24602461

24612462
schema, err = operation.parseObjectSchema("int", nil)
24622463
assert.NoError(t, err)

0 commit comments

Comments
 (0)