Skip to content

Commit

Permalink
Fix global overrides for any/interface ref types (#1835)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ezequiel authored Jul 3, 2024
1 parent 697572a commit ff50cd6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ff50cd6

Please sign in to comment.