Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated examples are not valid when using regular expression patterns #2312

Closed
albertored opened this issue May 3, 2023 · 5 comments
Closed

Comments

@albertored
Copy link

Generated examples are not valid when using regular expression patterns.
In this case, the example is simply "string" without honoring the regular expression.

Maybe something like https://github.com/fent/randexp.js can be used for this

@Orest-Yastremskyy
Copy link

Hi @albertored

Is there a chance you could provide us with additional details regarding this matter along with the minimal setup to replicate it from our side?

@albertored
Copy link
Author

Take this 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}$"

This is rendered like this

image

As you can see the example is rendered as {"test": "string"} that is not valid against the schema.

I was planning to open a PR on the https://github.com/Redocly/openapi-sampler repository for generating examples using randexp but I saw in the readme that

Deterministic (given a particular input, will always produce the same output)

so I stop 😄

@Orest-Yastremskyy
Copy link

Thank you for the details provided. Let us check it, please.

@Redocly Redocly deleted a comment from Sandrakay49 May 5, 2023
@Orest-Yastremskyy
Copy link

Hi @albertored
I will reopen this issue in the openapi-sampler repository and close this one. Thank you so much for reporting this.

@AlexVarchuk
Copy link
Collaborator

Hi @albertored, thanks for the issue. OpenAPI sampler does not support it for now, but I believe may. We'll discuss it.
For now you can use example field for provide value to right panel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants