-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(cmd/web/restdoc): 采用 go/types 代替 go/ast 的使用
- Loading branch information
Showing
30 changed files
with
1,696 additions
and
717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
package openapi | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/getkin/kin-openapi/openapi3" | ||
"github.com/issue9/assert/v3" | ||
) | ||
|
||
func TestOpenapi_Schema(t *testing.T) { | ||
a := assert.New(t, false) | ||
o := New("3.0.0") | ||
|
||
ref := NewSchemaRef("", nil) | ||
o.AddSchema(ref) | ||
a.Length(o.doc.Components.Schemas, 0) // 空的 refID,添加不成功 | ||
|
||
ref = NewSchemaRef("abc", nil) | ||
o.AddSchema(ref) | ||
a.Length(o.doc.Components.Schemas, 1) | ||
|
||
v1, found := o.GetSchema("abc") | ||
a.True(found).NotNil(v1) | ||
v2, found := o.GetSchema(ComponentSchemaPrefix + "abc") | ||
a.True(found).NotNil(v2) | ||
a.Equal(v1, v2). | ||
Equal(v1, v2). // v1,v2 指向同一个对象 | ||
Equal(v1.Ref, ComponentSchemaPrefix+"abc") | ||
|
||
// 同名,但都是 nil | ||
a.NotPanic(func() { | ||
ref = NewSchemaRef(ComponentSchemaPrefix+"abc", nil) | ||
o.AddSchema(ref) | ||
}) | ||
|
||
a.PanicString(func() { | ||
ref = NewSchemaRef(ComponentSchemaPrefix+"abc", &openapi3.Schema{}) | ||
o.AddSchema(ref) | ||
}, "添加同名的对象 abc") | ||
} | ||
|
||
func TestNewAttrSchemaRef(t *testing.T) { | ||
a := assert.New(t, false) | ||
|
||
ref := openapi3.NewSchemaRef("ref", openapi3.NewBoolSchema()) | ||
ref2 := NewAttrSchemaRef(ref, "", "", nil, false) | ||
a.Equal(ref2, ref) | ||
|
||
ref2 = NewAttrSchemaRef(ref, "", "123", nil, false) | ||
a.NotEqual(ref2, ref). | ||
Equal(ref2.Value.AllOf[0].Value, ref.Value). | ||
Equal(ref2.Value.Description, "123") | ||
|
||
ref2 = NewAttrSchemaRef(ref, "", "123", nil, true) | ||
a.NotEqual(ref2, ref). | ||
Equal(ref2.Value.AllOf[0].Value, ref.Value). | ||
Equal(ref2.Value.Description, "123"). | ||
True(ref2.Value.Nullable) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.