Skip to content

Commit c12f0c5

Browse files
committed
bugfix prefix generation in api
there was a bug that caused double slashes //
1 parent 51a52d5 commit c12f0c5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

marshal.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,11 @@ func (ctx *marshalingContext) marshalStruct(val *reflect.Value, isLinked bool) e
125125
name := jsonify(pluralize(valType.Name()))
126126

127127
buildLinksMap := func(referenceIDs []interface{}, single bool, field reflect.Value, name, keyName string) map[string]interface{} {
128-
resource := fmt.Sprintf("/%s/%s/%s", name, result["id"], keyName)
129-
if ctx.prefix != "/" {
130-
resource = fmt.Sprintf("%s%s", ctx.prefix, resource)
128+
var resource string
129+
if ctx.prefix != "/" && ctx.prefix != "" {
130+
resource = fmt.Sprintf("%s%s/%s/%s", ctx.prefix, name, result["id"], keyName)
131+
} else {
132+
resource = fmt.Sprintf("/%s/%s/%s", name, result["id"], keyName)
131133
}
132134

133135
result := make(map[string]interface{})

marshal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ var _ = Describe("Marshalling", func() {
278278

279279
It("marshal correctly with prefix", func() {
280280
post := Post{ID: 1, Comments: []Comment{}, CommentsIDs: []int{1}}
281-
i, err := MarshalPrefix(post, "/v1")
281+
i, err := MarshalPrefix(post, "/v1/")
282282
Expect(err).To(BeNil())
283283
Expect(i).To(Equal(map[string]interface{}{
284284
"data": map[string]interface{}{

0 commit comments

Comments
 (0)