From ab74da28e59e70da68ee4aa830c1d0b8693049a4 Mon Sep 17 00:00:00 2001 From: Magdalena Lorentz Date: Fri, 5 Apr 2024 11:54:15 +0200 Subject: [PATCH 1/3] Update string.js added binary sample method for binary format --- src/samplers/string.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/samplers/string.js b/src/samplers/string.js index f332e50..1ecf2da 100644 --- a/src/samplers/string.js +++ b/src/samplers/string.js @@ -104,6 +104,10 @@ function regexSample() { return '/regex/'; } +function binarySample() { + return [116, 101, 115, 116]; +} + const stringFormats = { 'email': emailSample, 'idn-email': idnEmailSample, // https://tools.ietf.org/html/rfc6531#section-3.3 @@ -125,6 +129,7 @@ const stringFormats = { 'json-pointer': jsonPointerSample, 'relative-json-pointer': relativeJsonPointerSample, // https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01 'regex': regexSample, + 'binary': binarySample, }; export function sampleString(schema, options, spec, context) { From 14609adf926d5d330a75a09598f40626bff8ab83 Mon Sep 17 00:00:00 2001 From: Magdalena Lorentz Date: Fri, 5 Apr 2024 11:54:54 +0200 Subject: [PATCH 2/3] Update string.spec.js added test for binary format --- test/unit/string.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/unit/string.spec.js b/test/unit/string.spec.js index 1b9c255..aa8c1dc 100644 --- a/test/unit/string.spec.js +++ b/test/unit/string.spec.js @@ -143,6 +143,11 @@ describe('sampleString', () => { }); }); + it('should return binary for format binary', () => { + res = sampleString({format: 'binary'}); + expect(res).to.deep.equal([116, 101, 115, 116]); + }); + it.each([ 'email', // 'idn-email', // unsupported by ajv-formats From 51a96ff0f3e5e3ccd0489d6199e179e33ae18459 Mon Sep 17 00:00:00 2001 From: Magdalena Lorentz Date: Fri, 11 Oct 2024 09:10:35 +0200 Subject: [PATCH 3/3] fixed test --- test/unit/string.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/string.spec.js b/test/unit/string.spec.js index 658c1c5..d79875c 100644 --- a/test/unit/string.spec.js +++ b/test/unit/string.spec.js @@ -137,7 +137,7 @@ describe('sampleString', () => { it('should return binary for format binary', () => { res = sampleString({format: 'binary'}); - expect(res).to.deep.equal([116, 101, 115, 116]); + expect(res).toEqual([116, 101, 115, 116]); }); it.each([