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

Make example string conform to regex #7829

Merged
merged 2 commits into from
Mar 4, 2022

Conversation

dewijones92
Copy link
Contributor

Description

Make the example string conform to the regex pattern

Motivation and Context

Otherwise the request body is invalid

How Has This Been Tested?

Created unit test for it

Screenshots (if appropriate):

Checklist

My PR contains...

  • No code changes (src/ is unmodified: changes to documentation, CI, metadata, etc.)
  • Dependency changes (any modification to dependencies in package.json)
  • Bug fixes (non-breaking change which fixes an issue)
  • Improvements (misc. changes to existing features)
  • Features (non-breaking change which adds functionality)

My changes...

  • are breaking changes to a public API (config options, System API, major UI change, etc).
  • are breaking changes to a private API (Redux, component props, utility functions, etc.).
  • are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
  • are not breaking changes.

Documentation

  • My changes do not require a change to the project documentation.
  • My changes require a change to the project documentation.
  • If yes to above: I have updated the documentation accordingly.

Automated tests

  • My changes can not or do not need to be tested.
  • My changes can and should be tested by unit and/or integration tests.
  • If yes to above: I have added tests to cover my changes.
  • If yes to above: I have taken care to cover edge cases in my tests.
  • All new and existing tests passed.

@dewijones92
Copy link
Contributor Author

I have cleaned up the code

@dewijones92 dewijones92 force-pushed the conform_to_pattern_regex branch from 8288247 to d9759cf Compare February 13, 2022 08:35
@dewijones92
Copy link
Contributor Author

Rebased

@dewijones92
Copy link
Contributor Author

Any particular reason why this isn't being merged in? Am I missing something?
thanks :)

@tim-lai
Copy link
Contributor

tim-lai commented Mar 2, 2022

@dewijones92 Thanks for the PR, it functionally works for me. However, can you update so that it passes the lint-errors test?

9:42  error  'generateStringFromRegex' was used before it was defined  no-use-before-define

package.json Outdated Show resolved Hide resolved
@tim-lai tim-lai self-assigned this Mar 2, 2022
@dewijones92 dewijones92 force-pushed the conform_to_pattern_regex branch 2 times, most recently from 150102e to 6392726 Compare March 3, 2022 10:11
@dewijones92
Copy link
Contributor Author

@tim-lai I have amended
hope it is ok now? thanks

@dewijones92 dewijones92 force-pushed the conform_to_pattern_regex branch from 6392726 to b4633a4 Compare March 3, 2022 11:14
@dewijones92 dewijones92 force-pushed the conform_to_pattern_regex branch from b4633a4 to dcdaa4b Compare March 3, 2022 11:20
@dewijones92
Copy link
Contributor Author

rebased

@tim-lai tim-lai merged commit 3d79c24 into swagger-api:master Mar 4, 2022
@tim-lai
Copy link
Contributor

tim-lai commented Mar 4, 2022

@dewijones92 PR merged! Thanks for the contribution!

@GandalfTheBlack16
Copy link

Hi there, I just opened an issue relative to this feature.., it's look like Swagger-ui now expects a @Schema Example attribute to be always specified, cause if you define a @pattern on your field but you dont specify an @Schema(example="") value something go wrong and try it out section is so verbose by 'error':

image

You can check the issue here: #8003

And the repo with a easily reproducible demo here: https://github.com/GandalfTheBlack16/demo-swagger

Thanks so much!

@tautvydasfrontit
Copy link

tautvydasfrontit commented Sep 26, 2024

@tim-lai @dewijones92
In our project API models contains lots of regexp pattern such as this: "[\p{L}]+(['՚’'֊᠆‐‑﹣--]+[\p{L}]+)[.]?([\p{Zs}]+[\p{L}]+(['՚\’'֊᠆‐‑﹣--]+[\p{L}]+)[.]?)*".
Since now swagger-ui tries to generate value for each field marked with 'pattern', it causes slow UI behaviour and sometimes even crash browser. Both cases swagger-ui becomes unusable.
I would appreciate a way to disable this functionality or have a workaround, cause now it really troubles our workflow.

@sdunderdog
Copy link

sdunderdog commented Oct 18, 2024

If your app is Java application and using this internally I have had luck adding this annotation from io.swagger.v3.oas.annotations.media.Schema to override pattern value in UI.
@Schema(defaultValue = "the_default_value_you_like_to_see_in_swagger")

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

Successfully merging this pull request may close these issues.

5 participants