-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(openapi-sampler): add support for extra format options
closes #185
- Loading branch information
Showing
2 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,18 +4,31 @@ import RandExp from 'randexp'; | |
export class StringSampler implements Sampler { | ||
private readonly stringFormats = { | ||
'email': () => '[email protected]', | ||
'idn-email': () => 'джон.сноу@таргариен.укр', | ||
'password': (min: number, max: number) => | ||
this.adjustLength('p@$$w0rd', min, max), | ||
'date-time': () => '2021-12-31T23:34:00Z', | ||
'date': () => '2021-12-31', | ||
'time': () => '23:34:00Z', | ||
'duration': () => 'P3D', | ||
'ipv4': () => '208.67.222.222', | ||
'ipv6': () => '0000:0000:0000:0000:0000:ffff:d043:dcdc', | ||
'hostname': () => 'brokencrystals.com', | ||
'idn-hostname': () => 'сломанные-кристаллы.бел', | ||
'iri': () => | ||
'https://be.wikipedia.org/wiki/%D0%9A%D1%80%D1%8B%D1%88%D1%82%D0%B0%D0%BB%D1%96', | ||
'iri-reference': () => | ||
'/wiki/%D0%9A%D1%80%D1%8B%D1%88%D1%82%D0%B0%D0%BB%D1%96', | ||
'uri': () => 'https://github.com/NeuraLegion/brokencrystals', | ||
'uri-reference': () => '../brokencrystals', | ||
'uri-template': () => 'https://brokencrystals.com/api/file/{provider}', | ||
'byte': () => 'ZHVtbXkgYmluYXJ5IHNhbXBsZQA=', | ||
'binary': () => '\\x01\\x02\\x03\\x04\\x05', | ||
'base64': () => 'ZHVtbXkgYmluYXJ5IHNhbXBsZQA=', | ||
'uuid': () => 'fbdf5a53-161e-4460-98ad-0e39408d8689', | ||
'json-pointer': () => '/json/pointer', | ||
'relative-json-pointer': () => '1/relative/json/pointer', | ||
'regex': () => '/regex/', | ||
'pattern': ( | ||
_min: number, | ||
_max: number, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,13 @@ describe('StringSampler', () => { | |
}, | ||
expected: '[email protected]' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'idn-email' | ||
}, | ||
expected: 'джон.сноу@таргариен.укр' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
|
@@ -54,6 +61,20 @@ describe('StringSampler', () => { | |
}, | ||
expected: '2021-12-31T23:34:00Z' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'time' | ||
}, | ||
expected: '23:34:00Z' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'duration' | ||
}, | ||
expected: 'P3D' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
|
@@ -78,13 +99,70 @@ describe('StringSampler', () => { | |
}, | ||
expected: 'brokencrystals.com' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'idn-hostname' | ||
}, | ||
expected: 'сломанные-кристаллы.бел' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'uri' | ||
}, | ||
expected: 'https://github.com/NeuraLegion/brokencrystals' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'uri-reference' | ||
}, | ||
expected: '../brokencrystals' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'uri-template' | ||
}, | ||
expected: 'https://brokencrystals.com/api/file/{provider}' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'iri' | ||
}, | ||
expected: | ||
'https://be.wikipedia.org/wiki/%D0%9A%D1%80%D1%8B%D1%88%D1%82%D0%B0%D0%BB%D1%96' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'iri-reference' | ||
}, | ||
expected: '/wiki/%D0%9A%D1%80%D1%8B%D1%88%D1%82%D0%B0%D0%BB%D1%96' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'json-pointer' | ||
}, | ||
expected: '/json/pointer' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'relative-json-pointer' | ||
}, | ||
expected: '1/relative/json/pointer' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
format: 'regex' | ||
}, | ||
expected: '/regex/' | ||
}, | ||
{ | ||
input: { | ||
type: 'string', | ||
|