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 #152

Closed
Orest-Yastremskyy opened this issue May 5, 2023 · 2 comments · Fixed by #153
Closed

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

Orest-Yastremskyy opened this issue May 5, 2023 · 2 comments · Fixed by #153
Labels

Comments

@Orest-Yastremskyy
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.

Steps to replicate:

  1. 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.

image

Original issue: Redocly/redoc#2312

@llllvvuu
Copy link
Contributor

llllvvuu commented Aug 23, 2023

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:

return sampler(schema.minLength | 0, schema.maxLength, propertyName);

Will post PR shortly.

llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
@llllvvuu llllvvuu mentioned this issue Aug 23, 2023
5 tasks
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 23, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 24, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 24, 2023
This fixes Redocly#152 except in an edge case where both `pattern` and
`maxLength` are used, and the sampler skips over the valid length range.

It introduces a tiny dependency (<10 KB uncompressed) which doesn't
really have any prominent competitors.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 24, 2023
Fixes Redocly#152.

Vendors a tiny dependency (total dependency tree <10 KB
uncompressed).

Other than removing unused code from the dependency, the only change
made is to change the following line:

https://github.com/fent/randexp.js/blob/2b35ea607883fa8cafa63bd3bdb5c12d695f873a/lib/randexp.js#L109

to a separately customizable callback.
llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 24, 2023
Fixes Redocly#152.

Vendors a tiny dependency (total dependency tree <10 KB
uncompressed).

Other than removing unused code from the dependency, the only change
made is to change the following line:

https://github.com/fent/randexp.js/blob/2b35ea607883fa8cafa63bd3bdb5c12d695f873a/lib/randexp.js#L109

to a separately customizable callback.
@llllvvuu
Copy link
Contributor

OK, just proposed a solution in #153. BTW if ignoring minLength / maxLength constraints is acceptable then there is a one-liner solution.

llllvvuu added a commit to llllvvuu/openapi-sampler that referenced this issue Aug 26, 2023
Fixes Redocly#152.

Vendors a tiny dependency (total dependency tree <10 KB
uncompressed).

Other than removing unused code from the dependency, the only change
made is to change the following line:

https://github.com/fent/randexp.js/blob/2b35ea607883fa8cafa63bd3bdb5c12d695f873a/lib/randexp.js#L109

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

Successfully merging a pull request may close this issue.

2 participants