Skip to content

Commit f344a1b

Browse files
committed
Address issue pb33f/wiretap#143
scalar rendering now fixed.
1 parent 0760217 commit f344a1b

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

renderer/mock_generator.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@ func (mg *MockGenerator) renderMockJSON(v any) []byte {
222222
data, _ = json.Marshal(v)
223223
}
224224
default:
225-
data = []byte(fmt.Sprint(v))
225+
// use json.Marshal for scalar types to produce valid JSON
226+
// (e.g. strings get properly quoted: "bob" not bob)
227+
data, _ = json.Marshal(v)
226228
}
227229
return data
228230
}

renderer/mock_generator_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func TestMockGenerator_GenerateJSONMock_NoExamples_JSON(t *testing.T) {
219219
mg := NewMockGenerator(JSON)
220220
mock, err := mg.GenerateMock(fake, "")
221221
assert.NoError(t, err)
222-
assert.Equal(t, "magic-herbs", string(mock))
222+
assert.Equal(t, `"magic-herbs"`, string(mock))
223223
}
224224

225225
func TestMockGenerator_GenerateJSONMock_NoExamples_YAML(t *testing.T) {

0 commit comments

Comments
 (0)