Skip to content

Commit 89868a8

Browse files
hkosovashockey
authored andcommitted
feat: sample value generation for uuid, hostname, ipv4, & ipv6 formats (via #5033)
1 parent 078bca3 commit 89868a8

File tree

2 files changed

+48
-0
lines changed
  • src/core/plugins/samples
  • test/core/plugins/samples

2 files changed

+48
-0
lines changed

src/core/plugins/samples/fn.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ const primitives = {
77
"string_email": () => "[email protected]",
88
"string_date-time": () => new Date().toISOString(),
99
"string_date": () => new Date().toISOString().substring(0, 10),
10+
"string_uuid": () => "3fa85f64-5717-4562-b3fc-2c963f66afa6",
11+
"string_hostname": () => "example.com",
12+
"string_ipv4": () => "198.51.100.42",
13+
"string_ipv6": () => "2001:0db8:5b96:0000:0000:426f:8e17:642a",
1014
"number": () => 0,
1115
"number_float": () => 0.0,
1216
"integer": () => 0,

test/core/plugins/samples/fn.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,50 @@ describe("sampleFromSchema", function() {
260260
expect(sampleFromSchema(definition)).toEqual(expected)
261261
})
262262

263+
it("returns a UUID for a string with format=uuid", function() {
264+
var definition = {
265+
type: "string",
266+
format: "uuid"
267+
}
268+
269+
var expected = "3fa85f64-5717-4562-b3fc-2c963f66afa6"
270+
271+
expect(sampleFromSchema(definition)).toEqual(expected)
272+
})
273+
274+
it("returns a hostname for a string with format=hostname", function() {
275+
var definition = {
276+
type: "string",
277+
format: "hostname"
278+
}
279+
280+
var expected = "example.com"
281+
282+
expect(sampleFromSchema(definition)).toEqual(expected)
283+
})
284+
285+
it("returns an IPv4 address for a string with format=ipv4", function() {
286+
var definition = {
287+
type: "string",
288+
format: "ipv4"
289+
}
290+
291+
var expected = "198.51.100.42"
292+
293+
expect(sampleFromSchema(definition)).toEqual(expected)
294+
})
295+
296+
it("returns an IPv6 address for a string with format=ipv6", function() {
297+
var definition = {
298+
type: "string",
299+
format: "ipv6"
300+
}
301+
302+
var expected = "2001:0db8:5b96:0000:0000:426f:8e17:642a"
303+
304+
expect(sampleFromSchema(definition)).toEqual(expected)
305+
})
306+
263307
describe("for array type", function() {
264308
it("returns array with sample of array type", function() {
265309
var definition = {

0 commit comments

Comments
 (0)