diff --git a/openapi2/openapi2.go b/openapi2/openapi2.go index d3297c2..b923a61 100644 --- a/openapi2/openapi2.go +++ b/openapi2/openapi2.go @@ -287,6 +287,7 @@ func typeName(i any) string { } s := strings.ReplaceAll(t.String(), " ", "") + s = strings.ReplaceAll(s, "*", "") if s == "error" { return "string" diff --git a/openapi2/openapi2_test.go b/openapi2/openapi2_test.go index 106aa1f..c94d5a0 100644 --- a/openapi2/openapi2_test.go +++ b/openapi2/openapi2_test.go @@ -295,6 +295,34 @@ func TestDocs(t *testing.T) { filePath: "testdata/t1.json", wantErr: false, }, + { + name: "t2", + args: args{ + routes: []*Route{ + { + Method: "GET", + Path: "/test1/{p1}/{p2}", + Params: []spec.Parameter{ + {ParamProps: spec.ParamProps{Name: "p1", In: "path", Description: "d1", Required: true}}, + {ParamProps: spec.ParamProps{Name: "p2", In: "path", Description: "d2", Required: true}}, + }, + + // ShowBottles godoc + // @Summary Test Handler + // @Description get string by ID + // @ID get-string-by-int + // @Tags bottles + // @Success 200 + // @Failure 400,404,500 + Handler: chai.NewReqResHandler(func(req []*tests.TestRequest, w http.ResponseWriter, r *http.Request) ([]*tests.TestResponse, int, error) { + return nil, 0, nil + }), + }, + }, + }, + filePath: "testdata/t2.json", + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/openapi2/testdata/t2.json b/openapi2/testdata/t2.json new file mode 100644 index 0000000..b4aa517 --- /dev/null +++ b/openapi2/testdata/t2.json @@ -0,0 +1,117 @@ +{ + "info": { + "contact": {} + }, + "paths": { + "/test1/{p1}/{p2}": { + "get": { + "description": "get string by ID", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "bottles" + ], + "summary": "Test Handler", + "operationId": "get-string-by-int", + "parameters": [ + { + "name": "body", + "in": "body", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/tests.TestRequest" + } + } + }, + { + "description": "d1", + "name": "p1", + "in": "path", + "required": true + }, + { + "description": "d2", + "name": "p2", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/tests.TestResponse" + } + } + }, + "400": { + "description": "", + "schema": { + "type": "string" + } + }, + "404": { + "description": "", + "schema": { + "type": "string" + } + }, + "500": { + "description": "", + "schema": { + "type": "string" + } + } + } + } + } + }, + "definitions": { + "tests.TestInnerResponse": { + "type": "object", + "properties": { + "bar_bar": { + "type": "integer" + }, + "foo_foo": { + "type": "integer" + } + } + }, + "tests.TestRequest": { + "type": "object", + "properties": { + "barb": { + "type": "string" + }, + "foob": { + "type": "string" + }, + "test_inner_responseb": { + "$ref": "#/definitions/tests.TestInnerResponse" + } + } + }, + "tests.TestResponse": { + "type": "object", + "properties": { + "bar": { + "type": "string" + }, + "foo": { + "type": "string" + }, + "test_inner_response": { + "$ref": "#/definitions/tests.TestInnerResponse" + } + } + } + } +} \ No newline at end of file