Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix make schema name to support generics #41

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions endpoint/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TestBodyR(t *testing.T) {
Name: "body",
Required: true,
Schema: &swag.Schema{
Ref: "#/definitions/endpoint.Model",
Ref: "#/definitions/github.com_zc2638_swag_endpoint.Model",
Prototype: reflect.TypeOf(Model{}),
},
}
Expand All @@ -234,7 +234,7 @@ func TestBody(t *testing.T) {
Description: "the description",
Required: true,
Schema: &swag.Schema{
Ref: "#/definitions/endpoint.Model",
Ref: "#/definitions/github.com_zc2638_swag_endpoint.Model",
Prototype: reflect.TypeOf(Model{}),
},
}
Expand All @@ -253,7 +253,7 @@ func TestResponse(t *testing.T) {
expected := swag.Response{
Description: "successful",
Schema: &swag.Schema{
Ref: "#/definitions/endpoint.Model",
Ref: "#/definitions/github.com_zc2638_swag_endpoint.Model",
Prototype: Model{},
},
}
Expand Down
6 changes: 3 additions & 3 deletions reflect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type Empty struct {

func TestDefine(t *testing.T) {
v := define(Pet{})
obj, ok := v["swag.Pet"]
obj, ok := v["github.com_zc2638_swag.Pet"]
assert.True(t, ok)
assert.False(t, obj.IsArray)
assert.Equal(t, 17, len(obj.Properties))
Expand All @@ -68,7 +68,7 @@ func TestDefine(t *testing.T) {
assert.Nil(t, err)
err = json.NewDecoder(bytes.NewReader(data)).Decode(&content)
assert.Nil(t, err)
expected := content["swag.Pet"]
expected := content["github.com_zc2638_swag.Pet"]

assert.Equal(t, expected.IsArray, obj.IsArray, "expected IsArray to match")
assert.Equal(t, expected.Type, obj.Type, "expected Type to match")
Expand Down Expand Up @@ -130,7 +130,7 @@ func TestNotStructDefine(t *testing.T) {

func TestHonorJsonIgnore(t *testing.T) {
v := define(Empty{})
obj, ok := v["swag.Empty"]
obj, ok := v["github.com_zc2638_swag.Empty"]
assert.True(t, ok)
assert.False(t, obj.IsArray)
assert.Equal(t, 0, len(obj.Properties), "expected zero exposed properties")
Expand Down
12 changes: 6 additions & 6 deletions testdata/pet.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"swag.Person": {
"github.com_zc2638_swag.Person": {
"type": "object",
"properties": {
"First": {
Expand All @@ -15,7 +15,7 @@
}
}
},
"swag.Pet": {
"github.com_zc2638_swag.Pet": {
"type": "object",
"required": [
"pointer"
Expand Down Expand Up @@ -85,23 +85,23 @@
"example": "b"
},
"friend": {
"$ref": "#/definitions/swag.Person",
"$ref": "#/definitions/github.com_zc2638_swag.Person",
"description": "description short expression"
},
"friends": {
"type": "array",
"description": "long desc",
"items": {
"$ref": "#/definitions/swag.Person"
"$ref": "#/definitions/github.com_zc2638_swag.Person"
}
},
"pointer": {
"$ref": "#/definitions/swag.Person"
"$ref": "#/definitions/github.com_zc2638_swag.Person"
},
"pointers": {
"type": "array",
"items": {
"$ref": "#/definitions/swag.Person"
"$ref": "#/definitions/github.com_zc2638_swag.Person"
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package swag

import (
"fmt"
"path"
"reflect"
"regexp"
"strconv"
Expand Down Expand Up @@ -68,10 +67,11 @@ func makeName(t reflect.Type) string {
ptr := reflect2.PtrOf(t)
name = "ptr" + strconv.FormatUint(uint64(uintptr(ptr)), 10)
}
pkgPath := path.Base(t.PkgPath())
pkgPath := t.PkgPath()
if pkgPath != "." {
pkgPath += "."
}
fullName := pkgPath + name
return strings.Replace(fullName, "-", "_", -1)
fullName = strings.ReplaceAll(fullName, "/", "_")
return strings.ReplaceAll(fullName, "-", "_")
}
Loading