Skip to content

Commit

Permalink
fix: 修改测试用例和实例的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
xurui committed Jul 9, 2024
1 parent 0e945e6 commit 176c17e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion example/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func main() {
}
})
api.IncludeRouter(&TestController{}, "/v1", true)
_ = api.Run("127.0.0.1:8080")
api.Run("127.0.0.1:8080")
}

type TestController struct {
Expand Down
42 changes: 21 additions & 21 deletions openapi/openapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"testing"
)

var jsonStr = `{"components":{"securitySchemes":{"httpBasic":{"scheme":"basic","type":"http"}}},"info":{"title":"GoAPI","version":"1.0.0"},"openapi":"3.1.0","paths":{"/user/{id}":{"description":"user handle","get":{"description":"user info","operationId":"/user/{id}_get","parameters":[{"description":"pk","in":"path","name":"id","required":true,"schema":{"type":["integer"]}},{"description":"type","in":"query","name":"type","schema":{"type":["string"]}}],"responses":{"default":{"content":{"application/json":{"schema":{"description":"content","properties":{"age":{"type":["integer"]},"id":{"type":["integer"]},"name":{"type":["string"]}},"title":"content","type":["object"]}}},"description":"desc","headers":{"Set-Token":{"description":"set token","required":false,"schema":{"type":["string"]}}},"links":{"bd":{"description":"baidu link","operationRef":"https://www.baidu.com","parameters":{"id":"1"},"requestBody":"test"}}}},"summary":"user info","tags":["admin"]},"put":{"callbacks":{"callback":{"{$request.query.callbackUrl}":{"description":"callback","post":{"description":"callback","operationId":"callback_post","parameters":[{"description":"type","in":"query","name":"callbackUrl","required":true,"schema":{"type":["string"]}}],"requestBody":{"$ref":"#/paths/~1user~1%7Bid%7D/put/requestBody"},"responses":{"default":{"$ref":"#/paths/~1user~1%7Bid%7D/put/responses/default"}},"summary":"callback","tags":["admin"]},"summary":"callback"}}},"description":"edit user","operationId":"/user/{id}_put","parameters":[{"description":"pk","in":"path","name":"id","required":true,"schema":{"type":["integer"]}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/paths/~1user~1%7Bid%7D/get/responses/default/content/application~1json/schema"}}},"description":"set body"},"responses":{"default":{"content":{"application/json":{"schema":{"type":["boolean"]}}},"description":"aaa"}},"summary":"edit user","tags":["admin"]},"summary":"user handle"}},"security":[{"httpBasic":[]}],"tags":[{"description":"admin manager","name":"admin"}]}`
var jsonStr = `{"components":{"securitySchemes":{"httpBasic":{"scheme":"basic","type":"http"}}},"info":{"title":"GoAPI","version":"1.0.0"},"openapi":"3.1.0","paths":{"/user/{id}":{"description":"user handle","get":{"description":"user info","operationId":"/user/{id}_get","parameters":[{"description":"pk","in":"path","name":"id","required":true,"schema":{"type":"integer"}},{"description":"type","in":"query","name":"type","schema":{"type":"string"}}],"responses":{"default":{"content":{"application/json":{"schema":{"description":"content","properties":{"age":{"type":"integer"},"id":{"type":"integer"},"name":{"type":"string"}},"title":"content","type":"object"}}},"description":"desc","headers":{"Set-Token":{"description":"set token","required":false,"schema":{"type":"string"}}},"links":{"bd":{"description":"baidu link","operationRef":"https://www.baidu.com","parameters":{"id":"1"},"requestBody":"test"}}}},"summary":"user info","tags":["admin"]},"put":{"callbacks":{"callback":{"{$request.query.callbackUrl}":{"description":"callback","post":{"description":"callback","operationId":"callback_post","parameters":[{"description":"type","in":"query","name":"callbackUrl","required":true,"schema":{"type":"string"}}],"requestBody":{"$ref":"#/paths/~1user~1%7Bid%7D/put/requestBody"},"responses":{"default":{"$ref":"#/paths/~1user~1%7Bid%7D/put/responses/default"}},"summary":"callback","tags":["admin"]},"summary":"callback"}}},"description":"edit user","operationId":"/user/{id}_put","parameters":[{"description":"pk","in":"path","name":"id","required":true,"schema":{"type":"integer"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/paths/~1user~1%7Bid%7D/get/responses/default/content/application~1json/schema"}}},"description":"set body"},"responses":{"default":{"content":{"application/json":{"schema":{"type":"boolean"}}},"description":"aaa"}},"summary":"edit user","tags":["admin"]},"summary":"user handle"}},"security":[{"httpBasic":[]}],"tags":[{"description":"admin manager","name":"admin"}]}`

func TestMarshalJSON(t *testing.T) {
callback := &Callback{}
Expand All @@ -25,7 +25,7 @@ func TestMarshalJSON(t *testing.T) {
Description: "type",
Required: true,
Schema: &Schema{
Type: []string{"string"},
Type: "string",
},
},
},
Expand Down Expand Up @@ -55,15 +55,15 @@ func TestMarshalJSON(t *testing.T) {
Description: "pk",
Required: true,
Schema: &Schema{
Type: []string{"integer"},
Type: "integer",
},
},
{
Name: "type",
In: "query",
Description: "type",
Schema: &Schema{
Type: []string{"string"},
Type: "string",
},
},
},
Expand All @@ -74,20 +74,20 @@ func TestMarshalJSON(t *testing.T) {
"Set-Token": {
Description: "set token",
Schema: &Schema{
Type: []string{"string"},
Type: "string",
},
},
},
Content: map[string]*MediaType{
"application/json": {
Schema: &Schema{
Type: []string{"object"},
Type: "object",
Title: "content",
Description: "content",
Properties: map[string]*Schema{
"id": {Type: []string{"integer"}},
"name": {Type: []string{"string"}},
"age": {Type: []string{"integer"}},
"id": {Type: "integer"},
"name": {Type: "string"},
"age": {Type: "integer"},
},
},
},
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestMarshalJSON(t *testing.T) {
Description: "pk",
Required: true,
Schema: &Schema{
Type: []string{"integer"},
Type: "integer",
},
},
},
Expand All @@ -137,7 +137,7 @@ func TestMarshalJSON(t *testing.T) {
Content: map[string]*MediaType{
"application/json": {
Schema: &Schema{
Type: []string{"boolean"},
Type: "boolean",
},
},
},
Expand Down Expand Up @@ -191,7 +191,7 @@ func TestUnmarshalJSON(t *testing.T) {
Description: "type",
Required: true,
Schema: &Schema{
Type: []string{"string"},
Type: "string",
},
},
},
Expand Down Expand Up @@ -221,15 +221,15 @@ func TestUnmarshalJSON(t *testing.T) {
Description: "pk",
Required: true,
Schema: &Schema{
Type: []string{"integer"},
Type: "integer",
},
},
{
Name: "type",
In: "query",
Description: "type",
Schema: &Schema{
Type: []string{"string"},
Type: "string",
},
},
},
Expand All @@ -240,20 +240,20 @@ func TestUnmarshalJSON(t *testing.T) {
"Set-Token": {
Description: "set token",
Schema: &Schema{
Type: []string{"string"},
Type: "string",
},
},
},
Content: map[string]*MediaType{
"application/json": {
Schema: &Schema{
Type: []string{"object"},
Type: "object",
Title: "content",
Description: "content",
Properties: map[string]*Schema{
"id": {Type: []string{"integer"}},
"name": {Type: []string{"string"}},
"age": {Type: []string{"integer"}},
"id": {Type: "integer"},
"name": {Type: "string"},
"age": {Type: "integer"},
},
},
},
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestUnmarshalJSON(t *testing.T) {
Description: "pk",
Required: true,
Schema: &Schema{
Type: []string{"integer"},
Type: "integer",
},
},
},
Expand All @@ -303,7 +303,7 @@ func TestUnmarshalJSON(t *testing.T) {
Content: map[string]*MediaType{
"application/json": {
Schema: &Schema{
Type: []string{"boolean"},
Type: "boolean",
},
},
},
Expand Down

0 comments on commit 176c17e

Please sign in to comment.