Skip to content
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
4 changes: 3 additions & 1 deletion renderer/mock_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ func (mg *MockGenerator) renderMockJSON(v any) []byte {
data, _ = json.Marshal(v)
}
default:
data = []byte(fmt.Sprint(v))
// use json.Marshal for scalar types to produce valid JSON
// (e.g. strings get properly quoted: "bob" not bob)
data, _ = json.Marshal(v)
}
return data
}
Expand Down
2 changes: 1 addition & 1 deletion renderer/mock_generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func TestMockGenerator_GenerateJSONMock_NoExamples_JSON(t *testing.T) {
mg := NewMockGenerator(JSON)
mock, err := mg.GenerateMock(fake, "")
assert.NoError(t, err)
assert.Equal(t, "magic-herbs", string(mock))
assert.Equal(t, `"magic-herbs"`, string(mock))
}

func TestMockGenerator_GenerateJSONMock_NoExamples_YAML(t *testing.T) {
Expand Down
Loading