From 176c17ecff5f7b92feb3535639f642e316d8460b Mon Sep 17 00:00:00 2001 From: xurui Date: Tue, 9 Jul 2024 17:43:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E5=92=8C=E5=AE=9E=E4=BE=8B=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/basic.go | 2 +- openapi/openapi_test.go | 42 ++++++++++++++++++++--------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/example/basic.go b/example/basic.go index 12efe30..6cc1347 100644 --- a/example/basic.go +++ b/example/basic.go @@ -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 { diff --git a/openapi/openapi_test.go b/openapi/openapi_test.go index 1ac5387..fe85504 100644 --- a/openapi/openapi_test.go +++ b/openapi/openapi_test.go @@ -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{} @@ -25,7 +25,7 @@ func TestMarshalJSON(t *testing.T) { Description: "type", Required: true, Schema: &Schema{ - Type: []string{"string"}, + Type: "string", }, }, }, @@ -55,7 +55,7 @@ func TestMarshalJSON(t *testing.T) { Description: "pk", Required: true, Schema: &Schema{ - Type: []string{"integer"}, + Type: "integer", }, }, { @@ -63,7 +63,7 @@ func TestMarshalJSON(t *testing.T) { In: "query", Description: "type", Schema: &Schema{ - Type: []string{"string"}, + Type: "string", }, }, }, @@ -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"}, }, }, }, @@ -117,7 +117,7 @@ func TestMarshalJSON(t *testing.T) { Description: "pk", Required: true, Schema: &Schema{ - Type: []string{"integer"}, + Type: "integer", }, }, }, @@ -137,7 +137,7 @@ func TestMarshalJSON(t *testing.T) { Content: map[string]*MediaType{ "application/json": { Schema: &Schema{ - Type: []string{"boolean"}, + Type: "boolean", }, }, }, @@ -191,7 +191,7 @@ func TestUnmarshalJSON(t *testing.T) { Description: "type", Required: true, Schema: &Schema{ - Type: []string{"string"}, + Type: "string", }, }, }, @@ -221,7 +221,7 @@ func TestUnmarshalJSON(t *testing.T) { Description: "pk", Required: true, Schema: &Schema{ - Type: []string{"integer"}, + Type: "integer", }, }, { @@ -229,7 +229,7 @@ func TestUnmarshalJSON(t *testing.T) { In: "query", Description: "type", Schema: &Schema{ - Type: []string{"string"}, + Type: "string", }, }, }, @@ -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"}, }, }, }, @@ -283,7 +283,7 @@ func TestUnmarshalJSON(t *testing.T) { Description: "pk", Required: true, Schema: &Schema{ - Type: []string{"integer"}, + Type: "integer", }, }, }, @@ -303,7 +303,7 @@ func TestUnmarshalJSON(t *testing.T) { Content: map[string]*MediaType{ "application/json": { Schema: &Schema{ - Type: []string{"boolean"}, + Type: "boolean", }, }, },