Skip to content

Commit

Permalink
fix dashes in path params (go-openapi#35)
Browse files Browse the repository at this point in the history
* allow for dashes in path param

* fix for updated docker/go-units
  • Loading branch information
casualjim authored Jan 30, 2017
1 parent 196f817 commit 4affd1e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions flagext/byte_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import "github.com/stretchr/testify/assert"
func TestMarshalBytesize(t *testing.T) {
v, err := ByteSize(1024).MarshalFlag()
if assert.NoError(t, err) {
assert.Equal(t, "1.024 kB", v)
assert.Equal(t, "1.024kB", v)
}
}

func TestStringBytesize(t *testing.T) {
v := ByteSize(2048).String()
assert.Equal(t, "2.048 kB", v)
assert.Equal(t, "2.048kB", v)
}

func TestUnmarshalBytesize(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions middleware/denco/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ func TestRouter_Lookup(t *testing.T) {
{"/networks/:owner/:repo/events", "testroute0"},
{"/orgs/:org/events", "testroute1"},
{"/notifications/threads/:id", "testroute2"},
{"/mypathisgreat/:thing-id", "testroute3"},
}
testcases = []testcase{
{"/networks/:owner/:repo/events", "testroute0", []denco.Param{{"owner", ":owner"}, {"repo", ":repo"}}, true},
{"/orgs/:org/events", "testroute1", []denco.Param{{"org", ":org"}}, true},
{"/notifications/threads/:id", "testroute2", []denco.Param{{"id", ":id"}}, true},
{"/mypathisgreat/:thing-id", "testroute3", []denco.Param{{"thing-id", ":thing-id"}}, true},
}
runLookupTest(t, records, testcases)

Expand Down
2 changes: 1 addition & 1 deletion middleware/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (d *defaultRouter) OtherMethods(method, path string) []string {
return methods
}

var pathConverter = regexp.MustCompile(`{(\w+)}`)
var pathConverter = regexp.MustCompile(`{(.+)}`)

func (d *defaultRouteBuilder) AddRoute(method, path string, operation *spec.Operation) {
mn := strings.ToUpper(method)
Expand Down
20 changes: 20 additions & 0 deletions middleware/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,23 @@ func petAPIRouterBuilder(spec *loads.Document, api *untyped.API, analyzed *analy

return builder
}

func TestPathConverter(t *testing.T) {
cases := []struct {
swagger string
denco string
}{
{"/", "/"},
{"/something", "/something"},
{"/{id}", "/:id"},
{"/{petid}", "/:petid"},
{"/{pet_id}", "/:pet_id"},
{"/{petId}", "/:petId"},
{"/{pet-id}", "/:pet-id"},
}

for _, tc := range cases {
actual := pathConverter.ReplaceAllString(tc.swagger, ":$1")
assert.Equal(t, tc.denco, actual, "expected swagger path %s to match %s but got %s", tc.swagger, tc.denco, actual)
}
}

0 comments on commit 4affd1e

Please sign in to comment.