Skip to content

Commit

Permalink
if the top type name is any or interface{}, don't use allOf (#1421)
Browse files Browse the repository at this point in the history
Signed-off-by: sdghchj <sdghchj@qq.com>
  • Loading branch information
sdghchj authored Feb 22, 2023
1 parent 4795c60 commit 566b8af
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,11 @@ func parseCombinedObjectSchema(parser *Parser, refType string, astFile *ast.File
return schema, nil
}

if schema.Ref.GetURL() == nil && len(schema.Type) > 0 && schema.Type[0] == OBJECT && len(schema.Properties) == 0 && schema.AdditionalProperties == nil {
schema.Properties = props
return schema, nil
}

return spec.ComposedSchema(*schema, spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{OBJECT},
Expand Down
4 changes: 4 additions & 0 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2273,6 +2273,10 @@ func TestParseObjectSchema(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, schema, PrimitiveSchema(OBJECT))

schema, err = operation.parseObjectSchema("any{data=string}", nil)
assert.NoError(t, err)
assert.Equal(t, schema, PrimitiveSchema(OBJECT).SetProperty("data", *PrimitiveSchema("string")))

schema, err = operation.parseObjectSchema("int", nil)
assert.NoError(t, err)
assert.Equal(t, schema, PrimitiveSchema(INTEGER))
Expand Down

0 comments on commit 566b8af

Please sign in to comment.