Generated examples are not valid when using regular expression patterns
Orest-Yastremskyy opened this issue · 2 comments
Orest-Yastremskyy commented
Generated examples are not valid when using regular expression patterns.
In this case, the example is simply "string" without honoring the regular expression.
Steps to replicate:
- OA as an example:
openapi: 3.0.3
info:
version: 1.0.0
title: Test
description: Test
servers:
- url: "/api/1"
paths:
/test:
get:
operationId: Test
summary: Test
description: Test
responses:
"200":
description: Test
content:
application/json:
schema:
type: object
properties:
test:
type: string
pattern: "^[0-9]{5,8}$"
Observe the example rendered as {"test": "string"}
that is not valid against the schema.
Original issue: Redocly/redoc#2312
llllvvuu commented
Added to RapiDoc just now: https://github.com/rapi-doc/RapiDoc/pull/947/files#diff-82d61daee06cfa4e64b7d6351db4581c12a0b04c8d7f6f5960f970b8d0835c95R268-R274
Should be doable in ReDoc too, just need to pass in the schema.pattern
here:
openapi-sampler/src/samplers/string.js
Line 130 in d143da1
Will post PR shortly.