forked from jormaechea/open-api-mocker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://spec.openapis.org/oas/v3.1.0#dataTypeFormat https://ajv.js.org/packages/ajv-formats.html#formats
- Loading branch information
1 parent
0391803
commit fefe0a5
Showing
1 changed file
with
34 additions
and
6 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 |
---|---|---|
|
@@ -5,6 +5,34 @@ const getFakerLocale = require('../utils/get-faker-locale'); | |
|
||
const faker = getFakerLocale(); | ||
|
||
const FORMAT_EXAMPLES = { | ||
date: '2023-11-17', | ||
time: '14:30:00Z', | ||
'date-time': '2023-11-17T14:30:00Z', | ||
'iso-time': '14:30:00Z', | ||
'iso-date-time': '2023-11-17T14:30:00Z', | ||
duration: 'PT2H30M', | ||
uri: 'https://www.example.com', | ||
'uri-reference': 'https://www.example.com/resource', | ||
'uri-template': 'https://www.example.com/{id}', | ||
url: 'https://www.example.com', | ||
email: '[email protected]', | ||
hostname: 'www.example.com', | ||
ipv4: '192.168.0.1', | ||
ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334', | ||
regex: '^\\d{3}-\\d{2}-\\d{4}$', | ||
uuid: '550e8400-e29b-41d4-a716-446655440000', | ||
'json-pointer': '/path/to/resource', | ||
'relative-json-pointer': '2/foo', | ||
byte: 'SGVsbG8gd29ybGQ=', | ||
int32: 123, | ||
int64: 9223372036854776000, | ||
float: 3.14, | ||
double: 2.718281828459045, | ||
password: 'P@ssw0rd', | ||
binary: '01001000 01100101 01101100 01101100 01101111' | ||
}; | ||
|
||
class ResponseGenerator { | ||
|
||
static generate(schemaResponse, preferredExampleName) { | ||
|
@@ -134,16 +162,16 @@ class ResponseGenerator { | |
}), {}); | ||
} | ||
|
||
static generateString() { | ||
return 'string'; | ||
static generateString({ format }) { | ||
return FORMAT_EXAMPLES[format] || 'string'; | ||
} | ||
|
||
static generateNumber() { | ||
return 1; | ||
static generateNumber({ format }) { | ||
return FORMAT_EXAMPLES[format] || 1; | ||
} | ||
|
||
static generateInteger() { | ||
return 1; | ||
static generateInteger({ format }) { | ||
return FORMAT_EXAMPLES[format] || 1; | ||
} | ||
|
||
static generateBoolean() { | ||
|