Open
Description
Generated duration strings are often not valid.
To reproduce the issue:
Using https://json-schema-faker.js.org/ with the following schema, some results generated are valid and others are not.
{
"properties": {
"duration": {
"type": "string",
"format": "duration"
}
},
"required": [
"duration"
],
"additionalProperties": false
}
Clicking "Generate" 10 times yielded the following results--7 valid durations and 3 non-valid durations:
{
"duration": "P78187143M"
}
{
"duration": "P35882228342MT"
}
{
"duration": "PW"
}
{
"duration": "P05Y6D"
}
{
"duration": "P15267M03035361D"
}
{
"duration": "P26Y411240M"
}
{
"duration": "P41Y7252451M9DT2590M"
}
{
"duration": "P"
}
{
"duration": "P69Y251M188D"
}
{
"duration": "PT26540H"
}
Here is a comparison of the Regex used in
against these results. As you can see, duration strings ending in T are not valid as well as strings without any duration values (e.g., P and PW)
I discovered this issue via Prism, where API response validation checks are failing against generated data. I initially logged stoplightio/prism#2650 against Prism, but it looks like this is actually a bug on json-schema-faker.
Metadata
Metadata
Assignees
Labels
No labels